Skip to content

Commit 7e0f59f

Browse files
committed
DOC: Examples of fs usage
1 parent 94a0157 commit 7e0f59f

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

scipy/signal/filter_design.py

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,8 @@ def butter(N, Wn, btype='low', analog=False, output='ba', fs=None):
24822482
24832483
Examples
24842484
--------
2485-
Plot the filter's frequency response, showing the critical points:
2485+
Design an analog filter and plot its frequency response, showing the
2486+
critical points:
24862487
24872488
>>> from scipy import signal
24882489
>>> import matplotlib.pyplot as plt
@@ -2498,6 +2499,27 @@ def butter(N, Wn, btype='low', analog=False, output='ba', fs=None):
24982499
>>> plt.axvline(100, color='green') # cutoff frequency
24992500
>>> plt.show()
25002501
2502+
Generate a signal made up of 10 Hz and 20 Hz, sampled at 1 kHz
2503+
2504+
>>> t = np.linspace(0, 1, 1000) # 1 second
2505+
>>> sig = np.sin(2*pi*10*t) + np.sin(2*pi*20*t)
2506+
>>> fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
2507+
>>> ax1.plot(t, sig)
2508+
>>> ax1.set_title('10 Hz and 20 Hz sinusoids')
2509+
>>> ax1.axis([0, 1, -2, 2])
2510+
2511+
Design a digital high-pass filter at 15 Hz to remove the 10 Hz tone, and
2512+
apply it to the signal. (It's recommended to use second-order sections
2513+
format when filtering, to avoid numerical error with transfer function
2514+
(``ba``) format):
2515+
2516+
>>> sos = signal.butter(10, 15, 'hp', fs=1000, output='sos')
2517+
>>> filtered = sosfilt(sos, sig) # Use SOS for high-order filters
2518+
>>> ax2.plot(t, filtered)
2519+
>>> ax2.set_title('After 15 Hz high-pass filter')
2520+
>>> ax2.axis([0, 1, -2, 2])
2521+
>>> ax2.set_xlabel('Time [seconds]')
2522+
>>> plt.show()
25012523
"""
25022524
return iirfilter(N, Wn, btype=btype, analog=analog,
25032525
output=output, ftype='butter', fs=fs)
@@ -2573,7 +2595,8 @@ def cheby1(N, rp, Wn, btype='low', analog=False, output='ba', fs=None):
25732595
25742596
Examples
25752597
--------
2576-
Plot the filter's frequency response, showing the critical points:
2598+
Design an analog filter and plot its frequency response, showing the
2599+
critical points:
25772600
25782601
>>> from scipy import signal
25792602
>>> import matplotlib.pyplot as plt
@@ -2590,6 +2613,27 @@ def cheby1(N, rp, Wn, btype='low', analog=False, output='ba', fs=None):
25902613
>>> plt.axhline(-5, color='green') # rp
25912614
>>> plt.show()
25922615
2616+
Generate a signal made up of 10 Hz and 20 Hz, sampled at 1 kHz
2617+
2618+
>>> t = np.linspace(0, 1, 1000) # 1 second
2619+
>>> sig = np.sin(2*pi*10*t) + np.sin(2*pi*20*t)
2620+
>>> fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
2621+
>>> ax1.plot(t, sig)
2622+
>>> ax1.set_title('10 Hz and 20 Hz sinusoids')
2623+
>>> ax1.axis([0, 1, -2, 2])
2624+
2625+
Design a digital high-pass filter at 15 Hz to remove the 10 Hz tone, and
2626+
apply it to the signal. (It's recommended to use second-order sections
2627+
format when filtering, to avoid numerical error with transfer function
2628+
(``ba``) format):
2629+
2630+
>>> sos = signal.cheby1(10, 1, 15, 'hp', fs=1000, output='sos')
2631+
>>> filtered = sosfilt(sos, sig) # Use SOS for high-order filters
2632+
>>> ax2.plot(t, filtered)
2633+
>>> ax2.set_title('After 15 Hz high-pass filter')
2634+
>>> ax2.axis([0, 1, -2, 2])
2635+
>>> ax2.set_xlabel('Time [seconds]')
2636+
>>> plt.show()
25932637
"""
25942638
return iirfilter(N, Wn, rp=rp, btype=btype, analog=analog,
25952639
output=output, ftype='cheby1', fs=fs)
@@ -2660,7 +2704,8 @@ def cheby2(N, rs, Wn, btype='low', analog=False, output='ba', fs=None):
26602704
26612705
Examples
26622706
--------
2663-
Plot the filter's frequency response, showing the critical points:
2707+
Design an analog filter and plot its frequency response, showing the
2708+
critical points:
26642709
26652710
>>> from scipy import signal
26662711
>>> import matplotlib.pyplot as plt
@@ -2677,6 +2722,27 @@ def cheby2(N, rs, Wn, btype='low', analog=False, output='ba', fs=None):
26772722
>>> plt.axhline(-40, color='green') # rs
26782723
>>> plt.show()
26792724
2725+
Generate a signal made up of 10 Hz and 20 Hz, sampled at 1 kHz
2726+
2727+
>>> t = np.linspace(0, 1, 1000) # 1 second
2728+
>>> sig = np.sin(2*pi*10*t) + np.sin(2*pi*20*t)
2729+
>>> fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
2730+
>>> ax1.plot(t, sig)
2731+
>>> ax1.set_title('10 Hz and 20 Hz sinusoids')
2732+
>>> ax1.axis([0, 1, -2, 2])
2733+
2734+
Design a digital high-pass filter at 17 Hz to remove the 10 Hz tone, and
2735+
apply it to the signal. (It's recommended to use second-order sections
2736+
format when filtering, to avoid numerical error with transfer function
2737+
(``ba``) format):
2738+
2739+
>>> sos = signal.cheby2(12, 20, 17, 'hp', fs=1000, output='sos')
2740+
>>> filtered = sosfilt(sos, sig) # Use SOS for high-order filters
2741+
>>> ax2.plot(t, filtered)
2742+
>>> ax2.set_title('After 15 Hz high-pass filter')
2743+
>>> ax2.axis([0, 1, -2, 2])
2744+
>>> ax2.set_xlabel('Time [seconds]')
2745+
>>> plt.show()
26802746
"""
26812747
return iirfilter(N, Wn, rs=rs, btype=btype, analog=analog,
26822748
output=output, ftype='cheby2', fs=fs)
@@ -2758,7 +2824,8 @@ def ellip(N, rp, rs, Wn, btype='low', analog=False, output='ba', fs=None):
27582824
27592825
Examples
27602826
--------
2761-
Plot the filter's frequency response, showing the critical points:
2827+
Design an analog filter and plot its frequency response, showing the
2828+
critical points:
27622829
27632830
>>> from scipy import signal
27642831
>>> import matplotlib.pyplot as plt
@@ -2776,6 +2843,27 @@ def ellip(N, rp, rs, Wn, btype='low', analog=False, output='ba', fs=None):
27762843
>>> plt.axhline(-5, color='green') # rp
27772844
>>> plt.show()
27782845
2846+
Generate a signal made up of 10 Hz and 20 Hz, sampled at 1 kHz
2847+
2848+
>>> t = np.linspace(0, 1, 1000) # 1 second
2849+
>>> sig = np.sin(2*pi*10*t) + np.sin(2*pi*20*t)
2850+
>>> fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
2851+
>>> ax1.plot(t, sig)
2852+
>>> ax1.set_title('10 Hz and 20 Hz sinusoids')
2853+
>>> ax1.axis([0, 1, -2, 2])
2854+
2855+
Design a digital high-pass filter at 17 Hz to remove the 10 Hz tone, and
2856+
apply it to the signal. (It's recommended to use second-order sections
2857+
format when filtering, to avoid numerical error with transfer function
2858+
(``ba``) format):
2859+
2860+
>>> sos = signal.ellip(8, 1, 100, 17, 'hp', fs=1000, output='sos')
2861+
>>> filtered = sosfilt(sos, sig) # Use SOS for high-order filters
2862+
>>> ax2.plot(t, filtered)
2863+
>>> ax2.set_title('After 15 Hz high-pass filter')
2864+
>>> ax2.axis([0, 1, -2, 2])
2865+
>>> ax2.set_xlabel('Time [seconds]')
2866+
>>> plt.show()
27792867
"""
27802868
return iirfilter(N, Wn, rs=rs, rp=rp, btype=btype, analog=analog,
27812869
output=output, ftype='elliptic', fs=fs)

0 commit comments

Comments
 (0)