Fact-checked by Grok 2 weeks ago

Hann function

The Hann function, also known as the Hanning window or raised cosine window, is a mathematical employed in to taper the of a finite-length signal, thereby minimizing when performing transforms. It is named after the Austrian meteorologist Julius von Hann and is characterized by its smooth, bell-shaped curve that starts and ends at zero, providing effective sidelobe suppression while maintaining reasonable frequency resolution. Mathematically, for a discrete signal of length M, the Hann window is defined as w(n) = 0.5 \left[1 - \cos\left(\frac{2\pi n}{M-1}\right)\right] for n = 0, 1, \dots, M-1, which can also be expressed using a sine-squared or raised cosine form. This window function belongs to the family of cosine-based tapers and is particularly valued for its balance of properties in : it exhibits a mainlobe width of 4 bins (between zero crossings), a first sidelobe level of -32 , and a sidelobe falloff rate of -18 per , making it superior to rectangular windows (-13 sidelobes) but with a wider mainlobe than some alternatives like the Hamming window. In practical applications, the Hann window is widely used in (FFT) computations for audio processing, vibration analysis, and spectrum estimation, where it reduces artifacts from non-periodic signals by smoothly attenuating edge discontinuities. Its equivalent bandwidth is 1.5 bins, and it incurs a coherent of 0.5, which must be accounted for in amplitude measurements. Compared to other windows, such as the Hamming (which offers better distant sidelobe suppression at -42 dB but similar mainlobe width) or the Blackman (with -58 dB sidelobes but broader mainlobe), the Hann window is often preferred for general-purpose reduction due to its simplicity and computational efficiency. It is implemented in standard libraries like and , where it supports both symmetric (for general tapering) and periodic (for FFT periodicity) variants. Historically, its properties were systematically analyzed in foundational work on window functions for applications, highlighting its role in improving the dynamic range and accuracy of .

Definition and Formulation

Continuous Hann Function

The continuous Hann function serves as a foundational raised cosine window in signal processing, providing a smooth tapering envelope for theoretical analysis of continuous-time signals. It is mathematically defined as w_0(x) = \frac{1}{2} \left( 1 + \cos \frac{2\pi x}{L} \right) for |x| \leq L/2, and w_0(x) = 0 otherwise, where L > 0 is the length parameter specifying the total width of the support interval. This formulation arises from the raised cosine shape, which inherently produces a periodic cosine curve adjusted to span exactly one full period over the interval [-L/2, L/2], ensuring the function transitions smoothly from zero at the boundaries to a peak value of 1 at the center x = 0. Graphically, the continuous Hann function forms a symmetric, bell-shaped centered at the origin, with the gradually increasing from 0 at x = \pm L/2 to the maximum at x = 0, and exhibiting even due to the cosine term. This shape emphasizes the central portion of the signal while suppressing edge discontinuities. In relation to the rectangular window, which is uniform at 1 over the same , the continuous Hann function introduces a cosine-based to taper the edges, thereby mitigating effects such as high in frequency-domain representations. The discrete Hann window represents a sampled version of this continuous form for practical digital implementations.

Discrete Hann Window

The discrete Hann window is a finite sequence derived by uniformly sampling the continuous Hann function over an interval of length L with N+1 points, which provides even symmetry and exact zeros at the endpoints. This formulation is widely used in digital signal processing to taper finite-duration signals while minimizing edge discontinuities. The standard symmetric discrete Hann window is defined as w = \frac{1}{2} \left(1 - \cos\left(\frac{2\pi n}{N}\right)\right), \quad 0 \leq n \leq N, where N determines the window length L = N+1. This yields a sequence with w{{grok:render&&&type=render_inline_citation&&&citation_id=0&&&citation_type=wikipedia}} = 0 and w[N] = 0, ensuring the window tapers smoothly to zero at both ends. An alternative indexing convention defines the window over n = 0 to M-1 with M = N+1, using the equivalent form w = \frac{1}{2} \left(1 - \cos\left(\frac{2\pi n}{M-1}\right)\right), which maintains the symmetric properties but adjusts the denominator for the finite range. Normalization options include unity peak value (maximum of 1 at the center) or coherent gain of 0.5, corresponding to the average window value, which is the DC gain in the frequency domain. In practice, the Hann window is computed directly using the cosine expression in programming environments, or equivalently via the \frac{1}{2}(1 - \cos \theta) = \sin^2(\theta/2), yielding w = \sin^2\left(\frac{\pi n}{N}\right), which can offer slight numerical advantages for certain implementations. For example, with N=2 (length 3), the sequence is [0, 1, 0], illustrating the central peak and endpoint zeros. Unlike the continuous Hann function, which is defined over an infinite or semi-infinite domain, the discrete version arises from sampling at points over a closed [0, N], inherently producing exact zeros at n=0 and n=N due to the periodicity of the cosine and the choice of denominator, enhancing for even-length sequences. Common variants include the symmetric form (with endpoint zeros, suitable for ) and the periodic form (designed for via FFT, where the window approximates one full without forcing endpoint zeros). The periodic variant is generated by evaluating the formula over L+1 points and truncating to length L, ensuring better continuity in periodic extensions.

