MATLAB: How I applly a bandpass filter in a signal

bandpass matlab

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.

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