Interpolate/Adjust to new Sampling Rate

Hello,
i have data received from a accelerometer with a sampling frequency of 10Hz.
But the time stamps in the data file are not equidistant, the sampling time interval is changin.
How can i "fix" the time stamps with my corresponding acceleration values?
So far i have just calculated the mean value for the sampling time interval (for further fft calculations) -> t_s = mean(diff(t))
Is there a better way to do that? maybe by interpolation?

 Respuesta aceptada

Star Strider
Star Strider el 18 de Mayo de 2020

1 voto

Use the Signal Processing Toolbox resample function. The advantage it offers over simply interpolating is that it uses an anti-aliasing filter to keep the resamples signal free of extraneous frequencies.

4 comentarios

Felix Westphal
Felix Westphal el 19 de Mayo de 2020
Editada: Felix Westphal el 19 de Mayo de 2020
As far as i understood, resample() resamples the input sequence, x, at p/q times the original sample rate.
But since the Sampling Interval of the recorded data is changing over time (sometimes the configured 0.1s but sometimes also less than 0.05s), I am not able to determine a fixed factor to resample the whole signal with.
The length of the signal is given in the last time stamp of the data. (t_w = t(end)).
so I need to adapt the acceleration values to the new "fixed" times-axis (time stamps) like:
t = 1:t_s:t_w;
with t_s = 1 / f_s. (and f_s from the MatLab Mobile App Sensor settings, 10Hz)
Or is there a way to use resample() with an adaptive factor?
Star Strider
Star Strider el 19 de Mayo de 2020
The resample function can do more than just that. See the section on Resample a Nonuniformly Sampled Data Set for a specific example of how to do what you want. (The ‘p’ and ‘q’ arguments there allow you to choose more or fewer points in the output. The default option sets them at 1 and 1 so the output is the same size as the input, with regularly-sampled points.) Be sure to get both outputs, so that you have the resampled signal as well as the new sampling times.
Felix Westphal
Felix Westphal el 20 de Mayo de 2020
That worked perfectly, thank you! :)
Star Strider
Star Strider el 20 de Mayo de 2020
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 18 de Mayo de 2020

Comentada:

el 20 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by