## How I applly a bandpass filter in a signal?

### Guilherme de Melo (view profile)

on 14 Oct 2017
Latest activity Edited by hssien rezk

### hssien rezk (view profile)

on 14 Apr 2019 at 19:22

### Star Strider (view profile)

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 (view profile)

on 14 Oct 2017
Is this a homework assignment?
Guilherme de Melo

### Guilherme de Melo (view profile)

on 14 Oct 2017
It is a seismic data of science research, but I never used matlab.

### Star Strider (view profile)

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

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.

hssien rezk

### hssien rezk (view profile)

on 14 Apr 2019 at 19:21
thanks for your work , and i want to ask how i can apply this filter in matrix not vector .