how to do sampling and filtering for the data?

31 visualizaciones (últimos 30 días)
Keshasni Earichappan
Keshasni Earichappan el 15 de Ag. de 2021
Comentada: Star Strider el 15 de Ag. de 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

Respuesta aceptada

Star Strider
Star Strider el 15 de Ag. de 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.
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 comentarios
Keshasni Earichappan
Keshasni Earichappan el 15 de Ag. de 2021
Editada: Keshasni Earichappan el 15 de Ag. de 2021
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 el 15 de Ag. de 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:
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
.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by