필터 지우기
필터 지우기

Interpolate non-uniform signals

조회 수: 37 (최근 30일)
MDias
MDias 2021년 5월 31일
댓글: Star Strider 2021년 5월 31일
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
MDias
MDias 2021년 5월 31일
Hi John,
My signal corresponds to the position of an object. The object sometimes jumps arround and there are omisions due to detection issues. This is data for one block but the actual recording lasts many days. The interpolated data is not really what I care about and filling missing values with NaN is perfectly fine.
Cheers
MDias
MDias 2021년 5월 31일
@John D'Errico I just saw your edit.
The swings are what I care about (transitions between 300 and the last bit at 100 for example). But for the next steps I do need each 12h block to be sampled at 1Hz (43200 samples).
Cheers

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 5월 31일
편집: Jan 2021년 5월 31일
John D'Erricos warning is important: The data do not look like an interpolation is fair. But if you have a good reason to do this, this is how it works:
data2 = interp1(data(:, 1), data(:, 2), 0:(12 * 3600 - 1));
A comparison:
figure;
plot(data(:, 1), data(:, 2), 'ro');
hold on;
plot(0:43199, data2, '-');
You see the typical effect of removed spikes for a linear interpolation.
  댓글 수: 2
MDias
MDias 2021년 5월 31일
Thanks! I'll test it
John D'Errico
John D'Errico 2021년 5월 31일
You definitely never want to use a spline interpolant with data like this. But even a linear interpolant may be too much, as the linear interpolant tends to average neighboring points together, but somewhat randomly.
plot(t,X,'.')
[min(t),max(t)]
ans =
0 43198.1130371094
that = 0:1:max(t);
Xhat0 = interp1(t,X,that,'nearest');
Xhat1 = interp1(t,X,that,'linear');
plot(that,Xhat0,'.')
plot(that,Xhat1,'.')
So the nearest neighbor interpolant retains much more of the character of the original plot, showing the dual nature of the series, where it seems to oscillate between two distinct levels.
Once the data is onto a uniform spacing, now some variety of Savitsky-Golay filter (with a wide window), or perhaps a wide window median filter might be appropriate.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Star Strider
Star Strider 2021년 5월 31일
Try something like this, using the Signal Processing Toolbox resample function —
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
MDias
MDias 2021년 5월 31일
Thanks! I'll give it a try.
Cheers
Star Strider
Star Strider 2021년 5월 31일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by