How I applly a bandpass filter in a signal?

9 vues (au cours des 30 derniers jours)
Guilherme de Melo
Guilherme de Melo le 14 Oct 2017
Modifié(e) : Mikk Laanes le 2 Juil 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 commentaires
Star Strider
Star Strider le 14 Oct 2017
Is this a homework assignment?
Guilherme de Melo
Guilherme de Melo le 14 Oct 2017
It is a seismic data of science research, but I never used matlab.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 14 Oct 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 commentaires
Chappi
Chappi le 17 Juin 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
Mikk Laanes le 2 Juil 2020
Modifié(e) : Mikk Laanes le 2 Juil 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.

Connectez-vous pour commenter.

Plus de réponses (2)

Chad Greene
Chad Greene le 14 Oct 2017
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 commentaire
hssien rezk
hssien rezk le 14 Avr 2019
Modifié(e) : hssien rezk le 14 Avr 2019
thanks for your work , and i want to ask how i can apply this filter in matrix not vector .

Connectez-vous pour commenter.


giannisk patra
giannisk patra le 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?

Community Treasure Hunt

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

Start Hunting!

Translated by