Home > wafo > onedim > dat2wa.m

dat2wa

PURPOSE ^

Extracts sequence of wavelengths from data.

SYNOPSIS ^

[T, index,ind] = dat2wa(xn,h,pdef,wdef,rate)

DESCRIPTION ^

 DAT2WA Extracts sequence of wavelengths from data.
 
   CALL:  [T, index] = dat2wa(x,v/h,pdef,wdef/index,rate);
 
       T = sequence of waveperiods (or wavelengths).    
       x = two column data matrix with sampled times and values.
     v/h = reference level ( default v=mean(x(:,2)) ) or
           rainflow filtering height (default h=0)     
    pdef = defines the type of waveperiod (wavelength) returned:
           Level v separated 't2c', 'c2t', 't2t' or 'c2c' -waveperiod.
           Level v 'd2d', 'u2u', 'd2u' or 'u2d' -waveperiod.
           Rain flow filtered (with height greater than h) 
           'm2M', 'M2m', 'm2m' or 'M2M' -waveperiod.
           Explanation to the abbreviations:
           M=Max, m=min, d=down-crossing, u=up-crossing , 
           t=trough and c=crest.
           Thus 'd2d' means period between a down-crossing to the
           next down-crossing and 'u2c' means period between a 
           u-crossing to the following crest.
           (Default is 'd2d')
    wdef = defines the type of wave. Possible options are
           'mw','Mw','dw', 'uw', 'tw', 'cw' or 'none'. Default is 'none'.
           If wdef='none' all troughs and crests will be used,
           otherwise only the troughs and crests which define a
           wave according to the wavedefinition are used.
 
   index = index sequence of one of the following : 
        -level v-crossings (indices to "du" are required to 
            calculate 'd2d', 'd2u', 'u2d' or 'u2u' waveperiods) 
           -level v separated trough and crest turningpoints  
         (indices to 'tc' are required to calculate 
         't2t', 't2c', 'c2t' or 'c2c' waveperiods)
        -level v crossings and level v separated trough and 
            crest turningpoints (indices to "dutc" are
            required to calculate t2u, u2c, c2d or d2t
            waveperiods)  
           -rainflow filtered turningpoints with minimum rfc height h 
            (indices to "mMtc" are required to calculate
            'm2m', 'm2M', 'M2m' or 'M2M' waveperiods)
 
   rate = interpolation rate. If rate larger than one, then x is
          interpolated before extrating T
 
  Example:
   x = load('sea.dat'); x1 = x(1:400,:); 
   T = dat2wa(x1,0,'c2c'); % Returns crest2crest waveperiods
   subplot(121), waveplot(x1,'-',1,1),subplot(122),whisto(T)
 
  See also  dat2tp, dat2tc, dat2crossind, perioddef

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [T, index,ind] = dat2wa(xn,h,pdef,wdef,rate)
002 %DAT2WA Extracts sequence of wavelengths from data.
003 %
004 %  CALL:  [T, index] = dat2wa(x,v/h,pdef,wdef/index,rate);
005 %
006 %      T = sequence of waveperiods (or wavelengths).    
007 %      x = two column data matrix with sampled times and values.
008 %    v/h = reference level ( default v=mean(x(:,2)) ) or
009 %          rainflow filtering height (default h=0)     
010 %   pdef = defines the type of waveperiod (wavelength) returned:
011 %          Level v separated 't2c', 'c2t', 't2t' or 'c2c' -waveperiod.
012 %          Level v 'd2d', 'u2u', 'd2u' or 'u2d' -waveperiod.
013 %          Rain flow filtered (with height greater than h) 
014 %          'm2M', 'M2m', 'm2m' or 'M2M' -waveperiod.
015 %          Explanation to the abbreviations:
016 %          M=Max, m=min, d=down-crossing, u=up-crossing , 
017 %          t=trough and c=crest.
018 %          Thus 'd2d' means period between a down-crossing to the
019 %          next down-crossing and 'u2c' means period between a 
020 %          u-crossing to the following crest.
021 %          (Default is 'd2d')
022 %   wdef = defines the type of wave. Possible options are
023 %          'mw','Mw','dw', 'uw', 'tw', 'cw' or 'none'. Default is 'none'.
024 %          If wdef='none' all troughs and crests will be used,
025 %          otherwise only the troughs and crests which define a
026 %          wave according to the wavedefinition are used.
027 %
028 %  index = index sequence of one of the following : 
029 %       -level v-crossings (indices to "du" are required to 
030 %           calculate 'd2d', 'd2u', 'u2d' or 'u2u' waveperiods) 
031 %          -level v separated trough and crest turningpoints  
032 %        (indices to 'tc' are required to calculate 
033 %        't2t', 't2c', 'c2t' or 'c2c' waveperiods)
034 %       -level v crossings and level v separated trough and 
035 %           crest turningpoints (indices to "dutc" are
036 %           required to calculate t2u, u2c, c2d or d2t
037 %           waveperiods)  
038 %          -rainflow filtered turningpoints with minimum rfc height h 
039 %           (indices to "mMtc" are required to calculate
040 %           'm2m', 'm2M', 'M2m' or 'M2M' waveperiods)
041 %
042 %  rate = interpolation rate. If rate larger than one, then x is
043 %         interpolated before extrating T
044 %
045 % Example:
046 %  x = load('sea.dat'); x1 = x(1:400,:); 
047 %  T = dat2wa(x1,0,'c2c'); % Returns crest2crest waveperiods
048 %  subplot(121), waveplot(x1,'-',1,1),subplot(122),whisto(T)
049 %
050 % See also  dat2tp, dat2tc, dat2crossind, perioddef
051 
052 
053 % This is a more flexible version than the dat2hwa or tp2wa routines. 
054 % There is a secret option: if pdef='all' the function returns 
055 % all the waveperiods 'd2t', 't2u', 'u2c' and 'c2d' in sequence.
056 % It is up to the user to extract the right waveperiods.
057 % If the first is a down-crossing then the first is a 'd2t' waveperiod.
058 % If the first is a up-crossing then the first is a 'u2c' waveperiod.
059 %
060 %    Example:
061 %        [T ind]=dat2wa(x,0,'all'); %returns all waveperiods
062 %        nn = length(T)
063 %        % want to extract all t2u waveperiods
064 %        if x(ind(1),2)>0 % if first is down-crossing
065 %            Tt2u=T(2:4:nn);
066 %        else         % first is up-crossing
067 %            Tt2u=T(4:4:nn);
068 %        end
069 
070 % Tested on: Matlab 5.3, 5.2, 5.1
071 % History:
072 % revised pab Feb2004  
073 % revised pab 28.06.2001
074 % - added secret option ind = indices to actual points used in the
075 %   calculations
076 % - added call to ecross => improved accuracy in the level v-crossing
077 %   period calculations
078 % revised pab 03.12.1999
079 %  - added interpolation before extracting the parameters
080 % last modified by Per A. Brodtkorb 07.08.98
081 
082   error(nargchk(1,5,nargin))
083 x=xn;
084 
085 [n m]= size(x);
086 if n<m
087  b=m;m=n;n=b; 
088  x=x';
089 end
090 
091 if n<2, 
092   error('The vector must have more than 2 elements!')
093 end
094 
095 switch m
096  case 2, % dimension OK!
097  otherwise, error('Wrong dimension of input! dim must be 2xN or Nx2 ')
098 end
099 
100 if ((nargin<4) | isempty(wdef)),
101  wdef='none';
102  index=[];
103 else
104  if ischar(wdef)
105    index=[];
106  else
107    index=wdef;
108    wdef='none';
109  end
110 end
111 
112 if nargin<5|isempty(rate)|(rate<=1),  % no interpolation
113   
114 elseif rate>1 % interpolate with spline
115   xx=x;
116   dT=xx(2,1)-xx(1,1);
117   dT=dT/rate;
118   ti=(xx(1,1):dT:xx(end,1))';
119   interpolate=1;
120   x=zeros(length(ti),2);
121   x(:,1)=ti;
122   x(:,2)=interp1(xx(:,1),xx(:,2),ti,'*spline'); 
123 end
124 
125 if ((nargin<3) | isempty(pdef)),
126  pdef = 'd2d';
127 end
128 
129 if ((nargin<2) | isempty(h)) ,
130   if (pdef(1)=='m') | (pdef(1)=='M'),
131     h=0;
132     disp(['   The minimum rfc height, h,  is set to: ', num2str(h)])
133   else
134     h=mean(x(:,2));
135     disp(['   The level l is set to: ', num2str(h)])
136     % l is h in order to save number of arguments in the 
137     % function call. Hopefully not too confusing!
138   end
139 end
140 
141 if ( isempty(index)),
142   switch pdef(1:3) % comparing only the three first characters
143     
144     case {'m2m', 'm2M', 'M2m','M2M'} , % 
145       %find rainflow filtered min and max turning points
146       [TP index]=dat2tp(x,h,wdef);       
147 
148     case {'u2u','u2d','d2u', 'd2d'},%
149       %find level v down-crossings and up-crossings
150       index=dat2crossind(x,h,wdef);
151 
152     case { 't2t','t2c','c2t' 'c2c'}, %
153       %find level v trough and crest turningpoints
154       [TC, index]=dat2tc(x,h,wdef);
155       
156     case { 'd2t','t2u', 'u2c', 'c2d','all'  }, 
157       %find level v down-crossings, up-crossings and trough and crest turningpoints
158       [TC index l_ind]=dat2tc(x,h,wdef);
159       index=(sort([index ; l_ind])); % sorting crossings and tp in sequence
160     
161     otherwise, error('Unknown option!');
162   end 
163 end % if nargin
164 
165 if (x(index(1),2)>x(index(2),2)), % if first is down-crossing or max 
166   switch pdef
167     case 'all', start=1;    % secret option!
168     case {'d2t','M2m','c2t', 'd2u' , 'M2M','c2c','d2d'}, start=1;
169     case {'t2u','m2M', 't2c', 'u2d' ,'m2m','t2t','u2u'}, start=2;
170     case 'u2c', start=3;
171     case 'c2d', start=4;
172     otherwise, error('Unknown option!');
173   end %switch pdef
174 else             % first is up-crossing or min 
175   switch pdef 
176     case 'all', start=1;    % secret option!
177     case {'u2c','m2M', 't2c', 'u2d','m2m','t2t','u2u'} , start=1;
178     case {'c2d','M2m','c2t', 'd2u' , 'M2M','c2c','d2d'}, start=2;
179     case 'd2t', start=3;
180     case 't2u', start=4;
181     otherwise, error('Unknown option!');
182   end % switch pdef
183 end %if 
184 
185 % determine the steps between wanted periods
186 switch pdef
187   case {'d2t','t2u','u2c', 'c2d' }, step=4; 
188   case 'all', step=1;;% secret option!  
189   otherwise, step=2; 
190 end % switch pdef
191 
192 % determine the distance between min2min, t2t etc..
193 switch pdef
194   case {'m2m','t2t','u2u','M2M','c2c','d2d'}, dist=2;
195   case 'all', dist=1;% secret option!
196   otherwise,  dist=1;
197 end % switch pdef
198 
199 nn = length(index);
200 % New call: (pab 28.06.2001)
201 if strmatch(pdef(1),strvcat('u','d')),
202   t0 = ecross(x(:,1),x(:,2),index(start:step:(nn-dist)),h);
203 else % min, Max, trough, crest or all crossings wanted
204   t0 = x(index(start:step:(nn-dist)),1); 
205 end
206 if strmatch(pdef(3),strvcat('u','d')),
207   t1 = ecross(x(:,1),x(:,2),index((start+dist):step:nn),h);
208 else % min, Max, trough, crest or all crossings wanted
209   t1 = x(index((start+dist):step:nn),1); 
210 end
211 T = t1-t0;
212 if nargout>2, % Secret option: indices to the actual crossings used.
213   index=index(:);
214   ind = [index(start:step:(nn-dist)) index((start+dist):step:nn)].';
215   ind = ind(:);
216 end
217 
218 return
219 
220 % Old call: kept just in case
221 %T  = x(index((start+dist):step:nn),1)-x(index(start:step:(nn-dist)),1);
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234

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