Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add See Also links and Example graphs to filter design *ord functions #3234

Merged
merged 4 commits into from

3 participants

@endolith

Also fixed a typo in a printed warning. Should that be converted to a raised warning or exception?

@coveralls

Coverage Status

Coverage remained the same when pulling a09d8dc on endolith:patch-3 into 6b6b41a on scipy:master.

scipy/signal/filter_design.py
@@ -1548,6 +1657,37 @@ def ellipord(wp, ws, gpass, gstop, analog=False):
The Chebyshev natural frequency (the "3dB frequency") for use with
`ellip` to give filter results.
+ See Also
+ --------
+ ellip : Filter design using order and critical points
+ buttord, cheb1ord, cheb2ord, : Find order and critical points
@rgommers Owner

Remove the comma after cheb2ord, otherwise the doc build crashes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
scipy/signal/filter_design.py
((9 lines not shown))
+ iirfilter : General filter design using order and critical frequencies
+ iirdesign : General filter design using passband and stopband spec
+
+ Examples
+ --------
+ Design an analog highpass filter such that the passband is within 3 dB
+ above 30 rad/s, while rejecting -60 dB at 10 rad/s. Plot its
+ frequency response, showing the passband and stopband constraints in gray.
+
+ >>> from scipy import signal
+ >>> import matplotlib.pyplot as plt
+
+ >>> N, Wn = signal.ellipord(30, 10, 3, 60, True)
+ >>> b, a = signal.ellip(N, 3, 60, Wn, 'high', True)
+ >>> w, h = signal.freqs(b, a, np.logspace(0, 3, 500))
+ >>> plt.plot(w, 20 * log10(abs(h)))
@rgommers Owner

log10 is not defined so the plot generation crashes, use np.log10 instead. This should be fixed in all examples in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rgommers
Owner

For the rest this looks good to me. Nice figures.

@endolith

Ok, fixed both of those.

@coveralls

Coverage Status

Coverage remained the same when pulling 19d71f5 on endolith:patch-3 into 6b6b41a on scipy:master.

@rgommers rgommers merged commit 7af62c8 into scipy:master
@rgommers
Owner

Thanks, merging

@endolith endolith deleted the endolith:patch-3 branch
@endolith

It looks like I screwed something up. The images show up on http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.signal.ellipord.html and http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.signal.buttord.html, but not on http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.signal.cheb1ord.html and http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.signal.cheb2ord.html Any idea why?

Also the lines like

butter, cheby1, cheby2, ellip, bessel : Filter design using order and
                                        critical points

are not working. I guess they can't have commas in them?

I could reword it to

butter : Filter design using order and critical points
cheby1, cheby2, ellip, bessel

also should have added an example/graph for iirdesign.

@rgommers
Owner

If you just paste the example into a clean IPython shell you'll see where it fails.The issue should be that you're using pi instead of np.pi. I failed to recheck the doc build after your last commit, my bad.

@rgommers
Owner

As for See Also, I think it's either a list of functions or a single function with a description behind it.

@endolith endolith restored the endolith:patch-3 branch
@endolith

I tried to add the fixes to the same patch, but they're not showing up here, maybe because it's already been merged?

They are visible here: endolith@137ace8

@rgommers
Owner

You indeed can't add commits to a PR that has been merged already. I'll cherry-pick and push that commit (after double checking it).

@rgommers
Owner

Pushed doc fix commit in 28f9d10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2014
  1. @endolith
  2. @endolith

    DOC: Add examples with plots for filter design functions

    endolith authored
    illustrating how the passband and stopband specs constrain the filter frequency response
  3. @endolith

    Fix typo in warning

    endolith authored
  4. @endolith
This page is out of date. Refresh to see the latest.
Showing with 142 additions and 2 deletions.
  1. +142 −2 scipy/signal/filter_design.py
