How I applly a bandpass filter in a signal?

13 次查看(过去 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.

采纳的回答

Star Strider
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
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
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
Chad Greene 2017-10-14
Hi Guilherme,
If you have the signal processing toolbox you can use my filter1 function. Syntax would be
yfilt = filter1('bp',y,'fc',[0 20],'fs',Fs);
where Fs is the sampling frequency.
  1 个评论
hssien rezk
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
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?

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by