Home > fcn > equalstep.m

equalstep

PURPOSE ^

EQUALSTEP Resamples to equal step-size

SYNOPSIS ^

function [y,idx] = equalstep(x,step,type);

DESCRIPTION ^

 EQUALSTEP Resamples to equal step-size

 [y,idx]=equalstep(x,stepsize) resamples the vector 'x' 
 to a new vector y=x(idx) (with linear interpolation
 for non-integer idx values) so that abs(diff(y)) is 
 constant and equal to 'stepsize'.

 If x is a matrix it considers each column of x as a data 
 point: It attempts sqrt(sum(abs(diff(y,1,2)).^2,1)) = stepsize
 where y=x(:,idx)).

 [y,idx]=equalstep(x,n,'fixedlength') resamples so that y has
 n elements (with equal stepsize)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y,idx] = equalstep(x,step,type);
0002 % EQUALSTEP Resamples to equal step-size
0003 %
0004 % [y,idx]=equalstep(x,stepsize) resamples the vector 'x'
0005 % to a new vector y=x(idx) (with linear interpolation
0006 % for non-integer idx values) so that abs(diff(y)) is
0007 % constant and equal to 'stepsize'.
0008 %
0009 % If x is a matrix it considers each column of x as a data
0010 % point: It attempts sqrt(sum(abs(diff(y,1,2)).^2,1)) = stepsize
0011 % where y=x(:,idx)).
0012 %
0013 % [y,idx]=equalstep(x,n,'fixedlength') resamples so that y has
0014 % n elements (with equal stepsize)
0015 %
0016 
0017 if sum(size(x)>1)==1, x=x(:).'; end
0018 dx=1e-5+sqrt(sum(abs(diff(x,1,2)).^2,1)); dx(isnan(dx))=1e-5;
0019 z=cumsum([0,dx]);
0020 n=size(x,2);
0021 
0022 if nargin>2 & strcmp(lower(type),'fixedlength'), step=z(end)/(step-1); end
0023 idx=interp1(z,1:n,0:step:z(end));
0024 y=interp1(1:n,x.',idx.').';

Generated on Tue 27-Mar-2007 12:06:24 by m2html © 2003