[37] | 1 | function [lmval,indd]=lmin_pw(xx, dx)
|
---|
| 2 | % Find piece-wise local minima in vector XX,where
|
---|
| 3 | % LMVAL is the output vector with minima values, INDD is the
|
---|
| 4 | % corresponding indexes, DX is scalar length of piece where minima is searched,
|
---|
| 5 | % IMPORTANT: FIRST and LAST point in vector are excluded
|
---|
| 6 | % IMPORTANT: XX must be single column vector
|
---|
| 7 | % IMPORTANT: Length of DX must be very carefully selected
|
---|
| 8 | % For example compare dx=10; and dx=1000;
|
---|
| 9 | %
|
---|
| 10 | % dx=150; xx=[0:0.01:35]'; y=sin(xx .* cos(xx /4.5)) + cos(xx);
|
---|
| 11 | % y(length(y))=-2; plot(xx,y); grid; hold on;
|
---|
| 12 | % % Excluding first and last points
|
---|
| 13 | % [b,a]=lmin_pw(y,dx); plot(xx(a),y(a),'r+')
|
---|
| 14 | % % Way to include first and last points can be as:
|
---|
| 15 | % yy=[1.5; y; 0]; % padd with values higher than end values
|
---|
| 16 | % [b,a]=lmin_pw(yy,dx); a=a-1; plot(xx(a),y(a),'go')
|
---|
| 17 | %
|
---|
| 18 | % see also LMIN,LMAX, LMAX_PW, MATCH
|
---|
| 19 |
|
---|
| 20 | % Sergei Koptenko, Applied Acoustic Technologies, Toronto, Canada
|
---|
| 21 | % sergei.koptenko@sympatico.ca, March/11/2003
|
---|
| 22 |
|
---|
| 23 | if nargin <2,
|
---|
| 24 | disp('Not enough arguments'); return
|
---|
| 25 | end
|
---|
| 26 |
|
---|
| 27 | len_x = length(xx);
|
---|
| 28 | xx = [xx; xx(end)];
|
---|
| 29 | nn=floor(len_x/dx);
|
---|
| 30 | ncount=1; lmval=[]; indd=[];
|
---|
| 31 | for ii=1:nn,
|
---|
| 32 | [lm,ind] = min(xx(ncount: ii*dx+1)) ;
|
---|
| 33 | ind=ind+(ii-1)*dx;
|
---|
| 34 | if (ind ~=ncount) & (ind~=ii*dx+1),
|
---|
| 35 | lmval=[lmval, lm]; indd=[indd, ind];
|
---|
| 36 | end
|
---|
| 37 | ncount=ncount +dx;
|
---|
| 38 | end
|
---|
| 39 | [lm,ind] = min(xx(ii*dx:len_x));
|
---|
| 40 | if (ind ~=len_x) & (ind~=ii*dx),
|
---|
| 41 | lmval=[lmval, lm]; indd=[indd, (ind+ii*dx-1)];
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | if indd(end)==len_x,
|
---|
| 45 | indd=indd(1:end-1); lmval=lmval(1:end-1);
|
---|
| 46 | end
|
---|
| 47 | return
|
---|