Home Resampling two vectors with interp1 or spline
Reply: 0

Resampling two vectors with interp1 or spline

user1747
1#
user1747 Published in May 27, 2018, 3:38 am

Situation:

I was trying to compare two signal vectors (y1 & y2 with time vectors x1 & x2) with different lengths (len(y1)=1000>len(y2)=800). For this, I followed the main piece of advice given hardly everywhere: to use interp1 or spline. In order to 'expand' y2 towards y1 in number of samples through an interpolation. So I want:

length(y1)=length(y2_interp)

However, in these functions you have to give the points 'x' where to interpolate (xq), so I generate a vector with the resampled points I want to compute:

xq = x2(1):(length(x2))/length(x1):x2(length(x2));
y2_interp = interp1(x2,y2,xq,'spline'); % or spline method directly

RMS = rms(y1-y2_interp)

The problem:

When I resample the x vector in 'xq' variable, as the faction of lengths is not an integer it gives me not the same length for 'y2_interp' as 'y1'. I cannot round it for the same problem.

I tried interpolate using the 'resample' function:

 y2_interp=resample(y2,length(y1),length(y2),n);

But I get an aliasing problem and I want to avoid filters if possible. And if n=0 (no filters) I get some sampling problems and more RMS.

The two vectors are quite long, so my misalignment is just of 2 or 3 points.

What I'm looking for:

I would like to find a way of interpolating one vector but having as a reference the length of another one, and not the points where I want to interpolate.

I hope I have explained it well... Maybe I have some misconception. It's more than i'm curious about any possible idea.

Thanks!!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302435 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO