MATLAB Answers


How I applly a bandpass filter in a signal?

Asked by Guilherme de Melo on 14 Oct 2017
Latest activity Answered by Star Strider
on 14 Oct 2017

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.


Is this a homework assignment?

It is a seismic data of science research, but I never used matlab.

Log in to comment.

2 Answers

Answer by Star Strider
on 14 Oct 2017
 Accepted Answer

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
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.)


Log in to comment.

Answer by Chad Greene
on 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.


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today