how to do sampling and filtering for the data?

14 views (last 30 days)
Keshasni Earichappan on 15 Aug 2021
Commented: Star Strider on 15 Aug 2021
hi good day..Anyone know how to do the steps as i mentioned below.I have tried but i coudn't find the right results
1-MC-sensor data need to sampled at 1000Hz
2-Moving Average method was used to down-sample the mc-sensor data to 100 Hz
3-MC-sensor data need to filtered at 5 Hz using a 4th order butter-worth filter

Star Strider on 15 Aug 2021
There is no reason to downsample it. Just resample it to a 1 kHz sampling frequency (since the sampling intervals are not regular), then filter it. Calculating a moving average will not downsample it anyway. It will just filter it, and that is not necessary since the actual desired filtering will be with the Butterworth filter.
Fs = 1E+3;
Fn = Fs/2;
[MCvr,tr] = resample(T1.('MC[v]'),T1.Time, Fs);
[z,p,k] = butter(4, 5/Fn,'low');
[sos,g] = zp2sos(z,p,k);
MCvrfilt = filtfilt(sos,g,MCvr);
figure
subplot(2,1,1)
plot(T1.Time, T1.('MC[v]'))
yl = ylim;
grid
subplot(2,1,2)
plot(tr, MCvrfilt)
ylim(yl)
grid .
Star Strider on 15 Aug 2021
My pleasure.
Use the resample function to resample the data to a different sampling frequency. The moving average method is not appropriate for that. Use the filter either with the original or resampled signal. It should work for both, however ‘Fs’ and ‘Fn’ will be different. One option for that is simply to downsample it originally:
Fs = 1E+2; % Resample At 100 Hz Instead Of 1000 Hz
Fn = Fs/2;
[MCvr,tr] = resample(T1.('MC[v]'),T1.Time, Fs);
[z,p,k] = butter(4, 5/Fn,'low');
[sos,g] = zp2sos(z,p,k);
MCvrfilt = filtfilt(sos,g,MCvr);
figure
subplot(2,1,1)
plot(T1.Time, T1.('MC[v]'))
yl = ylim;
grid
subplot(2,1,2)
plot(tr, MCvrfilt)
ylim(yl)
grid .