MATLAB Answers

0

Band Pass Filter Design

Asked by Ricardo Whitaker on 7 Nov 2018 at 0:52
Latest activity Commented on by Star Strider
on 10 Nov 2018 at 22:36
Hello everyone, I am trying to build a bandpass filter in matlab for an EMG signal. I know I want the band to be between 10 and 500 Hz. However, using fdesign.bandpass function it gives me many parameters ('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2'). Which value should I use for each parameter? I appreciate the help.

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 7 Nov 2018 at 2:14

If you have R2018a or later, you can use the bandpass (link) function.
Otherwise, try this:
t = your_time_vector;
EMG = your_signal;
Fs = ...; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [10 500]/Fn; % Passband Frequency Vector (Normalised)
Ws = [8 510]/Fn; % Stopband Frequency Vector (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Attenuation (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp,'bandpass'); % Default Here Is A Lowpass Filter
[sos,g] = zp2sos(z,p,k); % Use Second-Order-Section Implementation For Stability
EMG_filtered = filtfilt(sos,g,EMG); % Filter Signal (Here: ‘EMG’)
figure
freqz(sos, 2^14, Fs) % Bode Plot Of Filter
% set(subplot(2,1,1), 'XLim',[0 Fn]) % Optional, Change Limits As Necessary
% set(subplot(2,1,2), 'XLim',[0 Fn]) % Optional, Change Limits As Necessary
figure
plot(t, EMG_filtered)
grid
Note that your sampling frequency ‘Fs’ must be greater than 1000 Hz for this filter to work. The upper limit of your filter passband must be less than the Nyquist frequency.

  2 Comments

Thanks for the answer. I keep getting an error saying that my cutoff freq should be between 0 and 1
Star Strider
on 10 Nov 2018 at 22:36
My pleasure.
First: there was a slight error in the passband and stopband frequency vectors.
Use these instead:
Wp = [10 495]/Fn; % Passband Frequency Vector (Normalised)
Ws = [ 8 498]/Fn; % Stopband Frequency Vector (Normalised)
Second: ‘Note that your sampling frequency ‘Fs’ must be greater than 1000 Hz for this filter to work. The upper limit of your filter passband must be less than the Nyquist frequency.’
Third: If you want a highpass filter instead of a bandpass filter with a sampling frequency of 1000 Hz, change these lines to:
Wp = 10/Fn; % Passband Frequency Vector (Normalised)
Ws = 8/Fn; % Stopband Frequency Vector (Normalised)
. . .
[z,p,k] = ellip(n,Rp,Rs,Wp,'high'); % Default Here Is A Lowpass Filter
If your sampling frequency is 1000 Hz, and you want to pass all frequencies above 10 Hz, that will design a sufficient filter.

Sign in to comment.