Home > wafo > onedim > dat2tp.m

dat2tp

PURPOSE ^

Extracts turning points from data,

SYNOPSIS ^

[tp, ind] = data2tp(x,h,wdef);

DESCRIPTION ^

 DAT2TP Extracts turning points from data,
         optionally rainflowfiltered. 
 
  CALL:  [tp ind] = dat2tp(x,h,wdef);
 
     x  = two column data matrix with sampled times and values.
 
     tp = a two column matrix with times and turning points.
 
    ind = indices to the turning points in the original sequence.
 
     h  = a threshold; 
          if  h<0, then  tp=x; 
          if  h=0, then  tp  is a sequence of turning points (default); 
          if  h>0, then all rainflow cycles with height smaller than
                   h  are removed.
 
   wdef = defines the type of wave. Possible options are
       'mw' 'Mw' or 'none'. (Default 'none').
          If wdef='none' all rainflow filtered min and max 
          will be returned, otherwise only the rainflow filtered 
          min and max  which define a wave according to the 
          wave definition will be returned.
 
  Example:
    x  = load('sea.dat'); x1 = x(1:200,:);
    tp = dat2tp(x1,0,'Mw'); tph = dat2tp(x1,0.3,'Mw');
    plot(x1(:,1),x1(:,2),tp(:,1),tp(:,2),'ro',tph(:,1),tph(:,2),'k*')
  
   See also  findcross, findrfc, tp2rfc, dat2tc

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [tp, ind] = data2tp(x,h,wdef);
002 %DAT2TP Extracts turning points from data,
003 %        optionally rainflowfiltered. 
004 %
005 % CALL:  [tp ind] = dat2tp(x,h,wdef);
006 %
007 %    x  = two column data matrix with sampled times and values.
008 %
009 %    tp = a two column matrix with times and turning points.
010 %
011 %   ind = indices to the turning points in the original sequence.
012 %
013 %    h  = a threshold; 
014 %         if  h<0, then  tp=x; 
015 %         if  h=0, then  tp  is a sequence of turning points (default); 
016 %         if  h>0, then all rainflow cycles with height smaller than
017 %                  h  are removed.
018 %
019 %  wdef = defines the type of wave. Possible options are
020 %      'mw' 'Mw' or 'none'. (Default 'none').
021 %         If wdef='none' all rainflow filtered min and max 
022 %         will be returned, otherwise only the rainflow filtered 
023 %         min and max  which define a wave according to the 
024 %         wave definition will be returned.
025 %
026 % Example:
027 %   x  = load('sea.dat'); x1 = x(1:200,:);
028 %   tp = dat2tp(x1,0,'Mw'); tph = dat2tp(x1,0.3,'Mw');
029 %   plot(x1(:,1),x1(:,2),tp(:,1),tp(:,2),'ro',tph(:,1),tph(:,2),'k*')
030 % 
031 %  See also  findcross, findrfc, tp2rfc, dat2tc
032 
033 % Tested on: matlab 6.0, 5.3, 5.2, 5.1
034 
035 % History:
036 % revised pab oct 2005
037 % -replaced some code with a call to findextrema
038 % revised pab Feb2004  
039 % Revised by jr 03.04.2001
040 % - added example, updated info 
041 % Modified by Per A. Brodtkorb 07.08.98
042 % This is a modified version which is about 20 to 30 times faster than  
043 % the version of dat2tp in WAT (performance on a pentiumII 233 MHz  
044 % with 32 MB ram and Matlab 5.0 under Linux). The reason is
045 % that this version does not save x to disk. Instead it passes 
046 % the arguments directly to the executeable file. 
047 % This new version is also more flexible. It is able to return the 
048 % indices to the turningpoints 
049 % (This is useful when determining the wave steepness etc...). 
050 
051 error(nargchk(1,3,nargin))
052 
053 xn = x;
054 [n m]= size(xn);
055 if n<m
056   b=m;m=n;n=b; 
057   xn=xn';
058 end
059 
060 if n<2, 
061   error('The vector must have more than 2 elements!')
062 end
063 
064 istime=1;
065 
066 switch m
067   case 1, x2=xn; istime=0;
068   case 2, x2=xn(:,2);% dimension OK!
069   otherwise, error('Wrong dimension of input! dim must be 2xN, 1xN, Nx2 or Nx1 ')          
070 end
071 
072 if ((nargin<3) | isempty(wdef)),
073   wdef='none';
074 end
075 
076 if (nargin<2) | isempty(h),
077    h=0;
078 end
079 
080 if h<0 
081   tp=xn; 
082   ind=(1:n)';
083   disp('Warning: h<0, the original data is returned')
084   return   
085 end            
086 
087 ind = findextrema(x2);
088 
089 if length(ind)<2, 
090   tp=[];
091   return;
092 end
093 
094 % In order to get the exact up-crossing intensity from rfc by 
095 % mm2lc(tp2mm(rfc))  we have to add the indices
096 % to the last value (and also the first if the 
097 % sequence of turning points does not start with a minimum).
098 
099 if  x2(ind(1))>x2(ind(2)),        
100  % adds indices to  first and last value
101  ind=[1; ind ;n]; 
102 else %adds index to the last value
103  ind=[ind; n];
104 end
105 
106 if h>0 
107    ind1 = findrfc(x2(ind),h);
108    ind  = ind(ind1);
109 end 
110 
111 
112 Nm=length(ind); % number of min and Max
113 
114 
115 switch wdef  % switch wdef
116  case {'mw','Mw'},
117    % make sure that the first is a Max if wdef == 'Mw'
118    % or make sure that the first is a min if wdef == 'mw'
119    if xor((xn(ind(1))>(xn(ind(2)))),strcmp(wdef,'Mw')),
120      ind=ind(2:Nm);
121      Nm=Nm-1;
122    end
123 
124    % make sure the number of minima and Maxima are according to the wavedef.
125    % i.e., make sure Nm=length(ind) is odd
126    if ~(mod(Nm,2)), % if Nm is even do
127      ind(Nm)=[];
128      Nm=Nm-1;
129    end    
130    
131  case {'none'}% do nothing
132  otherwise, error('Unknown wave definition') 
133 end
134 
135 tp=xn(ind,:);
136 
137

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