Pages

21.6.11

Resample in Matlab

This is a simple function to resample a vector in matlab. I now there might be more elegant ways to do it, but this one works and it's simple

function newvector=resample(vector,newlen)

%%%%%%%%%%%%%%%%%%%%

%This function uses linear interpolation to change the number of samples

% Copyright 2011 Andrés Gonzalez

%%%%%%%%%%%%%%%%%%%%

len=length(vector);

x=1:len;x=x';y=vector;

xx=1:(len-1)/(newlen-1):len;

xx=xx';

yy=interp1(x,y,xx,'linear');

newvector=yy;

end

0 commenti:

Post a Comment