Mathematical Properties

Fourier Transform

The continuous Fourier transform of the normalized Hann function, where the time-domain function is scaled by 1/L to ensure unit integral, is given by W_0(f) = \frac{1}{2} \frac{\sinc(L f)}{1 - L^2 f^2} = \frac{\sin(\pi L f)}{2 \pi L f (1 - L^2 f^2)}, for f \neq \pm 1/L, with appropriate limits at those points. This arises from combining the contributions of the constant and cosine terms in the . To derive this, the cosine in the Hann function w(t) = \frac{1}{2} [1 - \cos(2\pi t / L)] for |t| \leq L/2 is expressed using as \cos(\theta) = \frac{1}{2} [e^{j \theta} + e^{-j \theta}], transforming the integral into the of a rectangular W_R(f) = L \sinc(L f) plus differenced shifted versions at frequencies f \pm 1/L. The resulting sum W(f) = \frac{L}{2} \sinc(L f) - \frac{L}{4} \sinc(L f - 1) - \frac{L}{4} \sinc(L f + 1) simplifies to the closed form after algebraic manipulation using trigonometric identities for the sine arguments and common denominator resolution. In the , the central lobe originates from the average value of 1/2 in the time-domain expression, producing a broad sinc-like shape centered at , while the cosine introduces interference from the shifted components, manifesting as shaped by the three primary terms at and \pm 1/L. This structure enhances frequency resolution compared to unwindowed signals by concentrating energy near zero frequency. The exhibit asymptotic decay proportional to $1/f^3, a significant improvement over the rectangular window's $1/f decay, attributable to the Hann function's —being zero at endpoints with a continuous first but discontinuous second . This rapid reduces distant effectively. The 1/L scaling ensures the transform's , particularly the height of the central lobe, remains independent of the window duration L, facilitating consistent across varying signal lengths; without it, amplitudes would scale linearly with L, amplifying low-frequency components disproportionately for longer windows.

Discrete Transforms

The discrete-time Fourier transform (DTFT) of the Hann window sequence w, defined for the periodic variant as n = 0 to M-1 with w = 0.5 \left(1 - \cos\left(\frac{2\pi n}{M}\right)\right), is given by W(f) = \sum_{n=0}^{M-1} w e^{-j 2\pi f n}, which simplifies to a closed-form involving three shifted sinc functions: W(f) = \frac{1}{2} \sinc\left(f M\right) + \frac{1}{4} \sinc\left((f - 0.5) M\right) e^{j \phi} + \frac{1}{4} \sinc\left((f + 0.5) M\right) e^{-j \phi}, where \sinc(x) = \sin(\pi x)/(\pi x) and \phi = \pi M (f \pm 0.5) accounts for the linear phase shift due to time centering. Due to the even symmetry of the Hann window around its center, W(f) is real and even after removing the linear phase term, ensuring phase linearity. The (DFT) of the length-M Hann sequence samples the DTFT at frequencies f = k/M for integer k = 0, \dots, M-1, introducing periodic due to the finite length but preserving the overall spectral shape. For the periodic definition using denominator M in the cosine argument, the DFT exhibits exact sparsity with only three non-zero bins: at k=0 with value $0.5 M, and at k=1 and k = M-1 with value -0.25 M each (up to the overall scaling by M), arising from the window's construction as a of DFT basis functions at and the adjacent bins; all other bins are exactly zero. This sparsity holds for any M \geq 2 and contrasts with denser spectra from the symmetric definition (e.g., denominator M-1), where energy leaks slightly beyond three bins. The sparse DFT structure of the Hann window enables efficient computations, such as fast in or , where time-domain windowing corresponds to frequency-domain with a three-tap (non-zeros at bins 0, 1, and M-1), reducing complexity from O(M^2) to O(M) per output sample. For example, consider a length-8 Hann window (M=8) with values [0, 0.1464, 0.5, 0.8536, 1, 0.8536, 0.5, 0.1464]; its DFT yields non-zero values of 4 at k=0, -2 at k=1, and -2 at k=7, confirming the sparsity and aiding applications like overlap-add methods in audio processing.

