7

I have two vectors: sensorA of length 927 and sensorB of length 1250. I would like to make them of the same length. The resample() function in MATLAB is very noisy at the edges and I need atleast reasonably good accuracy throughout.

I understand that resampling can be done by interpolation, but how do I implement it in the most efficient way. I need to stretch 927 to 1250 as uniformly as possible.

I was wondering if I could do something like this:

  1. I need 333 new samples in the shorter vector. So for every 3 values, I insert the average (midpoint) of two consecutive values in between then. => 309 samples inserted
  2. For the remaining I insert again for every 38 samples (927/(333-309))

Does this make sense? I still won't be able to get an exact interpolation. Is there any other function that I could use? (besides interp() because it requires an integral resampling rate?)

Imelza
  • 301
  • 1
  • 7
  • 19
  • Is there a reason that interp1() will not work for you? You can ask it to provide interpolation to an arbitrary set of output points. http://www.mathworks.com/help/techdoc/ref/interp1.html – Colin K Feb 15 '11 at 06:26
  • if you give it a better title, I'll give you a +1, eg "re-sampling 2 data sets to give the same length in Matlab" – mor22 Feb 15 '11 at 11:38

3 Answers3

6

From a signal-processing view, you should NOT just insert a sample every 3 values. That would be non-uniform stretching and would ruin your signal. The resample function is what you want. Try changing the parameters for n and/or beta. You may need to pad your signal as described here to reduce the edge effects.

k107
  • 15,882
  • 11
  • 61
  • 59
0

Resampling a bandlimited signal is identical to interpolation using an infinite Sinc interpolation kernel, and pretty close to windowed Sinc interpolation with a well chosen window. See this Stanford CCRMA website for details.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
0

To do interpolation, use interp1. For your purposes, this might be good enough, though, as stated above, resample is the correct thing to do.

nibot
  • 14,428
  • 8
  • 54
  • 58