0

I have the following problem:

I have two data vectors v1 (Length N1=13812) and v2 (Length N2=60002021). I have to bring both vectors in the same length N3 using interpolation bzw. downsampling, with the requirement: 2xN1.

Can somebody help me? My idea was to use: interp, interp1 and downsample to solve to problem. Is that the right approach?

mstich
  • 71
  • 1
  • 1
  • 5
  • 1
    you just need `interp1` or `interp2` depends on your dimension – Ander Biguri Sep 26 '16 at 08:43
  • here's an example why you shouldn't use interp1 to downsample a signal: t = 1:0.01:30; x=sin(t); plot(1:3:30, interp1(t, x, 1:3:30), 'o-'); hold on; plot(t, x); hold off – serigado Sep 26 '16 at 11:45

1 Answers1

0

Depending on your signal and sampling rate, using interp1 might not be the right thing to do. There is a resample function that you could use like this:

v1_resampled = resample(v1, 2, 1);
v2_resampled = resample(v2, p, q);

where the parameters p, q depending on the sampling rate of your vector v2.

Always check the beginning / end of the resampled vectors. Check NaNs and be careful if you have non equidistant sampling.

Another possible alternative would be to use a moving average / moving median filter on the higher resolution signal. The best resampling approach really depends on the signal type.

EBH
  • 10,350
  • 3
  • 34
  • 59
serigado
  • 168
  • 1
  • 7