Home > wafo > cycles > dat2dtp.m

# dat2dtp

## PURPOSE

The sequence of discretized turning points from a signal.

## SYNOPSIS

[dtp,u,tp] = dat2dtp(param,x,h,ddef)

## DESCRIPTION

``` DAT2DTP The sequence of discretized turning points from a signal.

CALL:  [dtp,u,tp] = dat2dtp(param,x,h,ddef);
dtp = dat2dtp(param,x);

Input:
param = Parameter vector, [a b n], defines the discretization.
x     = Data, one column with values OR                   [N,1]
two columns with times and values.          [N,2]
h     = Threshold for hysteresis filter (see rfcfilter).
(Optional, Default='smallest discretization step')
ddef  = 1 causes peaks to be projected upwards and troughs
downwards to the closest discrete level (default).
= 0 causes peaks and troughs to be projected
the closest discrete level.
=-1 causes peaks to be projected downwards and the
troughs upwards to the closest discrete level.

Output:
dtp   = Discretized turning points taking values 1,2,...,n.
[N,1] or [N,2]
u     = Discretization levels.                             [1,n]
tp    = Discretized turning points taking values u(1),u(2),...,u(n).
[N,1] or [N,2]

Calculates the sequence of discretized turning points and optionally
removes small oscillations from data x by rainflow filtering.

Example:
[dtp,u,tp] = dat2dtp([-2 2 32],x,0.5); % Discrete TP & rainflow filter 0.5
plot(x(:,1),x(:,2),tp(:,1),tp(:,2))

## CROSS-REFERENCE INFORMATION

This function calls:
 levels Calculates discrete levels given the parameter matrix. rfcfilter Rainflow filter a signal. error Display message and abort function. num2str Convert number to string. (Fast version)
This function is called by:
 Chapter4 % CHAPTER4 contains the commands used in Chapter 4 of the tutorial dat2rfm Calculates the rainflow matrix from a time signal. itmkurs_lab4 Script to computer exercises 4 test_cycles Quick test of the routines in module 'cycles' test_markov Quick test of the routines in module 'markov'

## SOURCE CODE

```001 function [dtp,u,tp] = dat2dtp(param,x,h,ddef)
002 %DAT2DTP The sequence of discretized turning points from a signal.
003 %
004 % CALL:  [dtp,u,tp] = dat2dtp(param,x,h,ddef);
005 %               dtp = dat2dtp(param,x);
006 %
007 % Input:
008 % param = Parameter vector, [a b n], defines the discretization.
009 % x     = Data, one column with values OR                   [N,1]
010 %               two columns with times and values.          [N,2]
011 % h     = Threshold for hysteresis filter (see rfcfilter).
012 %           (Optional, Default='smallest discretization step')
013 % ddef  = 1 causes peaks to be projected upwards and troughs
014 %           downwards to the closest discrete level (default).
015 %       = 0 causes peaks and troughs to be projected
016 %           the closest discrete level.
017 %       =-1 causes peaks to be projected downwards and the
018 %           troughs upwards to the closest discrete level.
019 %
020 % Output:
021 % dtp   = Discretized turning points taking values 1,2,...,n.
022 %                                                   [N,1] or [N,2]
023 % u     = Discretization levels.                             [1,n]
024 % tp    = Discretized turning points taking values u(1),u(2),...,u(n).
025 %                                                   [N,1] or [N,2]
026 %
027 % Calculates the sequence of discretized turning points and optionally
028 % removes small oscillations from data x by rainflow filtering.
029 %
030 % Example:
032 %   [dtp,u,tp] = dat2dtp([-2 2 32],x,0.5); % Discrete TP & rainflow filter 0.5
033 %   plot(x(:,1),x(:,2),tp(:,1),tp(:,2))
034 %
036
037 % Copyright (c) 1999 by Pär Johannesson, 27-Apr-99
038 % Toolbox: Rainflow Cycles for Switching Processes V.1.1, 27-Apr-99
039
040 % Tested  on Matlab  5.3
041 %
042 % History:
043 % Updated by PJ 28-Jul-2000
044 %   New implementation of discretization.
045 %   Implemented 'ddef' different methods for discretization.
046 % Updated by PJ 18-May-2000
047 %   Output 'tp' now works.
048 % Updated by PJ (Pär Johannesson) 25-Feb-2000
049 %   help
050 % Revised by PJ (Pär Johannesson) 12-Jan-2000
051 %   updated for WAFO
052 % Created by PJ (Pär Johannesson) 1999
053 %   Copyright (c) 1999 by Pär Johannesson, 27-Apr-99
054 %   Toolbox: Rainflow Cycles for Switching Processes V.1.1, 27-Apr-99
055
056 % Check input arguments
057 ni = nargin;
058 no = nargout;
059 error(nargchk(2,4,ni));
060
061 if ni < 3
062   h=[];
063 end
064 if ni < 4
065   ddef=[];
066 end
067
068
069 u = levels(param); % Discrete levels
070 delta = u(2)-u(1);
071
072 if isempty(h)
073   h = delta;
074 end
075 if isempty(ddef)
076   ddef = 1;
077 end
078
079 % Rainflow filter x,
080 % Gives turning points with no rfc-ranges less than threshold h.
081
082 if h>0
083   y = rfcfilter(x,h,0);  % Get rainflow filtered turning points
084 else
085   y = rfcfilter(x,0,1);  % Get turning points
086 end
087
088 % Discretize turning points 'y'
089 % From TP 'y' to discrete TP 'dtp'
090
091 % Make discretization
092
093 [N,m] = size(y);
094 dtp = zeros(N,m);
095
096 a=param(1); b=param(2); n=param(3);
097 delta = (b-a)/(n-1);        % Discretization step
098 dtp = y;
099 dtp(:,m) = (y(:,m)-a)/delta + 1;
100
101 if ddef == 0
102   dtp(:,m) = min(max(round(dtp(:,m)),1),n);
103 elseif ddef == +1
104   if dtp(1,m)<dtp(2,m)  % First TP is a minimum
105     dtp(1:2:N,m) = min(max(floor(dtp(1:2:N,m)),1),n-1); % Minumum
106     dtp(2:2:N,m) = min(max(ceil(dtp(2:2:N,m)),2),n);    % Maximum
107   else
108     dtp(2:2:N,m) = min(max(floor(dtp(2:2:N,m)),1),n-1); % Minumum
109     dtp(1:2:N,m) = min(max(ceil(dtp(1:2:N,m)),2),n);    % Maximum
110   end
111 elseif ddef == -1
112   if dtp(1,m)<dtp(2,m)  % First TP is a minimum
113     dtp(1:2:N,m) = min(max(ceil(dtp(1:2:N,m)),2),n);    % Minumum
114     dtp(2:2:N,m) = min(max(floor(dtp(2:2:N,m)),1),n-1); % Maximum
115   else
116     dtp(2:2:N,m) = min(max(ceil(dtp(2:2:N,m)),2),n);    % Minumum
117     dtp(1:2:N,m) = min(max(floor(dtp(1:2:N,m)),1),n-1); % Maximum
118   end
119 else
120   error(['Undefined discretization definition, ddef = ' num2str(ddef)]);
121 end
122
123 dtp = rfcfilter(dtp,0,1);  % Get turning points
124
125 if no>=2
126   uu = u';
127   if m == 1
128     tp = uu(dtp);
129   else
130     tp = [dtp(:,1) uu(dtp(:,2))];
131   end
132 end
133
134
135```

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