How to calculate passband and stopband coefficients for signal filtering?

48 views (last 30 days)
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])

Accepted Answer

Star Strider
Star Strider on 24 Dec 2019
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.
  16 Comments
Pallove Nautiyal
Pallove Nautiyal on 18 May 2022
please let me know the same @Danish khan if you got to know how to calculate stopband attenuation too.

Sign in to comment.

More Answers (1)

Maria Amr
Maria Amr on 3 Nov 2020
Hello Star Strider,
I have a signal, that is a well log Acoustic Impedance log and I need to apply a Antialias filter in coarser samoling that means a bandpass filter.
Sample frequency is 6562 per kilometer (28000 sample/4.27km). I do need to identify cutt off frequencies correctly. I applied your passband code into my dataset but my proffessors says: apply an anti-alias filter that has a flat spectrum over the band of interest. Would you please direct me how I can identify cutoff frequencies? Appreciated!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!