TP2RFC Finds the rainflow cycles from the sequence of turning points. CALL: [RFC,RFC1,res] = tp2rfc(tp,def,RFC0,res0); RFC = tp2rfc(tp); Output: RFC = Rainflow cycles (residual included). [N,2]/[N,4] RFC1 = Rainflow cycles (without resudual). [N1,2]/[N1,4] res = Residual. [nres,1]/[nres,2] Input: tp = Turning points. [T,1]/[T,2] def = Choice of definition of rainflow cycles [struct array] def.res = Treatment of residual. 'up': Count min-to-Max cycles, (default) gives correct number of upcrossings. 'down': Count Max-to-min cycles, gives correct number of downcrossings. 'CS': Cloormann/Seeger method, gives all closed hysteresis loops. This method is identical to the French AFNOR recommendation, and the ASTM standard (variant called simplified version). def.time = 0: Don't store time of max and min. (default) 1: Store the time when the maxima and minima occured in columns 3-4. def.asymmetric = 0: gives the symmetric RFC (default), 1: gives the asymmetric RFC (or From-To RFC), time order between maximum and rainflow minimum is preserved. RFC0 = Rainflow cycles (without resudual). [N0,2]/[N0,4] res0 = Residual. [nres0,1]/[nres0,2] Calculates the rainflow cycles (RFC) for the sequence of turning points, by using the so-called 4-point algorithm. It is possible to split the signal into smaller parts, and calculate RFC part by part. It can be especially useful for long signals. We count the first part and for the second part we continue counting from previously counted 'RFC0' with residual 'res0': [RFC1,RFC0,res0] = tp2rfc(tp(1:1000,:)); % Firts 1000 points [RFC2] = tp2rfc(tp(1001:end,:),[],RFC0,res0); % Point 1001 to end This shall give the same result as (i.e. ARFC=ARFC2) [RFC] = tp2rfc(tp); % Calculate all at once sum(RFC~=RFC2) % Shall return [0 0] This routine doesn't use MEX, Fortran or C codes, only matlab code. Example: x = load('sea.dat'); tp=dat2tp(x); RFC1=tp2rfc(tp); % Default (min-to-Max cycles in residual) ccplot(RFC1) RFC2=tp2rfc(tp,'CS'); % Compare with AFNOR/ASTM standard [I,J] = find(RFC1(:,1)~=RFC2(:,1) | RFC1(:,2)~=RFC2(:,2)); hold on,plot(RFC1(I,1),RFC1(I,2),'b+',RFC2(I,1),RFC2(I,2),'rx'), hold off See also findrfc, dat2tp, rfcfilt, tp2arfc
Calculates asymmetric rainflow cycles from turning points. | |
Display message and abort function. | |
True for character array (string). | |
True if field is in structure array. | |
True for numeric arrays. | |
True for structures. |
% CHAPTER1 demonstrates some applications of WAFO | |
% CHAPTER4 contains the commands used in Chapter 4 of the tutorial | |
Script to computer exercises 1 | |
Script to computer exercises 2 | |
Script to computer exercises 3 | |
Script to computer exercises 4 | |
Recontructs a load process given the frequency matrix (and residual). | |
Demo for switching AR(1)-processes. | |
Rainflow matrix for Switching Markov Chains of Turning Points. | |
Quick test of the routines in module 'cycles' | |
Intensity of rainflow cycles computed from St |
001 function [RFC,RFC1,res,def] = tp2rfc(x,def,RFC0,res0) 002 %TP2RFC Finds the rainflow cycles from the sequence of turning points. 003 % 004 % CALL: [RFC,RFC1,res] = tp2rfc(tp,def,RFC0,res0); 005 % RFC = tp2rfc(tp); 006 % 007 % Output: 008 % RFC = Rainflow cycles (residual included). [N,2]/[N,4] 009 % RFC1 = Rainflow cycles (without resudual). [N1,2]/[N1,4] 010 % res = Residual. [nres,1]/[nres,2] 011 % 012 % Input: 013 % tp = Turning points. [T,1]/[T,2] 014 % def = Choice of definition of rainflow cycles [struct array] 015 % def.res = Treatment of residual. 016 % 'up': Count min-to-Max cycles, (default) 017 % gives correct number of upcrossings. 018 % 'down': Count Max-to-min cycles, 019 % gives correct number of downcrossings. 020 % 'CS': Cloormann/Seeger method, 021 % gives all closed hysteresis loops. 022 % This method is identical to the French AFNOR recommendation, 023 % and the ASTM standard (variant called simplified version). 024 % def.time = 0: Don't store time of max and min. (default) 025 % 1: Store the time when the maxima and minima occured in columns 3-4. 026 % def.asymmetric = 0: gives the symmetric RFC (default), 027 % 1: gives the asymmetric RFC (or From-To RFC), time order between 028 % maximum and rainflow minimum is preserved. 029 % RFC0 = Rainflow cycles (without resudual). [N0,2]/[N0,4] 030 % res0 = Residual. [nres0,1]/[nres0,2] 031 % 032 % Calculates the rainflow cycles (RFC) for the sequence of turning points, 033 % by using the so-called 4-point algorithm. 034 % 035 % It is possible to split the signal into smaller parts, and calculate 036 % RFC part by part. It can be especially useful for long signals. 037 % We count the first part and for the second part we continue counting 038 % from previously counted 'RFC0' with residual 'res0': 039 % [RFC1,RFC0,res0] = tp2rfc(tp(1:1000,:)); % Firts 1000 points 040 % [RFC2] = tp2rfc(tp(1001:end,:),[],RFC0,res0); % Point 1001 to end 041 % This shall give the same result as (i.e. ARFC=ARFC2) 042 % [RFC] = tp2rfc(tp); % Calculate all at once 043 % sum(RFC~=RFC2) % Shall return [0 0] 044 % 045 % This routine doesn't use MEX, Fortran or C codes, only matlab code. 046 % 047 % Example: 048 % x = load('sea.dat'); tp=dat2tp(x); 049 % RFC1=tp2rfc(tp); % Default (min-to-Max cycles in residual) 050 % ccplot(RFC1) 051 % RFC2=tp2rfc(tp,'CS'); % Compare with AFNOR/ASTM standard 052 % [I,J] = find(RFC1(:,1)~=RFC2(:,1) | RFC1(:,2)~=RFC2(:,2)); 053 % hold on,plot(RFC1(I,1),RFC1(I,2),'b+',RFC2(I,1),RFC2(I,2),'rx'), hold off 054 % 055 % See also findrfc, dat2tp, rfcfilt, tp2arfc 056 057 % Further examples: 058 % % Rainflow cycles with time 059 % def.res='up'; def.time=1; % Store times 060 % RFC=tp2rfc(tp,def); RFC(1:10,:), ccplot(RFC) 061 % 062 % % For long signals it is possible to split the input in smaller parts 063 % [dummy,RFC0,res0] = tp2rfc(dat2tp(x(1:5000,:))); % First part 064 % [RFC3] = tp2rfc(dat2tp(x(5001:end,:)),[],RFC0,res0); % Second part 065 % % RFC3 shall be the same as RFC1. Check this! 066 % ccplot(RFC1), hold on,plot(RFC3(:,1),RFC3(:,2),'r.'), hold off 067 068 % Tested on Matlab 5.3 069 % 070 % History: 071 % Created by PJ (Pär Johannesson) 2000-01-04 072 % Uses same syntax as 'tp2rfc' in WAT 073 % Revised by PJ 26-Jul-2000 074 % New format of def. 075 % Added input 'RFC0' and 'res0'. New output 'RFC1' and 'res' 076 % Now supports AFNOR and ASTM standards for rainflow counting. 077 % Revised by PJ 06-Jul-2005 078 % Fixed error with def & mod to avoid warning i R14SP2. 079 080 % Check input arguments 081 ni = nargin; 082 no = nargout; 083 error(nargchk(1,4,ni)); 084 085 if ni < 2, def=[]; end 086 if ni < 3, RFC0=[]; end 087 if ni < 4, res0=[]; end 088 089 % Check input def 090 def0=def; 091 if ~isempty(def) 092 if isnumeric(def) 093 def=[]; def.time = def0; 094 elseif ischar(def) 095 def=[]; def.res = def0; 096 elseif ~isstruct(def) 097 def=[]; 098 end 099 end 100 101 % Set default values 102 if ~isfield(def,'res') 103 def.res = 'up'; 104 end 105 if ~isfield(def,'time') 106 def.time = 0; 107 end 108 if ~isfield(def,'asymmetric') 109 def.asymmetric = 0; 110 end 111 112 % Count rainflow cycles 113 if no<2 114 ARFC = tp2arfc(x,def,[],res0); 115 else 116 [ARFC,ARFC1,res] = tp2arfc(x,def,[],res0); 117 end 118 119 % Convert to symmetric RFC ? 120 if def.asymmetric == 0 % Symmetric rainflow cycles 121 RFC = make_symmetric(ARFC); 122 else 123 RFC = ARFC; 124 end 125 126 % Add previously counted cycles (if any) 127 if ~isempty(RFC0) 128 RFC = [RFC0; RFC]; 129 end 130 131 % Rainflow cycles without residual 132 if no>2, 133 if def.asymmetric == 0 % Symmetric rainflow cycles 134 RFC1 = make_symmetric(ARFC1); 135 else 136 RFC1 = ARFC1; 137 end 138 % Add previously counted cycles (if any) 139 if ~isempty(RFC0) 140 RFC1 = [RFC0; RFC1]; 141 end 142 end 143 144 145 function RFC = make_symmetric(ARFC) 146 147 I = ARFC(:,1)>ARFC(:,2); 148 [N,M]=size(ARFC); 149 if M == 2 % No time 150 J=1; 151 else % Time of occurances is stored in column 3:4 152 J=[1 3]; 153 end 154 RFC = ARFC; 155 RFC(I,J) = ARFC(I,J+1); 156 RFC(I,J+1) = ARFC(I,J); 157
Comments or corrections to the WAFO group