Skip to content

Commit 1599ccf

Browse files
committed
Add Nuttall window (3-term and 4-term)
1 parent 39c1132 commit 1599ccf

7 files changed

Lines changed: 348 additions & 8 deletions

File tree

docs/src/windows.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gaussian
1313
bartlett_hann
1414
blackman
1515
blackmanharris
16+
nuttall
1617
kaiser
1718
flattop
1819
dpss

gen/gen_winplots.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ open(joinpath(@__DIR__, "..", "src", "winplots.jl"), "w") do io
2525
(bartlett_hann, ()),
2626
(blackman, ()),
2727
(blackmanharris, ()),
28+
(nuttall, ()),
2829
(kaiser, (3)),
2930
(flattop, ()),
3031
(dpss, (2, 1)),

src/windows.jl

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export rect,
1717
bartlett_hann,
1818
blackman,
1919
blackmanharris,
20+
nuttall,
2021
kaiser,
2122
flattop,
2223
dpss,
@@ -514,6 +515,57 @@ function blackmanharris(n::Integer; term::Integer=4, padding::Integer=0, zeropha
514515
end
515516
end
516517

518+
"""
519+
$nuttall_winplot
520+
521+
nuttall(n::Integer; term::Integer=4, padding::Integer=0, zerophase::Bool=false)
522+
nuttall(dims; term::Integer=4, padding=0, zerophase=false)
523+
524+
Nuttall window of length `n` with `padding` zeros. These windows can be seen as
525+
the improved version of the Blackman-Harris windows with regard to maximum
526+
sidelobe level. The number of terms can be selected with `term` ∈ [3,4]. For
527+
`term = 3`, the maximum sidelobe level is about -71.48 dB, while for `term = 4`
528+
(the default), it improves to -98.17 dB.
529+
530+
The 3-term window `w3(x)` and the 4-term window `w4(x)` are defined by sampling
531+
the following continuous functions in the range `[-0.5, 0.5]`:
532+
533+
w3(x) = 0.4243801 + 0.4973406*cos(2π*x) + 0.0782793*cos(4π*x)
534+
535+
w4(x) = 0.3635819 + 0.4891775*cos(2π*x) + 0.1365995*cos(4π*x) + 0.0106411*cos(6π*x)
536+
537+
For more details see [Nuttall, A. H. (1981). Some windows with very good
538+
sidelobe behavior. IEEE Transactions on Acoustics, Speech, Signal Processing,
539+
29, 84-91](https://ieeexplore.ieee.org/document/1163506)
540+
541+
The `nuttall` windows do not generally satisfy the Constant Overlap-Add
542+
(COLA) property. Nevertheless, when using `zerophase = true` and implementing the
543+
following boundary conditions they approximately do:
544+
- For the 3-term window the overlap should be 66% and the window length should
545+
be a multiple of 3.
546+
- For the 4-term window the overlap should be 75% and the window length should
547+
be a multiple of 4.
548+
549+
$(twoD_docs())
550+
551+
$zerophase_docs
552+
"""
553+
function nuttall(n::Integer; term::Integer=4, padding::Integer=0, zerophase::Bool=false)
554+
if term == 4
555+
a0, a1, a2, a3 = 0.3635819, 0.4891775, 0.1365995, 0.0106411
556+
makewindow(n, padding, zerophase) do x
557+
muladd(a1, cospi(2x), muladd(a2, cospi(4x), muladd(a3, cospi(6x), a0)))
558+
end
559+
elseif term == 3
560+
a0, a1, a2 = 0.4243801, 0.4973406, 0.0782793
561+
makewindow(n, padding, zerophase) do x
562+
muladd(a1, cospi(2x), muladd(a2, cospi(4x), a0))
563+
end
564+
else
565+
throw(ArgumentError("`term` must be either 3 or 4"))
566+
end
567+
end
568+
517569
"""
518570
$kaiser_winplot
519571
@@ -745,7 +797,7 @@ function matrix_window(func::F, dims::Tuple{Integer,Integer}, arg::Union{RealOr2
745797
end
746798

747799
for func in (:rect, :hanning, :hamming, :cosine, :lanczos,
748-
:triang, :bartlett, :bartlett_hann, :blackman, :blackmanharris, :flattop)
800+
:triang, :bartlett, :bartlett_hann, :blackman, :blackmanharris, :nuttall, :flattop)
749801
@eval function $func(dims::Tuple{Integer,Integer}; padding::IntegerOr2=0, zerophase::BoolOr2=false)
750802
return matrix_window($func, dims; padding, zerophase)
751803
end

src/winplots.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,26 @@ const blackmanharris_winplot = padplot("""
243243
└──────────────────────────────────────────────────────────────────────┘
244244
1 69 """)
245245

246+
const nuttall_winplot = padplot("""
247+
┌──────────────────────────────────────────────────────────────────────┐
248+
1 │ ▄▀▀▀▀▀▀▄ │
249+
│ ▗▀ ▀▖ │
250+
│ ▞▘ ▝▚ │
251+
│ ▞ ▚ │
252+
│ ▗▀ ▀▖ │
253+
│ ▗▘ ▝▖ │
254+
│ ▗▘ ▝▖ │
255+
│ ▗▘ ▝▖ │
256+
│ ▄▘ ▝▄ │
257+
│ ▞ ▚ │
258+
│ ▗▞ ▚▖ │
259+
│ ▗▄▘ ▝▄▖ │
260+
│ ▗▞▘ ▝▚▖ │
261+
│ ▄▞▘ ▝▚▄ │
262+
0 │▄▄▄▄▄▄▄▄▄▞▀▀ ▀▀▚▄▄▄▄▄▄▄▄▄│
263+
└──────────────────────────────────────────────────────────────────────┘
264+
1 69 """)
265+
246266
const kaiser_winplot = padplot("""
247267
┌──────────────────────────────────────────────────────────────────────┐
248268
1 │ ▗▄▀▀▀▀▀▀▄▖ │

test/data/nuttall_3term_128.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
5.3187999999999569e-03
2+
5.5444471580414377e-03
3+
6.2236451361461645e-03
4+
7.3631304475890039e-03
5+
8.9740209684933767e-03
6+
1.1071652688761225e-02
7+
1.3675353590733871e-02
8+
1.6808157053868913e-02
9+
2.0496457827744233e-02
10+
2.4769614229369765e-02
11+
2.9659500797987723e-02
12+
3.5200016175491816e-02
13+
4.1426551467941629e-02
14+
4.8375424778501895e-02
15+
5.6083287980124963e-02
16+
6.4586512113607192e-02
17+
7.3920558050068169e-02
18+
8.4119339243836494e-02
19+
9.5214583520251528e-02
20+
1.0723520089173569e-01
21+
1.2020666437409223e-01
22+
1.3415041068345004e-01
23+
1.4908326753342008e-01
24+
1.6501691402334262e-01
25+
1.8195738031414135e-01
26+
1.9990459243107689e-01
27+
2.1885196761603359e-01
28+
2.3878606517988893e-01
29+
2.5968629728258191e-01
30+
2.8152470349976122e-01
31+
3.0426579242590179e-01
32+
3.2786645292042654e-01
33+
3.5227593693194137e-01
34+
3.7743591514271324e-01
35+
4.0328060596776888e-01
36+
4.2973697772737302e-01
37+
4.5672502309514557e-01
38+
4.8415810421373040e-01
39+
5.1194336617266445e-01
40+
5.3998221586577577e-01
41+
5.6817086259468896e-01
42+
5.9640091616724489e-01
43+
6.2456003766091472e-01
44+
6.5253263748731827e-01
45+
6.8020061490999850e-01
46+
7.0744413273846196e-01
47+
7.3414242055140799e-01
48+
7.6017459949473443e-01
49+
7.8542052145838970e-01
50+
8.0976161526289148e-01
51+
8.3308173238310312e-01
52+
8.5526798470477450e-01
53+
8.7621156684878965e-01
54+
8.9580855570874474e-01
55+
9.1396068002841824e-01
56+
9.3057605309522373e-01
57+
9.4556986194151116e-01
58+
9.5886500682464715e-01
59+
9.7039268519553912e-01
60+
9.8009291485951189e-01
61+
9.8791499157848395e-01
62+
9.9381787695400114e-01
63+
9.9777051306123121e-01
64+
9.9975206096844371e-01
65+
9.9975206096844371e-01
66+
9.9777051306123121e-01
67+
9.9381787695400114e-01
68+
9.8791499157848395e-01
69+
9.8009291485951189e-01
70+
9.7039268519553912e-01
71+
9.5886500682464715e-01
72+
9.4556986194151116e-01
73+
9.3057605309522373e-01
74+
9.1396068002841824e-01
75+
8.9580855570874474e-01
76+
8.7621156684878965e-01
77+
8.5526798470477450e-01
78+
8.3308173238310312e-01
79+
8.0976161526289148e-01
80+
7.8542052145838970e-01
81+
7.6017459949473443e-01
82+
7.3414242055140799e-01
83+
7.0744413273846196e-01
84+
6.8020061490999850e-01
85+
6.5253263748731827e-01
86+
6.2456003766091472e-01
87+
5.9640091616724489e-01
88+
5.6817086259468896e-01
89+
5.3998221586577577e-01
90+
5.1194336617266445e-01
91+
4.8415810421373040e-01
92+
4.5672502309514557e-01
93+
4.2973697772737302e-01
94+
4.0328060596776888e-01
95+
3.7743591514271324e-01
96+
3.5227593693194137e-01
97+
3.2786645292042654e-01
98+
3.0426579242590179e-01
99+
2.8152470349976122e-01
100+
2.5968629728258191e-01
101+
2.3878606517988893e-01
102+
2.1885196761603359e-01
103+
1.9990459243107689e-01
104+
1.8195738031414135e-01
105+
1.6501691402334262e-01
106+
1.4908326753342008e-01
107+
1.3415041068345004e-01
108+
1.2020666437409223e-01
109+
1.0723520089173569e-01
110+
9.5214583520251528e-02
111+
8.4119339243836494e-02
112+
7.3920558050068169e-02
113+
6.4586512113607192e-02
114+
5.6083287980124963e-02
115+
4.8375424778501895e-02
116+
4.1426551467941629e-02
117+
3.5200016175491816e-02
118+
2.9659500797987723e-02
119+
2.4769614229369765e-02
120+
2.0496457827744233e-02
121+
1.6808157053868913e-02
122+
1.3675353590733871e-02
123+
1.1071652688761225e-02
124+
8.9740209684933767e-03
125+
7.3631304475890039e-03
126+
6.2236451361461645e-03
127+
5.5444471580414377e-03
128+
5.3187999999999569e-03

test/data/nuttall_4term_128.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
3.6280000000003809e-04
2+
4.1018634383144757e-04
3+
5.5484449285105389e-04
4+
8.0426800626856761e-04
5+
1.1709328778546652e-03
6+
1.6722754552345800e-03
7+
2.3306572561868156e-03
8+
3.1733125865082137e-03
9+
4.2322739392433679e-03
10+
5.5442694056689933e-03
11+
7.1505857839516216e-03
12+
9.0968907561675728e-03
13+
1.1433007436739940e-02
14+
1.4212634787223953e-02
15+
1.7493007848818160e-02
16+
2.1334492463057353e-02
17+
2.5800110123822734e-02
18+
3.0954989814131851e-02
19+
3.6865745106539644e-02
20+
4.3599776417604971e-02
21+
5.1224500070387410e-02
22+
5.9806507695122649e-02
23+
6.9410661443912669e-02
24+
8.0099132464262826e-02
25+
9.1930392020463408e-02
26+
1.0495816652214864e-01
27+
1.1923036946715482e-01
28+
1.3478802488374997e-01
29+
1.5166419822068983e-01
30+
1.6988295174125595e-01
31+
1.8945834229300781e-01
32+
2.1039347981751877e-01
33+
2.3267966510935464e-01
34+
2.5629562511351239e-01
35+
2.8120686345553253e-01
36+
3.0736514292656342e-01
37+
3.3470811530290362e-01
38+
3.6315911218025493e-01
39+
3.9262710846930926e-01
40+
4.2300686786122638e-01
41+
4.5417927696602312e-01
42+
4.8601187199730744e-01
43+
5.1835955887219631e-01
44+
5.5106552446939194e-01
45+
5.8396233359861316e-01
46+
6.1687320304066906e-01
47+
6.4961344088054018e-01
48+
6.8199203633693273e-01
49+
7.1381338245072834e-01
50+
7.4487911138889118e-01
51+
7.7499001980323245e-01
52+
8.0394805970380678e-01
53+
8.3155836870732747e-01
54+
8.5763131233791445e-01
55+
8.8198451031902925e-01
56+
9.0444481852164826e-01
57+
9.2485023843595615e-01
58+
9.4305172671426996e-01
59+
9.5891487848466317e-01
60+
9.7232145974182094e-01
61+
9.8317076615918575e-01
62+
9.9138078810118502e-01
63+
9.9688916440533837e-01
64+
9.9965391060328990e-01
65+
9.9965391060328990e-01
66+
9.9688916440533837e-01
67+
9.9138078810118502e-01
68+
9.8317076615918608e-01
69+
9.7232145974182094e-01
70+
9.5891487848466306e-01
71+
9.4305172671427029e-01
72+
9.2485023843595615e-01
73+
9.0444481852164826e-01
74+
8.8198451031902958e-01
75+
8.5763131233791468e-01
76+
8.3155836870732724e-01
77+
8.0394805970380712e-01
78+
7.7499001980323245e-01
79+
7.4487911138889118e-01
80+
7.1381338245072845e-01
81+
6.8199203633693251e-01
82+
6.4961344088054063e-01
83+
6.1687320304066906e-01
84+
5.8396233359861327e-01
85+
5.5106552446939205e-01
86+
5.1835955887219620e-01
87+
4.8601187199730794e-01
88+
4.5417927696602334e-01
89+
4.2300686786122671e-01
90+
3.9262710846930954e-01
91+
3.6315911218025509e-01
92+
3.3470811530290362e-01
93+
3.0736514292656392e-01
94+
2.8120686345553286e-01
95+
2.5629562511351217e-01
96+
2.3267966510935484e-01
97+
2.1039347981751902e-01
98+
1.8945834229300801e-01
99+
1.6988295174125598e-01
100+
1.5166419822068986e-01
101+
1.3478802488374997e-01
102+
1.1923036946715468e-01
103+
1.0495816652214876e-01
104+
9.1930392020463533e-02
105+
8.0099132464262757e-02
106+
6.9410661443912711e-02
107+
5.9806507695122635e-02
108+
5.1224500070387376e-02
109+
4.3599776417605096e-02
110+
3.6865745106539720e-02
111+
3.0954989814131903e-02
112+
2.5800110123822800e-02
113+
2.1334492463057426e-02
114+
1.7493007848818187e-02
115+
1.4212634787224010e-02
116+
1.1433007436739978e-02
117+
9.0968907561675572e-03
118+
7.1505857839516901e-03
119+
5.5442694056689456e-03
120+
4.2322739392433688e-03
121+
3.1733125865082918e-03
122+
2.3306572561868260e-03
123+
1.6722754552345367e-03
124+
1.1709328778546774e-03
125+
8.0426800626858148e-04
126+
5.5484449285107991e-04
127+
4.1018634383147012e-04
128+
3.6280000000003809e-04

0 commit comments

Comments
 (0)