Applications and Characteristics

Signal Processing Uses

In digital signal processing, the is commonly applied to time-domain signals prior to computing the (FFT) to mitigate , which arises when analyzing non-periodic or finite-length data segments. By tapering the signal edges to zero, it reduces the discontinuities that cause energy to spread into adjacent frequency bins, thereby improving the accuracy of frequency content estimation in applications such as spectrum analysis. The Hann window plays a key role in overlap-add (OLA) methods, particularly within the (STFT) and filter banks, where signal segments are processed with 50% overlap between consecutive windows. This overlap, combined with the Hann window's symmetric tapering, satisfies the constant overlap-add (COLA) condition, enabling perfect reconstruction of the original signal upon without distortion or errors. As a tapered weighting function, the is used for time-series data by serving as a in weighted moving averages, which diminishes and Gibbs-like oscillations compared to uniform averaging. This approach weights central data points more heavily while gradually reducing influence toward the edges, making it suitable for preprocessing noisy measurements in fields like or . In audio and , the Hann window facilitates analysis of transient sounds, such as in voice recognition systems where STFT frames are windowed to capture frequencies without excessive leakage. Similarly, in monitoring for mechanical systems, it enhances the detection of resonant modes in data by providing balanced resolution for spectra. For image processing, two-dimensional Hann windows are applied to patches for tasks like or frequency-domain filtering, reducing artifacts in Fourier-based operations and preserving moderate in visual signals. For practical implementation, combining the Hann window with zero-padding—appending zeros to the windowed segment before the FFT—yields a finer bin spacing, aiding for estimation without altering the underlying limited by the original data length. This technique is particularly useful in systems where computational and visual clarity in spectrograms are prioritized.

Spectral Properties and Performance

The Hann window exhibits a coherent of 0.5, meaning the of a coherent component is reduced to half its true value in the (DFT) output. Its equivalent noise bandwidth measures 1.5 s, indicating that power is spread over 1.5 bins, which moderately broadens the effective resolution compared to a rectangular window. The scalloping loss reaches a maximum of 1.42 dB when a signal falls midway between DFT bins, representing the in detected under worst-case bin misalignment. The sidelobe structure of the Hann window's features a highest sidelobe level of -31 relative to the mainlobe peak, providing moderate suppression of from off-bin signals. The sidelobes decay at a rate of 18 per , which helps in reducing distant but may allow noticeable artifacts in scenarios with strong nearby tones. This profile makes the Hann window suitable for applications where moderate leakage is tolerable, such as general-purpose spectral estimation in audio or vibration analysis.
WindowCoherent GainENBW (bins)Scalloping Loss (dB)Highest Sidelobe (dB)Sidelobe Roll-off (dB/octave)
Rectangular1.01.03.92-13-6
Hann0.51.51.42-31-18
Hamming0.541.361.78-43-6
Blackman0.421.730.82-58-18
The table above compares key spectral metrics, highlighting the Hann window's balance: it offers better sidelobe suppression than the rectangular window (which has prominent -13 sidelobes leading to high leakage) but trades off with a narrower mainlobe and lower peak sidelobe than the Hamming window (-43 ). Relative to the Blackman window, the Hann provides a narrower mainlobe at the cost of higher sidelobes (-31 vs. -58 ), resulting in less effective far-out leakage control but improved frequency resolution. The three-lobe structure of the Hann window's spectrum—comprising a central mainlobe flanked by two smaller adjacent lobes—contributes to relatively smooth amplitude flatness in the when used in () , minimizing ripples compared to windows with more oscillatory tails. This configuration enhances the frequency response's uniformity for signals, though the wider mainlobe (about twice that of the rectangular window) slightly degrades performance in filtering tasks. Despite its advantages, the Hann window is not optimal for applications requiring very , such as or , where its -31 can mask weak targets amid strong returns; in these cases, windows like Blackman or with below -50 are preferred.

