1
votes

I'd like to try out the elliptic filter design function from SciPy in scipy.signal.filter_design.ellip. I'm familiar with the filter design functions in Octave, but I'm not sure how to use this:

From the documentation at http://www.scipy.org/doc/api_docs/SciPy.signal.filter_design.html

ellip(N, rp, rs, Wn, btype = 'low', analog = 0, output = 'ba')

Elliptic (Cauer) digital and analog filter design.

Description:

Design an Nth order lowpass digital or analog elliptic filter and return the filter coefficients in (B,A) or (Z,P,K) form.

See also ellipord.

I understand N (order), btype (low or high), analog (true/false), and output (ba vs. zpk).

What are rp, rs, and Wn and how are they supposed to work?

From my experience with Octave, I'm guessing that rp and rs have to do with the maximum allowed ripple in the pass and stop bands, and that Wn is a weight or controls the cutoff frequency, but how these work isn't documented and I can't find any examples.

2

2 Answers

1
votes

I think this function is the same as Octave or MATLAB, so you can read the MATLAB document about it.

http://www.mathworks.com/help/toolbox/signal/ref/ellip.html

1
votes

I believe HYRY is correct. From my experience using the Python Matlab clone scripts they work well, with the exception of poor documentation. Yes, Rp and Rs are the maximum allowable ripple in the passband and stopband respectively. The Wn is the digital cutoff, or edge frequency.

So...here's some code on how to use it to replicate the filter that the mathworks uses as an example:

import pylab
import scipy
import scipy.signal
[b,a] = scipy.signal.ellip(6,3,50,300.0/500.0);

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
plt.title('Digital filter frequency response')
ax1 = fig.add_subplot(111)
h,w = scipy.signal.freqz(b, a)
plt.semilogy(h, np.abs(w), 'b')
plt.semilogy(h, abs(w), 'b')
plt.ylabel('Amplitude (dB)', color='b')
plt.xlabel('Frequency (rad/sample)')
plt.grid()
plt.legend()
ax2 = ax1.twinx()
angles = np.unwrap(np.angle(w))
plt.plot(h, angles, 'g')
plt.ylabel('Angle (radians)', color='g')
plt.show()

sorry the format is so lame, but it works! You'll notice that the frequency scale is different than matlab shows, it's just cosmetic. This is what you get: Elliptical Filter with AWESOME Cutoff