interpolating data to different sample rate
18 views (last 30 days)
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?
Benjamin Thompson on 14 Feb 2022
You can use interp1 to interpolate, or resample, one signal onto the same set of time values as another.
Star Strider on 14 Feb 2022
If they are signals, use resample because it includes an anti-aliasing filter, and these appear to be signals.
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.