Library / Signal processing and digital filters / DSP-11
Signal processing and digital filters
Hann window sample
Coefficient n of the symmetric N-point Hann (raised-cosine) window.
- Ref
- DSP-11
- Rev
- v1
- Field
- Signal processing and digital filters
- Result
- w[n]
The Hann window w[n] = 0.5 − 0.5 cos(2πn/(N − 1)) is a raised cosine that falls to zero at both ends, which suppresses the edge discontinuity and gives sidelobes that decay quickly. The symmetric form used here is for filter design; for periodic spectral analysis, use N instead of N − 1.
Coefficient n of the symmetric N-point Hann (raised-cosine) window. Both end points are zero. Use it as a symmetric FIR taper; for periodic spectral analysis replace N − 1 by N. The page needs integers with 0 ≤ n ≤ N − 1.
Calculator
- Position along the window, n/(N − 1)0.25
- Value with the periodic convention (N in the denominator)0.4132
- Value at the mirror sample, w[N − 1 − n]0.5
What drives the result
Each variable is moved across its typical range while the others stay at the values above. The longest bar is the key driver.
- Sample 2 of a 9-point Hann window is 0.5, 25 % of the way along.
- The window is symmetric, so sample 6 has the same weight, and the end samples are exactly zero.
Chart data as tables
Ranked variables
| Variable | Typical range | Lowest result | Highest result | Swing () | Local step | Change in result |
|---|---|---|---|---|---|---|
| n Sample index | 0 to 8 | 0 | 1 | 1 | +1 | +70.7 % |
| N Window length | 9 to 1,024 samples | 3.772e-5 | 0.5 | 0.5 | +1 samples | −17.4 % |
Sweep of Sample index
| Sample index | Window coefficient |
|---|---|
| 0 | 0 |
| 1 | 0.1464 |
| 2 | 0.5 |
| 3 | 0.8536 |
| 4 | 1 |
| 5 | 0.8536 |
| 6 | 0.5 |
| 7 | 0.1464 |
| 8 | 0 |
Sweep one variable
Variables and how each one contributes
Window coefficient
What the equation gives you. Everything else feeds it.
Window length
The window length, in samples. A longer window has more samples across the same shape, so a given n sits nearer the start. Raising it by 10 % (to 9.9) moves the result by −17.4 %, from 0.5 to 0.4132.
Sample index
The sample index, 0 to N − 1. Moves along the window from the start towards the centre and the other end. Raising it by 10 % (to 2.2) moves the result by +0 %, from 0.5 to 0.5.
Worked example with the values above
- Phase angle: 2πn/(N − 1) = 2π × 2 / 8 = 1.5708 rad.
- Cosine: cos(1.5708) = 6.1232×10−17.
- w = 0.5 − 0.5 × 6.1232×10−17 = 0.5.
Assumptions and limits
- A symmetric N-point window with integer N ≥ 2 and 0 ≤ n ≤ N − 1, so the end points have the same value.
- For periodic spectral analysis, replace N − 1 with N in the denominator.
Common mistakes
- Using the symmetric form for spectral analysis, which assumes a periodic window.
- Using an index outside 0 to N − 1.
- Forgetting that Hamming and Kaiser (with β > 0) end points are not zero.
Statistics and uncertainty
Window coefficients are exact formulas, but sampled windows differ slightly between software packages (symmetric against periodic form), which changes the leakage figures in the fourth decimal place.
Where it is used
- Generating window coefficients for FIR design and spectral estimation.
- Trading main-lobe width against sidelobe level in tone measurements.
Maths you need
- Spectral leakage: energy spreading into neighbouring bins
- Sidelobe level: the height of the largest lobe outside the main lobe
- Symmetric against periodic windows: N − 1 or N in the denominator