Main Content

hann

Hann (Hanning) window

Description

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.

w = hann(___,typeName) specifies the option to return the window w with single or double precision.

Examples

collapse all

Create a 64-point Hann window. Display the result using wvtool.

L = 64;
wvtool(hann(L))

Figure Window Visualization Tool contains 2 axes objects and other objects of type uimenu, uitoolbar, uipanel. Axes object 1 with title Time domain, xlabel Samples, ylabel Amplitude contains an object of type line. Axes object 2 with title Frequency domain, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Magnitude (dB) contains an object of type line.

Input Arguments

collapse all

Window length, specified as a positive integer.

Note

If you specify L as noninteger, the function rounds it to the nearest integer value.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Window sampling method, specified as:

  • "symmetric" — Use this option when using windows for filter design.

  • "periodic" — Use this option when using windows for spectral analysis. When you specify "periodic", hann computes a window of length L + 1 and returns the first L points. The missing endpoint is the beginning of the next period of the periodic extension of the sequence. Therefore, the sequence satisfies the periodicity assumption of the discrete Fourier transform.

Data Types: char | string

Since R2024b

Output data type (class), specified as one of these:

  • "double" — Use this option to return a double-precision output w.

  • "single" — Use this option to return a single-precision output w.

Data Types: char | string

Output Arguments

collapse all

Hann window, returned as a column vector.

Algorithms

The following equation generates the coefficients of a Hann window:

w(n)=0.5(1cos(2πnN)),0nN.

The window length L = N + 1.

References

[1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced before R2006a

expand all