History and Naming

Origins with Julius von Hann

Julius von Hann (1839–1921), an Austrian and a foundational figure in , introduced a three-term weighted method in his Handbuch der Klimatologie (1883) specifically for analyzing temperature data in meteorological observations. This technique was designed to address irregularities in time series by applying unequal weights to consecutive data points, thereby enhancing the reliability of climatological averages. Hann's approach emerged from his extensive work on global temperature distributions and was particularly suited to handling the limitations of early instrumental records. It was detailed in the first edition (1883) and English translation (1903), and elaborated in the third edition (1908). The original formulation utilized weights of \frac{1}{4}, \frac{1}{2}, and \frac{1}{4} for three consecutive points, creating a simple yet effective that emphasized the central value while tapering the contributions from adjacent points. This weighting is mathematically equivalent to a Hann window of length N=3, providing a rudimentary form of low-pass filtering to suppress high-frequency variations. In , Hann applied it to raw readings along latitudinal parallels to derive smoother zonal means, such as obtaining a global average temperature of approximately 14.4°C after processing land-based data. Hann's smoothing procedure was developed in the context of eliminating periodic fluctuations inherent in geophysical , such as diurnal or seasonal cycles that could distort long-term trends in temperature records. By predating , it represented an analog-era innovation reliant on manual computation, yet it proved instrumental in early climatological research for reducing without overly distorting underlying patterns. This weighting scheme later inspired the formulation of the continuous raised cosine , which extended the tapering concept to analog filtering designs for smoother transitions in signal attenuation during the mid-20th century.

Evolution of Terminology

The term "Hanning window" first appeared in literature during the mid-20th century, notably in the 1958 work by Blackman and Tukey, where it was used to describe the raised cosine window function applied in to mitigate side-lobe effects. Subsequent efforts by organizations such as the (ISO) and the Institute of Electrical and Electronics Engineers (IEEE) have favored the precise term "Hann window" to directly honor its originator, Julius von Hann. For instance, ISO/IEC 14496-3 explicitly defines it as the "Hann window" in the context of audio coding and . Similarly, IEEE Std 1057-2017 employs "Hann window" in specifications for digitizing waveform recorders, emphasizing its continuous form and derivative properties. A key source of terminological confusion has been its distinction from the Hamming window, which shares a similar raised cosine structure but incorporates a different weighting factor (0.54 for the constant term versus 0.5 for Hann) and was named after Richard W. Hamming to reflect its optimized sidelobe suppression. This overlap led to occasional interchanges in early texts, though the functions differ fundamentally in their spectral characteristics, with the Hamming variant exhibiting slower sidelobe decay. The terminology gained widespread adoption in the 1970s alongside the rise of (FFT) algorithms in , where window functions became essential for leakage reduction. A seminal contribution to standardization came from Harris in , who reviewed various windows and advocated for "Hann" as the accurate designation while documenting "Hanning" as a common but imprecise variant in prior literature. In contemporary usage, "Hann window" predominates in academic and mathematical contexts for its etymological fidelity, whereas "Hanning window" persists in some software legacies, such as MATLAB's original hanning function, which has since been marked obsolete in favor of hann to align with standardized naming. This shift reflects broader efforts to unify terminology across disciplines, reducing ambiguity in implementations like , where hanning was deprecated in 2017 for the preferred hann.

