hann — Generate Hann windows in MATLAB and RunMat.
hann(L) returns an L-by-1 Hann window. Symmetric/periodic forms and optional single-precision output follow MATLAB semantics.
Syntax
w = hann(n)
w = hann(n, sampling)
w = hann(n, precision)
w = hann(n, sampling, precision)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
n | SizeArg | Yes | — | Window length. |
sampling | StringScalar | No | "symmetric" | Sampling mode: "symmetric" or "periodic". |
precision | StringScalar | No | "double" | Output precision: "double" or "single". |
Returns
| Name | Type | Description |
|---|---|---|
w | NumericArray | Hann window column vector. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:hann:InvalidLength | Length input is not a finite nonnegative scalar value. | hann: expected a nonnegative scalar integer length |
RunMat:hann:InvalidOption | An option argument is not a string-like sampling/precision token. | hann: unrecognized option |
RunMat:hann:UnknownOption | An option string is not recognized by hann. | hann: unrecognized option |
RunMat:hann:InternalError | Window materialization fails internally. | hann: internal error |
How hann works
hann(L)returns anL x 1symmetric Hann window.hann(L, 'periodic')returns the periodic form used in spectral-analysis workflows.hann(..., 'single')returns a single-precision window;'double'is the default.- If
Lis noninteger, RunMat rounds it to the nearest integer before constructing the window. hann(0)returns an empty0 x 1tensor.hann(1)returns1.- For the symmetric case and
L > 1, coefficients follow0.5 - 0.5*cos(2*pi*n/(L-1)). - The periodic form is constructed by evaluating a symmetric window of length
L + 1and dropping the final sample.
Examples
Generate a short Hann window
w = hann(8);
disp(w')Generate a periodic Hann window for spectral analysis
w = hann(8, 'periodic');
disp(w')Generate a single-precision Hann window
w = hann(8, 'single');
class(w)Using hann with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how hann changes the result.
Run a small hann example, explain the result, then change one input and compare the output.
FAQ
What is the difference between the symmetric and periodic Hann window?⌄
Use the default symmetric window for filter-design style workflows. Use 'periodic' for spectral analysis, where MATLAB and RunMat construct a symmetric window of length L + 1 and drop the last sample so the sequence matches the periodicity assumptions of the DFT.
What shape does hann(L) return?⌄
It returns an L x 1 column vector, matching MATLAB's window-function convention.
Does hann support single precision?⌄
Yes. Pass 'single' as the final option to request a single-precision output. The default output type is double precision.
Related Math functions
Signal
blackman · butter · buttord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hilbert · periodogram · pulstran · pwelch · rectpuls · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Elementwise
abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · heaviside · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times
Trigonometry
acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh
Reduction
all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var
Structure
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.