フィルターのクリア

How to smoothly interpolate signal data using another datasets timestepping

5 ビュー (過去 30 日間)
Sam Hurrell
Sam Hurrell 2024 年 3 月 28 日
コメント済み: Star Strider 2024 年 3 月 29 日
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 件のコメント
KSSV
KSSV 2024 年 3 月 28 日
JPG is not attched...Attach your data here..this can be done.
Meanwhile have a look on the functions smooth

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2024 年 3 月 28 日
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 件のコメント
Sam Hurrell
Sam Hurrell 2024 年 3 月 29 日
That's exaclty what I was looking for thanks.
Follow-up question: how do I do the same process to data that has to be offset in time by an irregular amount? E.g. if data1's time was 0:1:1000 and data2's was 0.7:2.5:1000.7, how could I make data2r's time equal 0:1:1000?
Star Strider
Star Strider 2024 年 3 月 29 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by