References

  1. [1]
    hann — SciPy v1.16.2 Manual
    The Hann window is a taper formed by using a raised cosine or sine-squared with ends that touch zero. Parameters: Mint. Number of points in the output window.1.13.0 · Hann · 1.12.0 · 1.13.1
  2. [2]
    [PDF] On the Use of Windows for Harmonic Analysis
    Jan 1, 1978 · Windows are applied to sampled data to affect the data, smoothing spectral samples, and are used with DFT sampling and windowing.
  3. [3]
    Hanning Window - an overview | ScienceDirect Topics
    The Hanning window is defined as a type of window function that reduces spectral leakage, thereby increasing the dynamic range of signal analysis, particularly ...
  4. [4]
    Window Functions in Spectrum Analyzers | Tektronix
    Mar 20, 2013 · Different window functions help you to optimize for different goals: a more accurate amplitude, a lower noise floor, and so on.<|control11|><|separator|>
  5. [5]
    Hann (Hanning) window - MATLAB - MathWorks
    w = hann(L) returns an L-point symmetric Hann window. example w = hann(L,sflag) returns a Hann window using the window sampling specified by sflag.Missing: definition | Show results with:definition
  6. [6]
    Hanning Function -- from Wolfram MathWorld
    The Hanning function, or Hann function, is an apodization function used to reduce leakage in discrete Fourier transforms. It is named after Julius von Hann.
  7. [7]
    Spectrum Analysis Windows | Spectral Audio Signal Processing
    The generalized Hamming window family is constructed by multiplying a rectangular window by one period of a cosine. The benefit of the cosine tapering is lower ...
  8. [8]
    On the Use of Windows for Harmonic Analysis With the Discrete ...
    Aug 5, 2025 · ArticlePDF Available. On the Use of Windows for Harmonic Analysis With the Discrete Fourier Transform. February 1978; Proceedings of the IEEE ...
  9. [9]
    | Spectral Audio Signal Processing
    - **DTFT Expression for Hann Window**: The Discrete-Time Fourier Transform (DTFT) of the Hann window is given by:
  10. [10]
    Evaluate Window Functions for the Discrete Fourier Transform
    Dec 18, 2018 · Spectrum of the Hanning Window. One commonly used window, the Hann, or Hanning window, is defined by this formula [4]:. w(n)=0.5(1−cos( ...
  11. [11]
    [PDF] Understanding FFT Windows
    Hanning is the most commonly used window function for random signals because it provides good frequency resolution and leakage protection with fair amplitude ...
  12. [12]
    [PDF] MUS421 Lecture 8A FFT Signal Processing: The Overlap-Add (OLA ...
    Jun 27, 2020 · In the weighted overlap add (WOLA) method, we apply a second window after the inverse DFT. Such a window can be called a “synthesis window”, “ ...
  13. [13]
    3.2. Windowing - Introduction to Speech Processing
    3.2.1.1. Windowing for analysis applications# ... A classical windowing function, the Hann-window w n = [ sin ⁡ ( π n / L ) ] 2 is shown below. The main ...Missing: formula | Show results with:formula
  14. [14]
    [PDF] frequency, phase and amplitude estimation of overlapping partials in
    ... Hann window: when applied twice (before the analysis and after the synthesis), the result is perfect reconstruction for 50% overlap. Furthermore, the ...
  15. [15]
    [PDF] WINDOWING By John Ehlers Simple Moving Averages (SMA) are ...
    Figure 3. Hamming Window with Sine(10) Pedestal SMA Frequency Response. A still smoother weighting function that is easy to program is called the Hann Window.
  16. [16]
    Windowing - Fundamentals of Signal Processing - VRU
    Jun 2, 2021 · Engineers apply a window function to a time signal because the FFT assumes signals are periodic, and real-world vibration is usually random.
  17. [17]
    Using window functions with images — skimage 0.25.2 documentation
    The application of a two-dimensional Hann window greatly reduces the spectral leakage, making the “real” frequency information more visible.
  18. [18]
    8.4 Zero-Padding and Windowing Techniques - Fiveable
    Zero-padding increases frequency resolution ... Example: The Hann window offers a good compromise between frequency resolution and spectral leakage reduction.
  19. [19]
    [PDF] Windowing, Zero Padding
    Clearly, the "Frequency resolution is affected by the shape of. A log-amplitude rectangular window spectrum ( magnitude. Main Lobe window spectrum. (Zologio ...
  20. [20]
    [PDF] Window Functions and Their Applications in Signal Processing
    In the past decades, rapid advances in digital IC (integrated circuit) tech nology have caused a “digital revolution” in the field of signal processing.
  21. [21]
    Meridional Distributions of Historical Zonal Averages and Their Use ...
    In his paper on von Hann's contribution to modern climatology, Kahlig [58] reported that von Hann used a three-term moving average (running mean) procedure ...<|control11|><|separator|>
  22. [22]
    [PDF] The Measurement of Power Spectra from the Point of View of ...
    By R. B. BLACKMAN and J. W. TUKEY. (Manuscript received August 28, 1957) ... (b) The heights of the side lobes for the "hanning" window fall off more ...
  23. [23]
    Window Function - Compute and apply window to input signal
    The Window Function block has three modes of operation that enable you to apply a window, or compute a window, or compute and apply a window to an input signal.<|control11|><|separator|>