View
144 scipy/signal/filter_design.py
@@ -566,6 +566,14 @@ def iirdesign(wp, ws, gpass, gstop, analog=False, ftype='ellip', output='ba'):
Zeros, poles, and system gain of the IIR filter transfer
function. Only returned if ``output='zpk'``.
+ See Also
+ --------
+ butter, cheby1, cheby2, ellip, bessel : Filter design using order and
+ critical points
+ buttord, cheb1ord, cheb2ord, ellipord : Find order and critical points
+ from passband and stopband spec
+ iirfilter : General filter design using order and critical frequencies
+
"""
try:
ordfunc = filter_dict[ftype][1]
@@ -634,7 +642,11 @@ def iirfilter(N, Wn, rp=None, rs=None, btype='band', analog=False,
See Also
--------
- buttord, cheb1ord, cheb2ord, ellipord
+ butter, cheby1, cheby2, ellip, bessel : Filter design using order and
+ critical points
+ buttord, cheb1ord, cheb2ord, ellipord : Find order and critical points
+ from passband and stopband spec
+ iirdesign : General filter design using passband and stopband spec
"""
ftype, btype, output = [x.lower() for x in (ftype, btype, output)]
@@ -1220,6 +1232,39 @@ def buttord(wp, ws, gpass, gstop, analog=False):
The Butterworth natural frequency (i.e. the "3dB frequency"). Should
be used with `butter` to give filter results.
+ See Also
+ --------
+ butter : Filter design using order and critical points
+ cheb1ord, cheb2ord, ellipord : Find order and critical points
+ from passband and stopband spec
+ iirfilter : General filter design using order and critical frequencies
+ iirdesign : General filter design using passband and stopband spec
+
+ Examples
+ --------
+ Design an analog bandpass filter with passband within 3 dB from 20 to
+ 50 rad/s, while rejecting at least -40 dB below 14 and above 60 rad/s.
+ Plot its frequency response, showing the passband and stopband
+ constraints in gray.
+
+ >>> from scipy import signal
+ >>> import matplotlib.pyplot as plt
+
+ >>> N, Wn = signal.buttord([20, 50], [14, 60], 3, 40, True)
+ >>> b, a = signal.butter(N, Wn, 'band', True)
+ >>> w, h = signal.freqs(b, a, np.logspace(1, 2, 500))
+ >>> plt.plot(w, 20 * np.log10(abs(h)))
+ >>> plt.xscale('log')
+ >>> plt.title('Butterworth bandpass filter fit to constraints')
+ >>> plt.xlabel('Frequency [radians / second]')
+ >>> plt.ylabel('Amplitude [dB]')
+ >>> plt.grid(which='both', axis='both')
+ >>> plt.fill([1, 14, 14, 1], [-40, -40, 99, 99], '0.9', lw=0) # stop
+ >>> plt.fill([20, 20, 50, 50], [-99, -3, -3, -99], '0.9', lw=0) # pass
+ >>> plt.fill([60, 60, 1e9, 1e9], [99, -40, -40, 99], '0.9', lw=0) # stop
+ >>> plt.axis([10, 100, -60, 3])
+ >>> plt.show()
+
"""
wp = atleast_1d(wp)
ws = atleast_1d(ws)
@@ -1269,7 +1314,7 @@ def buttord(wp, ws, gpass, gstop, analog=False):
W0 = nat / ((10 ** (0.1 * abs(gstop)) - 1) ** (1.0 / (2.0 * ord)))
except ZeroDivisionError:
W0 = nat
- print("Warning, order is zero...check input parametegstop.")
+ print("Warning, order is zero...check input parameter gstop.")
# now convert this frequency back from lowpass prototype
# to the original analog filter
@@ -1342,6 +1387,37 @@ def cheb1ord(wp, ws, gpass, gstop, analog=False):
The Chebyshev natural frequency (the "3dB frequency") for use with
`cheby1` to give filter results.
+ See Also
+ --------
+ cheby1 : Filter design using order and critical points
+ buttord, cheb2ord, ellipord : Find order and critical points
+ from passband and stopband spec
+ iirfilter : General filter design using order and critical frequencies
+ iirdesign : General filter design using passband and stopband spec
+
+ Examples
+ --------
+ Design a digital lowpass filter such that the passband is within 3 dB up
+ to 0.2*(fs/2), while rejecting at least -40 dB above 0.3*(fs/2). Plot its
+ frequency response, showing the passband and stopband constraints in gray.
+
+ >>> from scipy import signal
+ >>> import matplotlib.pyplot as plt
+
+ >>> N, Wn = signal.cheb1ord(0.2, 0.3, 3, 40)
+ >>> b, a = signal.cheby1(N, 3, Wn, 'low')
+ >>> w, h = signal.freqz(b, a)
+ >>> plt.plot(w/pi, 20 * np.log10(abs(h)))
+ >>> plt.xscale('log')
+ >>> plt.title('Chebyshev I lowpass filter fit to constraints')
+ >>> plt.xlabel('Normalized frequency')
+ >>> plt.ylabel('Amplitude [dB]')
+ >>> plt.grid(which='both', axis='both')
+ >>> plt.fill([.01, 0.2, 0.2, .01], [-3, -3, -99, -99], '0.9', lw=0) # stop
+ >>> plt.fill([0.3, 0.3, 2, 2], [ 9, -40, -40, 9], '0.9', lw=0) # pass
+ >>> plt.axis([0.08, 1, -60, 3])
+ >>> plt.show()
+
"""
wp = atleast_1d(wp)
ws = atleast_1d(ws)
@@ -1434,6 +1510,39 @@ def cheb2ord(wp, ws, gpass, gstop, analog=False):
The Chebyshev natural frequency (the "3dB frequency") for use with
`cheby2` to give filter results.
+ See Also
+ --------
+ cheby2 : Filter design using order and critical points
+ buttord, cheb1ord, ellipord : Find order and critical points
+ from passband and stopband spec
+ iirfilter : General filter design using order and critical frequencies
+ iirdesign : General filter design using passband and stopband spec
+
+ Examples
+ --------
+ Design a digital bandstop filter which rejects -60 dB from 0.2*(fs/2) to
+ 0.5*(fs/2), while staying within 3 dB below 0.1*(fs/2) or above
+ 0.6*(fs/2). Plot its frequency response, showing the passband and
+ stopband constraints in gray.
+
+ >>> from scipy import signal
+ >>> import matplotlib.pyplot as plt
+
+ >>> N, Wn = signal.cheb2ord([0.1, 0.6], [0.2, 0.5], 3, 60)
+ >>> b, a = signal.cheby2(N, 60, Wn, 'stop')
+ >>> w, h = signal.freqz(b, a)
+ >>> plt.plot(w/pi, 20 * np.log10(abs(h)))
+ >>> plt.xscale('log')
+ >>> plt.title('Chebyshev II bandstop filter fit to constraints')
+ >>> plt.xlabel('Normalized frequency')
+ >>> plt.ylabel('Amplitude [dB]')
+ >>> plt.grid(which='both', axis='both')
+ >>> plt.fill([.01, .1, .1, .01], [-3, -3, -99, -99], '0.9', lw=0) # stop
+ >>> plt.fill([.2, .2, .5, .5], [ 9, -60, -60, 9], '0.9', lw=0) # pass
+ >>> plt.fill([.6, .6, 2, 2], [-99, -3, -3, -99], '0.9', lw=0) # stop
+ >>> plt.axis([0.06, 1, -80, 3])
+ >>> plt.show()
+
"""
wp = atleast_1d(wp)
ws = atleast_1d(ws)
@@ -1548,6 +1657,37 @@ def ellipord(wp, ws, gpass, gstop, analog=False):
The Chebyshev natural frequency (the "3dB frequency") for use with
`ellip` to give filter results.
+ See Also
+ --------
+ ellip : Filter design using order and critical points
+ buttord, cheb1ord, cheb2ord : Find order and critical points
+ from passband and stopband spec
+ iirfilter : General filter design using order and critical frequencies
+ iirdesign : General filter design using passband and stopband spec
+
+ Examples
+ --------
+ Design an analog highpass filter such that the passband is within 3 dB
+ above 30 rad/s, while rejecting -60 dB at 10 rad/s. Plot its
+ frequency response, showing the passband and stopband constraints in gray.
+
+ >>> from scipy import signal
+ >>> import matplotlib.pyplot as plt
+
+ >>> N, Wn = signal.ellipord(30, 10, 3, 60, True)
+ >>> b, a = signal.ellip(N, 3, 60, Wn, 'high', True)
+ >>> w, h = signal.freqs(b, a, np.logspace(0, 3, 500))
+ >>> plt.plot(w, 20 * np.log10(abs(h)))
+ >>> plt.xscale('log')
+ >>> plt.title('Elliptical highpass filter fit to constraints')
+ >>> plt.xlabel('Frequency [radians / second]')
+ >>> plt.ylabel('Amplitude [dB]')
+ >>> plt.grid(which='both', axis='both')
+ >>> plt.fill([.1, 10, 10, .1], [1e4, 1e4, -60, -60], '0.9', lw=0) # stop
+ >>> plt.fill([30, 30, 1e9, 1e9], [-99, -3, -3, -99], '0.9', lw=0) # pass
+ >>> plt.axis([1, 300, -80, 3])
+ >>> plt.show()
+
"""
wp = atleast_1d(wp)
ws = atleast_1d(ws)
Something went wrong with that request. Please try again.