How I applly a bandpass filter in a signal?
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Guilherme de Melo
il 14 Ott 2017
Modificato: Mikk Laanes
il 2 Lug 2020
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 Commenti
Risposta accettata
Star Strider
il 14 Ott 2017
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 Commenti
Chappi
il 17 Giu 2020
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
il 2 Lug 2020
Modificato: Mikk Laanes
il 2 Lug 2020
@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.
Più risposte (2)
Chad Greene
il 14 Ott 2017
Hi Guilherme,
yfilt = filter1('bp',y,'fc',[0 20],'fs',Fs);
where Fs is the sampling frequency.
1 Commento
hssien rezk
il 14 Apr 2019
Modificato: hssien rezk
il 14 Apr 2019
thanks for your work , and i want to ask how i can apply this filter in matrix not vector .
giannisk patra
il 20 Mar 2019
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 Commenti
Vedere anche
Categorie
Scopri di più su Filter Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!