Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

interp1 to a certain number (time normalization of data)

58 views
Skip to first unread message

Stefan Litzenberger

unread,
Oct 5, 2010, 12:20:04 PM10/5/10
to
Dear all!
I am facing a small problem (Matlab 7.0.4), which I hope might be solved by some of you. I am trying to interpolate one-dimensional data of different measurements of different lenghts to one exact length for time normalizaton of data.

Let's assume we have recorded two vectors of different lenghts:
a = 1:14;
b = 9:42;

I want both vectors to have a length of 100 (but within the given boundaries (1:length(a) and 1:length(b) respectively).
In the end I will use
a_int = interp1(1:length(a),a,xi_a);

When I calculate my
xi_a = 1:length(a)/100:length(a)

I - no surprise - get only 93 values. So I use

xi_a = 1:(length(a)-1)/100:length(a);
this gives length(xi_a) = 101

So:
xi_a = 1:(length(a)-1)/100:length(a)-((length(a)-1)/100);
gives the exact 100 values for xi_a, but my last xi_a value = 13.8700 and not = 14 as in my original measurement.

How can I manage this within the original x-range and without extrapolation?

I am looking forward to your replies. They are highly welcome
Regards
Stefan

Ross W

unread,
Oct 6, 2010, 1:10:05 AM10/6/10
to
"Stefan Litzenberger" <litzen...@technikum-wien.at> wrote in message <i8fj7k$49g$1...@fred.mathworks.com>...

Not sure I understand, but ...

Have you tried linspace?

e.g. linspace(a(1),a(end),100)

Ross

Stefan Litzenberger

unread,
Oct 6, 2010, 3:31:04 AM10/6/10
to
Ross,
thank you for your quick reply. But that's not quite what I was looking for. In the meantime I got the solution:

xi_a = 1:(length(a)-1)/(100-1):length(a);

Regards
Stefan

Jan Simon

unread,
Oct 6, 2010, 4:25:24 PM10/6/10
to
Dear Stefan,

Matlab's INTERP1 is slow. If the input and the output of the interpolation is equally spaced, this function might be helpful:
http://www.mathworks.com/matlabcentral/fileexchange/25463
Example for calling:
x = rand(1, 30);
y = ScaleTime(x, 1, 30, 100);
This scales the values of x from index 1 to index 30 to a vector of 100 elements.

Jan

Stefan Litzenberger

unread,
Oct 7, 2010, 9:44:04 AM10/7/10
to
Dear Jan,

Thank you. A very handy function. Will certainly use it in the future.

Lieben Gruß nach Heidelberg
Stefan

0 new messages