Home > wafo > onedim > dat2midind.m

dat2midind

PURPOSE ^

Finds indices to midpoints between a min and Max and Max and min.

SYNOPSIS ^

ind2=dat2midind(x,p,ind,h)

DESCRIPTION ^

  DAT2MIDIND Finds indices to midpoints between a min and Max and Max and min. 
   
    CALL: ind = dat2midind(x,p,TP_index/wdef,h); 
      
     ind = indices to midpoints. 
          x = two column data matrix with sampled times and values. 
          p = level between min and max. The default value p=0.5 
         corresponds to midpoint. (0 < p < 1).     
   TP_index = indices to turningpoints.         
     wdef= defines the type of wave. Possible options are 
         'mw' 'Mw' or 'none'. Default is 'mw'. 
         If wdef='none' all rainflow filtered min and max  
         will be used, otherwise only the rainflow filtered  
         min and max  which define a wave according to the  
         wave definition will be used. 
      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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function ind2=dat2midind(x,p,ind,h) 
002 % DAT2MIDIND Finds indices to midpoints between a min and Max and Max and min. 
003 %  
004 %   CALL: ind = dat2midind(x,p,TP_index/wdef,h); 
005 %     
006 %    ind = indices to midpoints. 
007 %         x = two column data matrix with sampled times and values. 
008 %         p = level between min and max. The default value p=0.5 
009 %        corresponds to midpoint. (0 < p < 1).     
010 %  TP_index = indices to turningpoints.         
011 %    wdef= defines the type of wave. Possible options are 
012 %        'mw' 'Mw' or 'none'. Default is 'mw'. 
013 %        If wdef='none' all rainflow filtered min and max  
014 %        will be used, otherwise only the rainflow filtered  
015 %        min and max  which define a wave according to the  
016 %        wave definition will be used. 
017 %     h  = a threshold 
018 %             if  h<0, then  tp=x;  
019 %             if  h=0, then  tp  is a sequence of turning points (default);  
020 %             if  h>0, then all rainflow cycles with height smaller than 
021 %                           h  are removed. 
022  
023 % last modified by Per A Brodtkorb 06.07.00 , 01.09.98 
024  
025  
026 xn=x; 
027  
028 [n m]= size(xn); 
029 if n<m 
030   b=m;m=n;n=b;  
031   xn=xn'; 
032 end 
033  
034 if n<2,  
035   error('The vector must have more than 2 elements!') 
036 end 
037  
038 istime=1; 
039  
040 switch m 
041   case 1, x2=xn; istime=0; 
042   case 2, x2=xn(:,2);% dimension OK! 
043   otherwise, error('Wrong dimension of input! dim must be 2xN, 1xN, Nx2 or Nx1 ')   
044 end 
045  
046 if (nargin<4) | isempty(h) 
047   h=0; 
048 end 
049  
050 if (nargin<3) | isempty(ind) 
051   wdef='mw'; 
052   [tp ind]=dat2tp(xn,h,wdef); 
053 else 
054   if ischar(ind), 
055     wdef=ind; 
056     [tp ind]=dat2tp(xn,h,wdef); 
057   else 
058     wdef=[]; 
059     if (abs(diff(sign(diff(x2(ind)))))~=2), 
060       error('Wrong input! TP_index is not a sequence of turningpoints') 
061     end 
062   end 
063 end 
064  
065 if ((nargin<2) | isempty(p)), 
066   p=0.5; 
067 end 
068  
069 if (p<=0) | (p>=1), 
070   error('p must be between 0 and 1.') 
071 end 
072  
073 Ntp=length(ind); 
074 Nw=floor((Ntp-1)/2); 
075  
076  
077 ind2=zeros(2*Nw,1); 
078  
079 for i=1:Nw, 
080   tmp=findcross(x2((ind(2*i-1)):ind(2*i)), ((1-p)*x2(ind(2*i-1))+p*x2(ind(2*i)))); 
081   ind2(2*i-1)=tmp(end); % choosing the one closest to the Max (or min) 
082   tmp = findcross(x2((ind(2*i)):ind(2*i+1)), ... 
083       (p*x2(ind(2*i))+(1-p)*x2(ind(2*i+1)))); 
084   ind2(2*i)=tmp(1); % choosing the one closest to the Max (or min) 
085 end 
086  
087 %if 2*Nw+1<Ntp, 
088 %  tmp = findcross(x2((ind(Ntp-1)+1):ind(Ntp)),((1-p)*x2(ind(Ntp-1))+ p*x2(ind(Ntp))) ); 
089 %  ind2(Ntp-1)=tmp(end); 
090 %end 
091  
092 ind2=ind(1:(2*Nw))+ind2;

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