TP2ARFC4P Calculates asymmetric rainflow cycles from turning points (4-point). CALL: [ARFC,res] = tp2arfc4p(tp) [ARFC,res] = tp2arfc4p(tp,res0,def_time) Output: ARFC = Asymmetric RFC (without residual). [N,2]/[N,4] res = Residual. [nres,1]/[nres,2] Input: tp = Turning points. [T,1]/[T,2] res0 = Residual. [nres0,1]/[nres0,1] def_time = 0: Don't store time of max and min. (default) 1: Store the time when the maxima and minima occured. Calculates the rainflow cycles for the sequence of turning points, by using the so-called 4-point algorithm. Calculate ARFC for turning points, starting from old residual 'res0' [ARFC,res] = tp2arfc4p(tp,res0) This routine doesn't use MEX, Fortran or C codes, only matlab code. Example: x = load('sea.dat'); tp=dat2tp(x); [ARFC,res]=tp2arfc4p(tp); % Default (min-to-Max cycles in residual) ccplot(ARFC), res See also tp2arfc, findrfc, dtp2arfm4p, tp2rfc, dat2tp, rfcfilt
Display message and abort function. |
Calculates asymmetric rainflow cycles for a residual. | |
Calculates asymmetric rainflow cycles from turning points. |
001 function [ARFC,res] = tp2arfc4p(x,res0,def_time) 002 %TP2ARFC4P Calculates asymmetric rainflow cycles from turning points (4-point). 003 % 004 % CALL: [ARFC,res] = tp2arfc4p(tp) 005 % [ARFC,res] = tp2arfc4p(tp,res0,def_time) 006 % 007 % Output: 008 % ARFC = Asymmetric RFC (without residual). [N,2]/[N,4] 009 % res = Residual. [nres,1]/[nres,2] 010 % 011 % Input: 012 % tp = Turning points. [T,1]/[T,2] 013 % res0 = Residual. [nres0,1]/[nres0,1] 014 % def_time = 0: Don't store time of max and min. (default) 015 % 1: Store the time when the maxima and minima occured. 016 % 017 % Calculates the rainflow cycles for the sequence of turning points, 018 % by using the so-called 4-point algorithm. 019 % 020 % Calculate ARFC for turning points, starting from old residual 'res0' 021 % [ARFC,res] = tp2arfc4p(tp,res0) 022 % 023 % This routine doesn't use MEX, Fortran or C codes, only matlab code. 024 % 025 % Example: 026 % x = load('sea.dat'); tp=dat2tp(x); 027 % [ARFC,res]=tp2arfc4p(tp); % Default (min-to-Max cycles in residual) 028 % ccplot(ARFC), res 029 % 030 % See also tp2arfc, findrfc, dtp2arfm4p, tp2rfc, dat2tp, rfcfilt 031 032 % Tested on Matlab 5.3 033 % 034 % History: 035 % Created by PJ (Pär Johannesson) 2000-Jul-12 036 % Revised by PJ 04-Apr-2001 037 % - Added input def_time 038 % Check input arguments 039 ni = nargin; 040 no = nargout; 041 error(nargchk(1,3,ni)); 042 043 if ni<2, res0 = []; end 044 if ni<3, def_time = []; end 045 046 % Set default values 047 if isempty(def_time), def_time=0; end 048 049 [T,nn] = size(x); 050 ARFC = zeros(floor(T/2),2); 051 N = 0; 052 053 if def_time == 0, nn0=nn; else nn0=1; end 054 055 res = zeros(max([100 length(res0)]),nn); 056 if isempty(res0) 057 nres = 0; 058 else 059 nres = length(res0); 060 res(1:nres,1:nn) = res0; 061 end 062 063 % Calculate ARFC and res 064 for i = 1:T 065 nres = nres+1; 066 res(nres,1:nn) = x(i,1:nn); 067 cycleFound = 1; 068 while cycleFound==1 & nres>=4 069 if res(nres-1,nn) < res(nres-2,nn) 070 A = [res(nres-1,nn) res(nres-2,nn)]; 071 else 072 A = [res(nres-2,nn) res(nres-1,nn)]; 073 end 074 if res(nres,nn) < res(nres-3,nn) 075 B = [res(nres,nn) res(nres-3,nn)]; 076 else 077 B = [res(nres-3,nn) res(nres,nn)]; 078 end 079 %A = sort([res(nres-1) res(nres-2)]); 080 %B = sort([res(nres) res(nres-3)]); 081 if A(1) >= B(1) & A(2) <= B(2) 082 N = N+1; 083 arfc = [res(nres-2,nn:-1:nn0); res(nres-1,nn:-1:nn0)]; 084 ARFC(N,1:2*(nn-nn0+1)) = arfc(:)'; 085 res(nres-2,1:nn) = res(nres,1:nn); 086 nres = nres-2; 087 else 088 cycleFound = 0; 089 end 090 end 091 end 092 093 % Counted rainflow cycles 094 ARFC = ARFC(1:N,:); 095 096 % Residual 097 res = res(1:nres,:); 098 099
Comments or corrections to the WAFO group