DTP2ARFM_SID Asymmetric RFM from discrete TP with side information. CALL: [RFM,RFM0,res,RFMsid,RFM0sid,res_sid] = dtp2arfm_sid(x,y,n,r,def) RFM = Rainflow Matrix (residual included). [n,n] RFM0 = Rainflow matrix (without resudual). [n,n] res = Residual. [2*n,1] RFMsid = Rainflow Matrix with side information (residual included). {r,r1}[n,n] RFMsid = Rainflow Matrix with side information (without resudual). {r,r1}[n,n] res_sid = Residual for side information. [2*n,1] x = Turning points (taking values 1,...,n). [T,1] y = Side information (taking values 1,...,r). [T,1] n = Number of levels. r = Number of levels in side information.. def = Which type of side information 1: Mark min & max, r1=r 2: Mark when counted, r1=1 RFM0 = Rainflow matrix (without resudual). [n,n] res = Residual. [2*n,1] Example: (Two processes as in Example 4.1 in PhD thesis) P = [0.9 0.1; 0.05 0.95]; param = [-1 1 32]; u = levels(param); F1 = mktestmat(param,[-0.4 -0.3],0.15,1); F2 = mktestmat(param,[0.3 0.4],0.15,1); [x,z] = smctpsim(P,{F1 F1'; F2 F2'},10000); % Two regime states [RFM,RFM0,res,RFMsid,RFM0sid,res_sid] = dtp2arfm_sid(x,z,32,2,1); figure(1),cmatplot(u,u,RFMsid,3) RFM1 = RFMsid{1,1}+RFMsid{1,2}+RFMsid{2,1}+RFMsid{2,2}; figure(2),cmatplot(u,u,{RFM RFM1},3) % Shall be identical See also dtp2arfm, smctp2arfm
Rainflow matrix from discrete turning points with side information. |
001 function [RFM,RFM0,res,RFMsid,RFM0sid,res_y] = dtp2arfm_sid(x,y,n,ny,def) 002 %DTP2ARFM_SID Asymmetric RFM from discrete TP with side information. 003 % 004 % CALL: [RFM,RFM0,res,RFMsid,RFM0sid,res_sid] = dtp2arfm_sid(x,y,n,r,def) 005 % 006 % RFM = Rainflow Matrix (residual included). [n,n] 007 % RFM0 = Rainflow matrix (without resudual). [n,n] 008 % res = Residual. [2*n,1] 009 % RFMsid = Rainflow Matrix with side information (residual included). 010 % {r,r1}[n,n] 011 % RFMsid = Rainflow Matrix with side information (without resudual). 012 % {r,r1}[n,n] 013 % res_sid = Residual for side information. [2*n,1] 014 % 015 % x = Turning points (taking values 1,...,n). [T,1] 016 % y = Side information (taking values 1,...,r). [T,1] 017 % n = Number of levels. 018 % r = Number of levels in side information.. 019 % def = Which type of side information 020 % 1: Mark min & max, r1=r 021 % 2: Mark when counted, r1=1 022 % RFM0 = Rainflow matrix (without resudual). [n,n] 023 % res = Residual. [2*n,1] 024 % 025 % Example: (Two processes as in Example 4.1 in PhD thesis) 026 % P = [0.9 0.1; 0.05 0.95]; 027 % param = [-1 1 32]; u = levels(param); 028 % F1 = mktestmat(param,[-0.4 -0.3],0.15,1); 029 % F2 = mktestmat(param,[0.3 0.4],0.15,1); 030 % [x,z] = smctpsim(P,{F1 F1'; F2 F2'},10000); % Two regime states 031 % [RFM,RFM0,res,RFMsid,RFM0sid,res_sid] = dtp2arfm_sid(x,z,32,2,1); 032 % figure(1),cmatplot(u,u,RFMsid,3) 033 % RFM1 = RFMsid{1,1}+RFMsid{1,2}+RFMsid{2,1}+RFMsid{2,2}; 034 % figure(2),cmatplot(u,u,{RFM RFM1},3) % Shall be identical 035 % 036 % See also dtp2arfm, smctp2arfm 037 038 % References: 039 % 040 % P. Johannesson (1999): 041 % Rainflow Analysis of Switching Markov Loads. 042 % PhD thesis, Mathematical Statistics, Centre for Mathematical Sciences, 043 % Lund Institute of Technology. 044 045 % Tested on Matlab 5.3 046 % 047 % History: 048 % Revised by PJ 09-Apr-2001 049 % updated for WAFO 050 % Created by PJ (Pär Johannesson) 1998 051 % Copyright (c) 1997-1998 by Pär Johannesson 052 % Toolbox: Rainflow Cycles for Switching Processes V.1.1, 22-Jan-1998 053 054 ni = nargin; 055 no = nargout; 056 error(nargchk(5,5,ni)); 057 058 RFM0 = zeros(n); 059 res0 = []; 060 if def == 1 061 RFM0sid = cell(ny,ny); 062 for iy=1:ny 063 for jy=1:ny 064 RFM0sid{iy,jy} = RFM0; 065 end 066 end 067 res0_y = []; 068 end 069 if def == 2 070 RFM0sid = cell(ny,1); 071 for iy=1:ny 072 RFM0sid{iy,1} = RFM0; 073 end 074 end 075 076 077 nres = length(res0); 078 res = zeros(2*n+1,1); 079 res(1:nres) = res0; 080 res_y = zeros(2*n+1,1); 081 res_y(1:nres) = res0_y; 082 083 % Calculate RFM and res 084 085 for k = 1:length(x)-1 086 nres = nres+1; 087 res(nres) = x(k); 088 if def == 1 089 res_y(nres) = y(k+1); 090 end 091 cycleFound = 1; 092 while cycleFound==1 & nres>=4 093 A = sort([res(nres-1) res(nres-2)]); 094 B = sort([res(nres) res(nres-3)]); 095 if A(1) >= B(1) & A(2) <= B(2) 096 i = res(nres-2); 097 j = res(nres-1); 098 RFM0(i,j) = RFM0(i,j) + 1; 099 if def == 1 100 s1 = res_y(nres-2); 101 s2 = res_y(nres-1); 102 RFM0sid{s1,s2}(i,j) = RFM0sid{s1,s2}(i,j) + 1; 103 res_y(nres-2) = res_y(nres); 104 end 105 if def == 2 106 s = y(k+1); 107 RFM0sid{s,1}(i,j) = RFM0sid{s,1}(i,j) + 1; 108 end 109 110 res(nres-2) = res(nres); 111 nres = nres-2; 112 else 113 cycleFound = 0; 114 end 115 end 116 end 117 118 % Residual 119 120 res = res(1:nres); 121 if def == 1 122 res_y = res_y(1:nres); 123 end 124 125 % Calculate RFM = RFM0 + 'cycles in res' 126 127 RFM = RFM0; 128 if def == 1 | def == 2 129 RFMsid = RFM0sid; 130 end 131 132 for k = 1:2:nres-1 133 i = res(k); 134 j = res(k+1); 135 RFM(i,j) = RFM(i,j) + 1; 136 if def == 1 137 s1 = res_y(k); 138 s2 = res_y(k+1); 139 RFM0sid{s1,s2}(i,j) = RFM0sid{s1,s2}(i,j) + 1; 140 end 141 if def == 2 142 s = y(end); 143 RFM0sid{s,1}(i,j) = RFM0sid{s,1}(i,j) + 1; 144 end 145 end 146 147 148
Comments or corrections to the WAFO group