interp1 yields NaN for two signals interpolation of the same sampling frequency

1 view (last 30 days)
Dear friends,
I am trying to interpolate two signals of the same sampling rate (1000 Hz). One signal (X1) has the length of 863 while the other (X2) has a length of 1121. I would like to make both of them equal in length. This is the code I wrote for interpolation:
t1=0:1/1000:(length(X1)-1)/1000; t2=0:1/1000:(length(X2)-1)/1000;
NewX1=interp1(t1,X1,X2);
The problem is all values are 'NaN' after the 863th in signal NewX1. "Interp1" works if the original signal (X1) is of different sampling rate. Why does does not it work for two signals of the same sampling rate?
Thank you very much for your assistance in advance.
Abbas Orand

Accepted Answer

Wayne King
Wayne King on 3 Aug 2012
Edited: Wayne King on 3 Aug 2012
I think you have the wrong idea about interpolation here. interp1 assumes that X1 has been sampled at a lower rate than X2. So the limits of the time (or spatial) vector "t" are the same for both X1 and X2, but X2 has been sampled on a finer grid. The inputs to interp1 should NOT be a time vector and the two signals, the inputs should be:
1.) the coarser time vector
2.) the signal vector with the coarser sampling
3.) the more finely sampled time vector.
For example:
t = 0:0.1:2*pi;
x = cos(t);
ti = 0:0.01:2*pi;
y = interp1(t,x,ti);
plot(t,x,'b'); hold on;
plot(ti,y,'k')
You have observed two signals over different time scales, one over 863 milliseconds and one over 1.12 seconds. How do you know how X1 will behave over the remaining 257 milliseconds?
  1 Comment
Abbas Orand
Abbas Orand on 4 Aug 2012
Hello King,
Thank you very much for the reply. It helped me very much.
Actually, these data for the stance and swing phases of several steps. The objective is to make all of them of equal length for further analysis.I understand your point that it is not possible to predict how the signals of short length are going to behave for the remaining time we extend them.
But since the whole other variables affecting the experiment are the same like the weight of the subject, I assume that the trial to trial variation is negligible. Therefore, I like to assume that the same thing for each trial happens within the same length of time.
I hope I could explain what I mean.
I thank you very much again for your reply.
Best regards,
Abbas

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!