Skip to content

Commit 250245d

Browse files
author
Ralf Gommers
committed
DOC: improve clarity of window function docs.
Thanks to Yury Zaytsev for the suggestion.
1 parent 857e191 commit 250245d

File tree

1 file changed

+33
-55
lines changed

1 file changed

+33
-55
lines changed

numpy/lib/function_base.py

+33-55
Original file line numberDiff line numberDiff line change
@@ -2081,8 +2081,8 @@ def blackman(M):
20812081
Returns
20822082
-------
20832083
out : ndarray
2084-
The window, normalized to one (the value one appears only if the
2085-
number of samples is odd).
2084+
The window, with the maximum value normalized to one (the value one
2085+
appears only if the number of samples is odd).
20862086
20872087
See Also
20882088
--------
@@ -2112,8 +2112,7 @@ def blackman(M):
21122112
21132113
Examples
21142114
--------
2115-
>>> from numpy import blackman
2116-
>>> blackman(12)
2115+
>>> np.blackman(12)
21172116
array([ -1.38777878e-17, 3.26064346e-02, 1.59903635e-01,
21182117
4.14397981e-01, 7.36045180e-01, 9.67046769e-01,
21192118
9.67046769e-01, 7.36045180e-01, 4.14397981e-01,
@@ -2122,11 +2121,8 @@ def blackman(M):
21222121
21232122
Plot the window and the frequency response:
21242123
2125-
>>> from numpy import clip, log10, array, blackman, linspace
21262124
>>> from numpy.fft import fft, fftshift
2127-
>>> import matplotlib.pyplot as plt
2128-
2129-
>>> window = blackman(51)
2125+
>>> window = np.blackman(51)
21302126
>>> plt.plot(window)
21312127
[<matplotlib.lines.Line2D object at 0x...>]
21322128
>>> plt.title("Blackman window")
@@ -2140,10 +2136,10 @@ def blackman(M):
21402136
>>> plt.figure()
21412137
<matplotlib.figure.Figure object at 0x...>
21422138
>>> A = fft(window, 2048) / 25.5
2143-
>>> mag = abs(fftshift(A))
2144-
>>> freq = linspace(-0.5,0.5,len(A))
2145-
>>> response = 20*log10(mag)
2146-
>>> response = clip(response,-100,100)
2139+
>>> mag = np.abs(fftshift(A))
2140+
>>> freq = np.linspace(-0.5, 0.5, len(A))
2141+
>>> response = 20 * np.log10(mag)
2142+
>>> response = np.clip(response, -100, 100)
21472143
>>> plt.plot(freq, response)
21482144
[<matplotlib.lines.Line2D object at 0x...>]
21492145
>>> plt.title("Frequency response of Blackman window")
@@ -2182,9 +2178,9 @@ def bartlett(M):
21822178
Returns
21832179
-------
21842180
out : array
2185-
The triangular window, normalized to one (the value one
2186-
appears only if the number of samples is odd), with the first
2187-
and last samples equal to zero.
2181+
The triangular window, with the maximum value normalized to one
2182+
(the value one appears only if the number of samples is odd), with
2183+
the first and last samples equal to zero.
21882184
21892185
See Also
21902186
--------
@@ -2231,11 +2227,8 @@ def bartlett(M):
22312227
22322228
Plot the window and its frequency response (requires SciPy and matplotlib):
22332229
2234-
>>> from numpy import clip, log10, array, bartlett, linspace
22352230
>>> from numpy.fft import fft, fftshift
2236-
>>> import matplotlib.pyplot as plt
2237-
2238-
>>> window = bartlett(51)
2231+
>>> window = np.bartlett(51)
22392232
>>> plt.plot(window)
22402233
[<matplotlib.lines.Line2D object at 0x...>]
22412234
>>> plt.title("Bartlett window")
@@ -2249,10 +2242,10 @@ def bartlett(M):
22492242
>>> plt.figure()
22502243
<matplotlib.figure.Figure object at 0x...>
22512244
>>> A = fft(window, 2048) / 25.5
2252-
>>> mag = abs(fftshift(A))
2253-
>>> freq = linspace(-0.5,0.5,len(A))
2254-
>>> response = 20*log10(mag)
2255-
>>> response = clip(response,-100,100)
2245+
>>> mag = np.abs(fftshift(A))
2246+
>>> freq = np.linspace(-0.5, 0.5, len(A))
2247+
>>> response = 20 * np.log10(mag)
2248+
>>> response = np.clip(response, -100, 100)
22562249
>>> plt.plot(freq, response)
22572250
[<matplotlib.lines.Line2D object at 0x...>]
22582251
>>> plt.title("Frequency response of Bartlett window")
@@ -2288,8 +2281,8 @@ def hanning(M):
22882281
Returns
22892282
-------
22902283
out : ndarray, shape(M,)
2291-
The window, normalized to one (the value one
2292-
appears only if `M` is odd).
2284+
The window, with the maximum value normalized to one (the value
2285+
one appears only if `M` is odd).
22932286
22942287
See Also
22952288
--------
@@ -2325,17 +2318,14 @@ def hanning(M):
23252318
23262319
Examples
23272320
--------
2328-
>>> from numpy import hanning
2329-
>>> hanning(12)
2321+
>>> np.hanning(12)
23302322
array([ 0. , 0.07937323, 0.29229249, 0.57115742, 0.82743037,
23312323
0.97974649, 0.97974649, 0.82743037, 0.57115742, 0.29229249,
23322324
0.07937323, 0. ])
23332325
23342326
Plot the window and its frequency response:
23352327
23362328
>>> from numpy.fft import fft, fftshift
2337-
>>> import matplotlib.pyplot as plt
2338-
23392329
>>> window = np.hanning(51)
23402330
>>> plt.plot(window)
23412331
[<matplotlib.lines.Line2D object at 0x...>]
@@ -2350,10 +2340,10 @@ def hanning(M):
23502340
>>> plt.figure()
23512341
<matplotlib.figure.Figure object at 0x...>
23522342
>>> A = fft(window, 2048) / 25.5
2353-
>>> mag = abs(fftshift(A))
2354-
>>> freq = np.linspace(-0.5,0.5,len(A))
2355-
>>> response = 20*np.log10(mag)
2356-
>>> response = np.clip(response,-100,100)
2343+
>>> mag = np.abs(fftshift(A))
2344+
>>> freq = np.linspace(-0.5, 0.5, len(A))
2345+
>>> response = 20 * np.log10(mag)
2346+
>>> response = np.clip(response, -100, 100)
23572347
>>> plt.plot(freq, response)
23582348
[<matplotlib.lines.Line2D object at 0x...>]
23592349
>>> plt.title("Frequency response of the Hann window")
@@ -2367,10 +2357,6 @@ def hanning(M):
23672357
>>> plt.show()
23682358
23692359
"""
2370-
# XXX: this docstring is inconsistent with other filter windows, e.g.
2371-
# Blackman and Bartlett - they should all follow the same convention for
2372-
# clarity. Either use np. for all numpy members (as above), or import all
2373-
# numpy members (as in Blackman and Bartlett examples)
23742360
if M < 1:
23752361
return array([])
23762362
if M == 1:
@@ -2393,8 +2379,8 @@ def hamming(M):
23932379
Returns
23942380
-------
23952381
out : ndarray
2396-
The window, normalized to one (the value one
2397-
appears only if the number of samples is odd).
2382+
The window, with the maximum value normalized to one (the value
2383+
one appears only if the number of samples is odd).
23982384
23992385
See Also
24002386
--------
@@ -2437,8 +2423,6 @@ def hamming(M):
24372423
Plot the window and the frequency response:
24382424
24392425
>>> from numpy.fft import fft, fftshift
2440-
>>> import matplotlib.pyplot as plt
2441-
24422426
>>> window = np.hamming(51)
24432427
>>> plt.plot(window)
24442428
[<matplotlib.lines.Line2D object at 0x...>]
@@ -2638,8 +2622,8 @@ def kaiser(M,beta):
26382622
Returns
26392623
-------
26402624
out : array
2641-
The window, normalized to one (the value one
2642-
appears only if the number of samples is odd).
2625+
The window, with the maximum value normalized to one (the value
2626+
one appears only if the number of samples is odd).
26432627
26442628
See Also
26452629
--------
@@ -2682,7 +2666,6 @@ def kaiser(M,beta):
26822666
large enough to sample the increasingly narrow spike, otherwise nans will
26832667
get returned.
26842668
2685-
26862669
Most references to the Kaiser window come from the signal processing
26872670
literature, where it is used as one of many windowing functions for
26882671
smoothing values. It is also known as an apodization (which means
@@ -2701,8 +2684,7 @@ def kaiser(M,beta):
27012684
27022685
Examples
27032686
--------
2704-
>>> from numpy import kaiser
2705-
>>> kaiser(12, 14)
2687+
>>> np.kaiser(12, 14)
27062688
array([ 7.72686684e-06, 3.46009194e-03, 4.65200189e-02,
27072689
2.29737120e-01, 5.99885316e-01, 9.45674898e-01,
27082690
9.45674898e-01, 5.99885316e-01, 2.29737120e-01,
@@ -2711,11 +2693,8 @@ def kaiser(M,beta):
27112693
27122694
Plot the window and the frequency response:
27132695
2714-
>>> from numpy import clip, log10, array, kaiser, linspace
27152696
>>> from numpy.fft import fft, fftshift
2716-
>>> import matplotlib.pyplot as plt
2717-
2718-
>>> window = kaiser(51, 14)
2697+
>>> window = np.kaiser(51, 14)
27192698
>>> plt.plot(window)
27202699
[<matplotlib.lines.Line2D object at 0x...>]
27212700
>>> plt.title("Kaiser window")
@@ -2729,10 +2708,10 @@ def kaiser(M,beta):
27292708
>>> plt.figure()
27302709
<matplotlib.figure.Figure object at 0x...>
27312710
>>> A = fft(window, 2048) / 25.5
2732-
>>> mag = abs(fftshift(A))
2733-
>>> freq = linspace(-0.5,0.5,len(A))
2734-
>>> response = 20*log10(mag)
2735-
>>> response = clip(response,-100,100)
2711+
>>> mag = np.abs(fftshift(A))
2712+
>>> freq = np.linspace(-0.5, 0.5, len(A))
2713+
>>> response = 20 * np.log10(mag)
2714+
>>> response = np.clip(response, -100, 100)
27362715
>>> plt.plot(freq, response)
27372716
[<matplotlib.lines.Line2D object at 0x...>]
27382717
>>> plt.title("Frequency response of Kaiser window")
@@ -2809,7 +2788,6 @@ def sinc(x):
28092788
-5.84680802e-02, -8.90384387e-02, -8.40918587e-02,
28102789
-4.92362781e-02, -3.89804309e-17])
28112790
2812-
>>> import matplotlib.pyplot as plt
28132791
>>> plt.plot(x, np.sinc(x))
28142792
[<matplotlib.lines.Line2D object at 0x...>]
28152793
>>> plt.title("Sinc Function")

0 commit comments

Comments
 (0)