# how to do sampling and filtering for the data?

조회 수: 36(최근 30일)
Keshasni Earichappan 2021년 8월 15일
댓글: Star Strider 2021년 8월 15일
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 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.
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표시숨기기 이전 댓글 수: 1
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:
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
.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Digital Filter Design in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by