How I applly a bandpass filter in a signal?
20 ビュー (過去 30 日間)
古いコメントを表示
I would like to know how I applly a bandpass filter between 0 and 20 Hz in a signal that the it variable to be 'signal' in matlab.
2 件のコメント
採用された回答
Star Strider
2017 年 10 月 14 日
Since it is research, here is your filter:
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [1.0 20]/Fn; % Passband Frequency (Normalised)
Ws = [0.5 21]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sosbp, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(sosbp, gbp, original_signal); % Filter Signal
Insert the correct value for the sampling frequency ‘Fs’. It must be at least 45 Hz for this filter to work.
NOTE — This bandpass filter will eliminate d-c (constant) offset or a slowly varying baseline. A filter with a lower passband of 0 Hz is a lowpass filter, not a bandpass filter. A lowpass filter requires only changes in ‘Wp’ and ‘Ws’ to pass everything from 0 Hz to 20 Hz:
Wp = 20/Fn; % Passband Frequency (Normalised)
Ws = 21/Fn; % Stopband Frequency (Normalised)
The default design for discrete filters is a lowpass filter, so you do not specifically have to specify 'low' here. (All other designs require transformation from the lowpass design. The Signal Processing Toolbox does this if you ask it to.)
6 件のコメント
Chappi
2020 年 6 月 17 日
Hi, can I ask why dont you just use
bandpass(signal,[0 20],45)?
WHy do you have to go through so many steps Star Strider? I am a researcher as well but very new in signal processing. THank you very much
Mikk Laanes
2020 年 7 月 2 日
編集済み: Mikk Laanes
2020 年 7 月 2 日
@Chappi, by just using the 'bandpass' command, you allow Matlab to use a minimum-order filter with a stopband attenuation of 60 dB. If this is sufficient for your application, then go with that. Star Strider's method of designing allows one to make the filter requirements more strict, or relaxed. Because you can then easily control the stopband and passband ripple, as well as the transition width.
To provide an example of having the possibility to apply stricter attenuation in the stopband, I have attached a figure below. Hope that helps to explain.
By the way, another easy way of designing a filter (let's take the already suggested filter) is using the command (but I do not know how much stability is lost by not using the 'zp2sos' command?):
lpFilt = designfilt('bandpassiir', ...
'StopbandFrequency1',0.5,'PassbandFrequency1', 1, ...
'PassbandFrequency2',20,'StopbandFrequency2', 21, ...
'StopbandAttenuation1',150,'PassbandRipple', 1, ...
'StopbandAttenuation2',150, ...
'DesignMethod','cheby2','SampleRate',fs);
figure
freqz(lpFilt,2^16,fs)
filtered_signal = filtfilt(lpFilt, original_signal);
Maybe to bear in mind that allowing a passband ripple of 1dB, can cause an error of
in the magnitude of the signal.
その他の回答 (2 件)
Chad Greene
2017 年 10 月 14 日
Hi Guilherme,
yfilt = filter1('bp',y,'fc',[0 20],'fs',Fs);
where Fs is the sampling frequency.
1 件のコメント
hssien rezk
2019 年 4 月 14 日
編集済み: hssien rezk
2019 年 4 月 14 日
thanks for your work , and i want to ask how i can apply this filter in matrix not vector .
giannisk patra
2019 年 3 月 20 日
I would like to know how I applly a bandpass filter between 2 and 45 Hz in a signal that the it variable to be 'signal' in matlab. I have fs=160Hz. Can you please tell me the matlab code for this?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Analog Filters についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!