Hello everyone, I wrote a simple code to analyze an accelerometric signal in the frequency domain and I saw that the magnitudes over the 300 Hz are quite negligible. I used a Chebyshev type 1 lowpass filter and it works:
%%Design a Lowpass IIR Filter
N=7;
Fp=300;
Ap=1;
h=fdesign.lowpass('N,Fp,Ap', N, Fp, Ap, Fs);
d=design(h, 'cheby1');
%%Apply the filter to to Smooth out the Signal
xfilter = filter(d,x2);
%%Overlay the filtered signal on the original signal.
% Filtered signal is delayed
figure;
plot(t2,x2,'b',t2,xfilter,'r');
grid on;
legend({'Original Signal','Filtered Signal'});
%set(gcf,'NumberTitle','Off', 'Name','Filtered Signal vs. Actual Signal');
%%Compare the original signal and delay compensated filtered signal
figure;
xfiltfilt = filtfilt(d.sosMatrix,d.ScaleValues,x2);
plot(t2,x2,t2,xfiltfilt);
grid on
legend({'Original Signal','Actual (filtered and delayed signal)'});
Now, I'd like to use a Butterworth lowpass filter: how can I modify my script? Thank you very much!

 採用された回答

Star Strider
Star Strider 2016 年 10 月 11 日

0 投票

I would just substiture 'butter' here:
d=design(h, 'butter');
I would also add 'Ast' to the fdesign.lowpass parameters for a Butterworth design.
Also, use filtfilt for phase-neutral filtering, not filter, so your*|‘xfilter’|* assignment becomes:
xfilter = filtfilt(d,x2);
This applies to all filter designs, so try it with your Chebyshev Type I filter as well. The results will be different, perhaps noticeably so.

4 件のコメント

Guglielmo Giambartolomei
Guglielmo Giambartolomei 2016 年 10 月 12 日
編集済み: Guglielmo Giambartolomei 2016 年 10 月 12 日
Thank you Star Strider! I wrote this simple code for a Butterworth filter (I didn't use the design toolbox):
% Butterworth filter
Fc = 300;
Fs = 2400;
[b,a] = butter(10,Fc/(Fs/2));
figure;
freqz(b,a)
dataIn = x2;
%%Apply the filter to to Smooth out the Signal
xfilter = filter(b,a,dataIn);
%%Overlay the filtered signal on the original signal.
% Filtered signal is delayed
figure;
plot(t2,x2,'b',t2,xfilter,'r');
grid on;
legend({'Original Signal','Filtered Signal'});
%%Compare the original signal and delay compensated filtered signal
figure;
xfiltfilt = filtfilt(b,a,x2);
plot(t2,x2,t2,xfiltfilt);
grid on
legend({'Original Signal','Actual (filtered and delayed signal)'});
What do you think about it? Thanks!
Star Strider
Star Strider 2016 年 10 月 12 日
I would use buttord to calculate the optimal filter order, and convert it to second-order-section form for stability. My filter design procedure for IIR filters is here: How to design a lowpass filter for ocean wave data in Matlab?
Guglielmo Giambartolomei
Guglielmo Giambartolomei 2016 年 10 月 12 日
Thank you for sharing Star Strider.
Star Strider
Star Strider 2016 年 10 月 12 日
My pleasure.
If my Answer helped you. please Accept it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by