MATLAB: How to calculate passband and stopband coefficients for signal filtering

filtersignal processing

Hi All
using the following code, I need that my passband frequency be 250 Hz , and the Stop Band at 512 Hz. how do I calculate Wp and Ws to insert in the code ?
Ts = 0.001; % Sampling Interval (s)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 0.001; % Passband Frequency For Lowpass Filter (Hz)
Ws = 0.0012; % Stopband Frequency For Lowpass Filter (Hz)
Rp = 1; % Passband Ripple For Lowpass Filter (dB)
Rs = 50; % Stopband Ripple (Attenuation) For Lowpass Filter (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp); % Calculate Filter
[sos,g] = zp2sos(z,p,k); % Second-Order-Section For Stability
% A_Filt = filtfilt(sos,g,A); % Filter Signal
figure
freqz(sos, 2^14, Fs) % Filter Bode Plot (Check Performance)
set(subplot(2,1,1), 'Xlim',[0 1])
set(subplot(2,1,2), 'Xlim',[0 1])

Best Answer

Specifying both passband and stopband frequencies (and without other arguments to the ellip function) means that you are designing a bandpass filter. I appreciate your quoting my code, however I also posted several examples of elliptical filters using bandpass filters.
For your filter, replace ‘Wp’ with:
Wp = [250 512]/Fn; % Passband Frequencies For Bandpass Filter (Hz)
and ‘Ws’ with:
Ws = [0.99 1.01]*Wp; % Stopband Frequencies For Bandpass Filter (Hz)
or define it yourself, similarly to the way I defined ‘Wp’ here. Note that for a bandpass filter, the stopbands must be outside the passbands.