interpolating data to different sample rate
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have 2 data sets I want to correlate. One is sampled every second, and one is sampled at a much smaller interval (attached). I want to get them both to the same sampling rate by increasing the smaller intervalled one to 1s.
How would I go about this?
0 commentaires
Réponses (2)
Benjamin Thompson
le 14 Fév 2022
You can use interp1 to interpolate, or resample, one signal onto the same set of time values as another.
0 commentaires
Star Strider
le 14 Fév 2022
If they are signals, use resample because it includes an anti-aliasing filter, and these appear to be signals.
format longE
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/894275/Raw%20Data.xlsx', 'VariableNamingRule','preserve')
M1 = table2array(T1);
TimeStats = [mean(diff(M1(:,1))); std(diff(M1(:,1))); 1/mean(diff(M1(:,1)))]
[y,t] = resample(M1(:,2:end), M1(:,1), 1.25E+2); % Resample To Uniform 1.25 Hz Sampling Frequency
T1r = array2table([t, y], 'VariableNames',T1.Properties.VariableNames)
The data need to be resampled regardless, since the standard deviation of the sampling intervals is not near 0 as it should be, indicating irregulal sampling intervals. This is not appropriate for signal processing applications, all of which assuming regular sampling intervals.
To use these data in any signal processing application — and even for fft — they need to be resampled first to a consistent sampling frequency. I chose 125 Hz because the mean sampling frequency of the original data ia 124.514... Hz so this would likely produce the least disruptive resampling.
Resample the other signals at 125 Hz in order to compare them. Ideally, they also need to have identical sampling times (not simply the same sampling frequency) in order to do this correctly.
.
2 commentaires
Star Strider
le 15 Fév 2022
My pleasure!
format longE
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/895055/S%20Raw.xlsx', 'VariableNamingRule','preserve')
T1.Var1 = datetime(T1.Var1, 'InputFormat','''''yyyy-MM-dd HH:mm:ss.SSS''''')
TT1 = table2timetable(T1)
TotTime = TT1.Var1(end) - TT1.Var1(1)
TT1.ssSSS = TT1.Var1;
TT1.ssSSS.Format = 'ss.SSS' % Cumulative Time In s & ms
TssSSS = second(TT1.ssSSS);
TimeStats = [mean(diff(TssSSS)); std(diff(TssSSS)); 1/mean(diff(TssSSS))]
[y,t] = resample(TT1.Var2, TssSSS, 1.25E+2); % Resample To Uniform 1.25 Hz Sampling Frequency
T1r = array2table([t, y], 'VariableNames',{'Time (ms)','Var2'})
Now, the previous set and this set are all sampled at the same frequency (125 Hz), so they can all be processed with the same filters or other signal processing procedures.
.
Voir également
Catégories
En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!