Interpolate non-uniform signals
Show older comments
I have a 12 hour signal X, that was recorded at 1Hz.
However, some samples were missed and I don't have all 43200 samples (the 12h period in seconds [1Hz]). Furthermore, the sampling rate does not seem to be constant, meaning that besides missed samples, the interval between the ones I do have might be slightly above or below 1s.
Together with my signal of interest (X) I also recorded the timestamps (t) at which each sample was recorded (lengths of X and t are equal).
I need to resample/interpolate my signal sucha that I have 43200 samples.
Any suggestion how I could accomplish this?
Thanks in advance!
5 Comments
Jan
on 31 May 2021
Of couse with an interpolation. If you show us, in which format your data are availble, it is easy to post the corresponding interp1 command.
Do you assume, that the data are smooth? Would you prefer a fair linear interpolation?
MDias
on 31 May 2021
John D'Errico
on 31 May 2021
Edited: John D'Errico
on 31 May 2021
Magic would be easy, if we only had a magic wand. :)
t = data(:,1);
X = data(:,2);
t(1:10)
ans =
0
0.750389099121094
1.74427032470703
2.78888702392578
3.73203277587891
4.77415466308594
5.85184478759766
6.77722930908203
7.83953094482422
8.87712097167969
diff(t(1:10))
ans =
0.750389099121094
0.993881225585938
1.04461669921875
0.943145751953125
1.04212188720703
1.07769012451172
0.925384521484375
1.06230163574219
1.03759002685547
How wild is the spacing?
max(diff(t))
ans =
1.14429473876953
min(diff(t))
ans =
0.750389099121094
So not too bad.
Your data really is unequally spaced. You want to interpolate this onto a uniform spacing, perhaps at every 1 unit of time? Before we go any further, lets plot it. ALWAYS PLOT EVERYTHING. And then look carefully at the plot.
plot(t,X,'.')

Sigh. You want to interpolate that????? Wildly oscillatory swings, what appear to be effectively random spikes and outliers. As well, a system that appears to oscillate between two distinct levels for a large part of the plot.
Can we make it easier, and just pick random numbers for a result? :)
What would a meaningfully interpolated plot look like here? If you were able to draw a good curve through that mess, would it be smooth? In that case, you do NOT want to interpolate, but you want to do smoothing. So what would you think is a reasonable result from that data?
MDias
on 31 May 2021
MDias
on 31 May 2021
Accepted Answer
More Answers (1)
Star Strider
on 31 May 2021
LD = load('example_data.mat');
data = LD.data;
t = data(:,1);
s = data(:,2);
Fs = 1; % Sampling Frequency (Hz)
[sr,tr] = resample(s,t,1); % Resample At Uniform Sampling Frequency Of 1 Hz, Return Interpolated Signal (‘sr’) and Time (‘tr’) Vectors
figure
plot(t, s)
hold on
plot(tr,sr)
hold off
grid
legend('Original','Resampled', 'Location','best')
.
2 Comments
MDias
on 31 May 2021
Star Strider
on 31 May 2021
My pleasure!
The resample function uses a common technique to interpolate unevenly-sampled signals to a uniform sampling frequency, since this is required by all digital signal processing procedures that I am aware of. The function uses an anti-aliasing filter to prevent aliased signals from appearing in the resampled vectors, a common problem using simple interpolation.
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


