how to do sampling and filtering for the data?

17 次查看(过去 30 天)
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
Star Strider 2021-8-15
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.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/712412/MC.txt', 'VariableNamingRule','preserve');
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
.
  2 个评论
Keshasni Earichappan
编辑:Keshasni Earichappan 2021-8-15
Thank you so much @Star Strider..It's worked :)much appreciated...Besides, can i know how to down-sample the data to 100Hz using moving average method because there are difference between sampling rates of this data with another data.I need to downsample it in order to match the sampling rate of my another data.
Star Strider
Star Strider 2021-8-15
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:
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/712412/MC.txt', 'VariableNamingRule','preserve');
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
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by