How to smoothly interpolate signal data using another datasets timestepping
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sam Hurrell
am 28 Mär. 2024
Kommentiert: Star Strider
am 29 Mär. 2024
I have 2 datasets (data1 and data2), each with a time column with different timesteps (data2 always has the larger step size) from 0 to around 95-99. I'd like to create a new dataset: interpolated from data2 with the same timestepping as data1. I currently have a script that calculates values from a linear interpolation, but it looks a bit rough (see attached JPG). Is there a function that can do this more smoothly?
1 Kommentar
KSSV
am 28 Mär. 2024
JPG is not attched...Attach your data here..this can be done.
Meanwhile have a look on the functions smooth
Akzeptierte Antwort
Star Strider
am 28 Mär. 2024
Yes. If you have the Signal Processing Toolbox, use the resample function. You can define the sampling frequency of the resampled signal using this approach (where ‘data#’ denotes the signal and ‘time#’ denotes the corresponding time vector) —
Fs1 = 1/mean(diff(time1)) % ‘data1’ Sampling Frequency
[data2r, time2r] = resample(data2, time2, Fs1); % Resample ‘data2’ To Fs1
This is preferable to using interp1 because resample incorporates an anti-aliasing filter, and is specifically designed for signal processing applications. (The only poroblem with this approach is that resampling to a higher sampling frequency creates data where no data previously existed. If this is not a problem, then proceed with it. Resampling to a lower sampling frequency is generally the preferred approach for this reason.)
.
2 Kommentare
Star Strider
am 29 Mär. 2024
As always, my pleasure!
There is nothing in the resample documentation about dealing with a delay like that. I note that ‘data2’ goes from 0.7 to 1000.7 so one option sould simply be to subtract 0.7 from the ‘data2’ time so that it begins at 0, and then resample it, or resample it first and then deal with the time vector differences. If both were supposedly collected at the same times with the same instrument (or something that correlates their times in some way), then that becomes a problem with missing data for the first 0.7 and then deleting the data after 1000. I would go with subtracting 0.7 from the time vector, and then resampling it, however I’m not sure that there’s any recommended ‘correct’ way of dealing with this situation. I have methodological problems recommending extrapolating to 0 on the beginning of the time vector (because I am generally opposed to extrapolation), and then deleting the signal at 1000.7, however that is another option. You could do that with an interp1 call.
In the end, it depends on how important it is to align the signals with respect to their recorded times, and whether just shifting the ‘data2’ time by subtracting 0.7 would be a problem with your data analysis.
I don’t have an answer for that, so I settled for discussing the possibilities.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!