Home > wafo > cycles > test > test_cycles.m

test_cycles

PURPOSE ^

Quick test of the routines in module 'cycles'

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 TEST_CYCLES Quick test of the routines in module 'cycles'
 
 This script is used for a quick test of the routines in
  Modul 'cycles':
 
  The following routines are tested:
 
  Cycle counting
  - dat2tp
  - rfcfilter
  - tp2mm
  - tp2rfc
  - tp2arfc
  
  Cycle matrix
  - cc2cmat
  - cmat2nt
  - nt2cmat
  - cmat2rmcmat
  - rmcmat2cmat
  - smoothcmat
  - tp2lc
  - cc2lc
  - cmat2lc
  - nt2lc
  - cc2amp
  - cmat2amp
 
  Discrete loads
  - dat2dtp
  - cc2dcc
  - dtp2rfm
  - dtp2arfm
  - dcc2cmat
 
  Extrapolation & Smoothing of RFM/CMAT/LC. 
  - rfmextrapolate
  - tpextrapolate
  - cmat2extralc  
  - wgpdfit_mld  
  - lc2rfmextreme
  - extralc     
  - smoothcmat

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %TEST_CYCLES Quick test of the routines in module 'cycles'
0002 %
0003 %This script is used for a quick test of the routines in
0004 % Modul 'cycles':
0005 %
0006 % The following routines are tested:
0007 %
0008 % Cycle counting
0009 % - dat2tp
0010 % - rfcfilter
0011 % - tp2mm
0012 % - tp2rfc
0013 % - tp2arfc
0014 % 
0015 % Cycle matrix
0016 % - cc2cmat
0017 % - cmat2nt
0018 % - nt2cmat
0019 % - cmat2rmcmat
0020 % - rmcmat2cmat
0021 % - smoothcmat
0022 % - tp2lc
0023 % - cc2lc
0024 % - cmat2lc
0025 % - nt2lc
0026 % - cc2amp
0027 % - cmat2amp
0028 %
0029 % Discrete loads
0030 % - dat2dtp
0031 % - cc2dcc
0032 % - dtp2rfm
0033 % - dtp2arfm
0034 % - dcc2cmat
0035 %
0036 % Extrapolation & Smoothing of RFM/CMAT/LC. 
0037 % - rfmextrapolate
0038 % - tpextrapolate
0039 % - cmat2extralc  
0040 % - wgpdfit_mld  
0041 % - lc2rfmextreme
0042 % - extralc     
0043 % - smoothcmat   
0044 
0045 % History:
0046 % Created by PJ (Pär Johannesson) 18-May-2000
0047 % Updated by PJ (Pär Johannesson) 07-Jul-2005
0048 
0049 figure(1), clf
0050 
0051 echo on
0052 
0053 % Load test-signal: deep.dat
0054 load([waforoot filesep 'wdemos' filesep 'itmkurs' filesep 'deep.dat'])
0055 x = deep;
0056 plot(x(:,1),x(:,2))
0057 
0058 pause
0059 
0060 %%%%
0061 % Cycle counting
0062 %
0063 
0064 %DAT2TP - Turning points from a signal.
0065 
0066 tp = dat2tp(x);    % Calculate turing points
0067 tp5 = dat2tp(x,5); % TP, rainflow filter with threshold 5. Needs FINDRFC!
0068 
0069 plot(x(:,1),x(:,2),tp(:,1),tp(:,2),tp5(:,1),tp5(:,2))
0070 
0071 pause
0072 
0073 %DAT2TP - Turning points from a signal.
0074 
0075 [RFM0,u0] = dat2rfm(x);    % Default parameters
0076 [RFM,u] = dat2rfm(x,0.5,[-25 25 50]);
0077 subplot(1,2,1), cmatplot(u0,u0,RFM0,3)
0078 subplot(1,2,2), cmatplot(u,u,RFM,3)
0079 
0080 pause
0081 
0082 %RFCFILTER - Rainflow filter a signal.
0083 y = rfcfilter(x,0,1); % Filtered signal y is the turning points of x.
0084 y5 = rfcfilter(x,5);  % This removes all rainflow cycles with range less than 5.
0085 
0086 plot(x(:,1),x(:,2),y(:,1),y(:,2),y5(:,1),y5(:,2))
0087 
0088 pause
0089 
0090 %TP2MM - min-max cycles from TP.
0091 [mM,Mm] = tp2mm(tp);
0092 ccplot({mM Mm})
0093 
0094 pause
0095 
0096 %TP2RFC - Rainflow cycles from TP.
0097 [rfc] = tp2rfc(tp);
0098 [rfc2] = tp2rfc(tp,1);
0099 def=[]; def.res='cs'; def.time=1;
0100 [rfc3] = tp2rfc(tp,def);
0101 def.asymmetric=1;
0102 [rfc4] = tp2rfc(tp,def);
0103 ccplot({rfc rfc2; rfc3 rfc4})
0104 
0105 pause
0106 
0107 %TP2ARFC - Asymmetric rainflow cycles from TP.
0108 [arfc,arfc0,res] = tp2arfc(tp);
0109 ccplot({arfc arfc0; [] []})
0110 subplot(2,2,3), ccplot(arfc), hold on, plot(arfc0(:,1),arfc0(:,2),'r.'), hold off
0111 subplot(2,2,4), plot(res)
0112 
0113 pause
0114 
0115 %%%%
0116 % Cycle matrix
0117 %
0118 
0119 %CC2CMAT - Cycle matrix from cycle count.
0120 param = [-20 20 41]; u=levels(param);
0121 Frfc = cc2cmat(param,rfc);
0122 Farfc = cc2cmat(param,arfc);
0123 cmatplot(u,u,{Frfc Farfc},13)
0124 
0125 pause
0126 
0127 % Smoothing, fixed bandwidth
0128 Frfc1 = cc2cmat(param,rfc,[],1);
0129 Farfc1 = cc2cmat(param,arfc,[],1); % Don't work for ARFC
0130 cmatplot(u,u,{Frfc1 Farfc1},13)
0131 
0132 pause
0133 
0134 % Smoothing, varying bandwidth
0135 Frfc2 = cc2cmat(param,rfc,[],2);
0136 %Farfc2 = cc2cmat(param,arfc,[],2); % Don't work for ARFC
0137 cmatplot(u,u,{Frfc2},13)
0138 
0139 pause
0140 
0141 %CMAT2NT - Counting distribution from cycle matrix.
0142 F=Frfc;
0143 NT = cmat2nt(F);
0144  
0145 %NT2CMAT - Cycle matrix from counting distribution.
0146 FF = nt2cmat(NT);
0147 cmatplot({F NT FF},13)
0148 sum(sum(abs(FF-F))) % Shall be zero
0149 
0150 pause
0151 
0152 %CMAT2RMCMAT - Convert cycle matrix from min-max to range-mean (PJ)
0153 Frm = cmat2rmcmat(F);
0154 cmatplot({F Frm},13)
0155 
0156 pause
0157 
0158 %RMCMAT2CMAT - Convert cycle matrix from range-mean to min-max (PJ)
0159 F1 = rmcmat2cmat(Frm);
0160 cmatplot({F Frm F1},13)
0161 sum(sum(abs(F1-F))) % Shall be zero
0162 
0163 pause
0164 
0165 %SMOOTHCMAT - Smooth a cycle matrix. (PJ)
0166 Frfc1 = smoothcmat(Frfc,1); % Smoothing, fixed bandwidth
0167 Frfc2 = smoothcmat(Frfc,2); % Smoothing, varying bandwidth
0168 cmatplot(u,u,{Frfc1 Frfc2},13)
0169 
0170 pause
0171 
0172 %TP2LC - Level crossings from a cycle count. (WAT/PJ)
0173 lc1 = tp2lc(tp);
0174 subplot(2,2,1), lcplot(lc1)
0175 
0176 %CC2LC - Level crossings from a cycle count. (WAT/PJ)
0177 lc2 = cc2lc(rfc);
0178 subplot(2,2,2), lcplot(lc2)
0179 
0180 sum(abs(lc1-lc2)) % Shall be zero
0181 
0182 %CMAT2LC - Level crossings from cycle matrix. (PJ)
0183 lc3 = cmat2lc(param,Frfc);
0184 subplot(2,2,3), lcplot(lc3)
0185 
0186 %NT2LC - Level crossings from counting distribution. (FAT/PJ)
0187 lc4 = nt2lc(param,NT);
0188 subplot(2,2,4), lcplot(lc4)
0189 
0190 sum(abs(lc3-lc4)) % Shall be zero
0191 
0192 pause
0193 
0194 %CC2AMP - Amplitude histogram from a cycle count. (WAT/PJ)
0195 amp = cc2amp(rfc);
0196 [N,X] = hist(amp,((u-u(1))+(u(2)-u(1))/2)/2);
0197 amp_hist1=[X' N'];
0198 
0199 %CMAT2AMP - Amplitude histogram from cycle matrix. (PJ)
0200 amp_hist2 = cmat2amp(param,F);
0201 
0202 subplot(2,1,1), bar(amp_hist1(:,1),amp_hist1(:,2))
0203 subplot(2,1,2), bar(amp_hist2(:,1)+0.25,amp_hist2(:,2))
0204 
0205 lsplot({amp_hist2})
0206 pause
0207 
0208 %%%%
0209 % Discrete loads
0210 %
0211 
0212 clf
0213 
0214 %DAT2DTP - Discrete TP from load. (PJ)
0215 param = [-20 20 41];  u=levels(param);
0216 [dtp1,u1,tp1] = dat2dtp(param,x);
0217 [dtp2,u2,tp2] = dat2dtp(param,x,5);
0218 plot(x(:,1),x(:,2),tp1(:,1),tp1(:,2),tp2(:,1),tp2(:,2)), grid
0219 
0220 pause
0221 
0222 %CC2DCC - Discretization of a cycle count. (WAT)
0223 dcc = cc2dcc(param,rfc);
0224 Adcc = cc2dcc(param,arfc);
0225 
0226 %DTP2RFM - Rainflow matrix from discrete TP. (PJ)
0227 n=param(3);
0228 [RFM,RFM0,res] = dtp2rfm(dtp1(:,2),n);
0229 
0230 %DTP2ARFM - Asymmetric rainflow matrix from discrete TP. (PJ)
0231 [ARFM,ARFM0,Ares] = dtp2arfm(dtp1(:,2),n);
0232 
0233 %DCC2CMAT - Histogram matrix from discrete class indices. (WAT)
0234 Frfc = dcc2cmat(dcc,n);
0235 Farfc = dcc2cmat(Adcc,n);
0236 
0237 % Different methods for discretization, results should be different
0238 cmatplot(u,u,{RFM ARFM; Frfc Farfc},13)
0239 
0240 pause
0241 
0242 
0243 
0244 %%%%
0245 % Extrapolation & Smoothing
0246 %
0247 
0248 %Create a MCTP model
0249 
0250 n = 64;
0251 param = [-1 1 n]; uu=levels(param);
0252 paramD = [1 n n];
0253 [G,Gh] = mktestmat(param,[-0.2 0.2], 0.15,1);
0254 lcG = cmat2lc(paramD,G);
0255 
0256 % Simulate a sample path
0257 N = 1000;
0258 xD = mctpsim({G Gh},2*N);
0259 
0260 % Calculate RFM
0261 Frfc = dtp2rfm(xD,n);
0262 
0263 % Test rfmextrapolate
0264 
0265 [G,Gh] = mktestmat([-1 1 64],[-0.2 0.2], 0.15,1);
0266 xD = mctpsim({G Gh},2000);
0267 Frfc = dtp2rfm(xD,64,'CS');
0268 Fest = rfmextrapolate(Frfc,[],1);
0269 Grfc = mctp2rfm({G Gh});
0270 cmatplot({Frfc Fest; Grfc G},4)
0271 
0272 pause
0273 
0274 % Test tpextrapolate
0275 
0276 x = load('sea.dat');
0277 tp = dat2tp(x,0.5);
0278 tpe = tpextrapolate(tp,1,[],1);
0279 clf, plot(tp(:,1),tp(:,2),'b',tpe(:,1),tpe(:,2),'r')
0280 [tpe,Pout,I] = tpextrapolate(tp,1,[],2);
0281 clf, plot(tpe(:,1),tpe(:,2),'b',tpe(I.min,1),tpe(I.min,2),'g*',tpe(I.max,1),tpe(I.max,2),'g*')
0282 
0283 % Test cmat2extralc
0284 
0285 [G,Gh] = mktestmat([-1 1 64],[-0.2 0.2], 0.15,1);
0286 xD = mctpsim({G Gh},2000);
0287 Frfc = dtp2rfm(xD,64,'CS');
0288 [lcEst,Est] = cmat2extralc([-1 1 64],Frfc,[-0.4 0.4]);
0289 lcG = cmat2lc([-1 1 64],G/sum(sum(G)));
0290 lcF = cmat2lc([-1 1 64],Frfc);
0291 clf, semilogx(1000*lcG(:,2),lcG(:,1),lcF(:,2),lcF(:,1),lcEst.lc(:,2),lcEst.lc(:,1))
0292 
0293 param=[-1 1 64]; u=0.4;
0294 [lcEst,Est] = cmat2extralc(param,Frfc,[-u u]); %,method,plotflag)
0295 lcEst = cmat2extralc(param,Frfc,[-u u],[],0); %,method,plotflag)
0296 [lcEst,Est,R,MSE] = cmat2extralc(param,Frfc,[-u u],'exp,ls1',1); %,method,plotflag)
0297 [lcEst,Est,R,MSE] = cmat2extralc(param,Frfc,[-u u],'exp,wls4',1); %,method,plotflag)
0298 [lcEst,Est,R,MSE] = cmat2extralc(param,Frfc,[-u u],'ray,ml',1); %,method,plotflag)
0299 
0300 pause
0301 
0302 %Test wgpdfit_mld
0303 
0304 data0 = wgpdrnd(0.3,1,0,200,1);
0305 x_ML = fzero('wgpdfit_ml',0,[],data0);
0306 [f,k_ML,s_ML] = wgpdfit_ml(x_ML,data0) % Estimates k_ML and s_ML
0307 data1 = floor(data0*10)/10;
0308 x=(0:0.1:(max(data1)+0.1))';
0309 N = histc(data1+0.05,x);
0310 x_MLD = fzero('wgpdfit_mld',0,[],[x N]);
0311 [f,k_MLD,s_MLD] = wgpdfit_mld(x_MLD,[x N]) % Estimates k_ML and s_ML
0312 
0313 %Test lc2rfmextreme
0314 
0315 u = (-5:0.2:5)'; lc = [u exp(-u.^2/2)];
0316 [Frfc,u,Nrfc] = lc2rfmextreme(lc);
0317 cmatplot(u,u,{Frfc Nrfc},3)
0318 
0319 pause
0320 
0321 %Test cmatcombine
0322 
0323 F1 = triu(ones(8),0)
0324 F2 = 2*F1
0325 [F,Lim,FF1,FF2]=cmatcombine(F1,F2,2)
0326 Lim=[]; Lim.range=2; Lim.min=4; Lim.max=4;
0327 [F,Lim,FF1,FF2]=cmatcombine(F1,F2,Lim)
0328 
0329 %Test extralc
0330 
0331 S = jonswap;
0332 x = spec2sdat(S,100000,0.1,[],'random');
0333 lc = dat2lc(x); s = std(x(:,2));
0334 [lcEst,Est] = extralc(lc,s*[-2 2]);
0335 [lcEst,Est] = extralc(lc,s*[-2 2],'exp,ml');
0336 [lcEst,Est] = extralc(lc,s*[-2 2],'ray,ml');
0337 
0338 pause
0339 
0340 %Test cmatresamp
0341 
0342 F = round(5*triu(rand(4,4),1))
0343 FF = cmatresamp(F)
0344 
0345 %%%%%
0346 % End of test
0347 
0348 echo off
0349

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003