zahraesb
zahraesb

Reputation: 153

making two vectors the same length using interpolatoin in matlab

i want to interpolate a vector y1 of length 3 to get a vector y2 of length 6.which of the functions interp1 or resample should i use?

ex. y1=[1 2 3]; y2=[1 2 3 4 5 6 ];

resample(y1,length(y2),length(y1))

Upvotes: 0

Views: 878

Answers (1)

user2261062
user2261062

Reputation:

Use interp1.

Ex: You have a sinusoidal signal sampled every pi/4.

x = 0:pi/4:2*pi;
v = sin(x);

enter image description here

Now to want a finer sampling xq (every pi/16):

xq = 0:pi/16:2*pi;

The result will be:

vq1 = interp1(x,v,xq);

enter image description here

Where vq1 is a vector whose values are interpolated from vto satisfy the new sampling xq

PD: You can also pass as a parameter which type of interpolation you want: 'linear', 'nearest', 'cubic', etc...

Upvotes: 2

Related Questions