HanningWindow<T>

Models & Types · AiDotNet.WindowFunctions

Implements the Hanning window function (also known as Hann window) for signal processing applications.

Implements: IWindowFunction<T>

For Beginners

A window function is like a special filter that helps analyze signals more accurately.

The Hanning window:

  • Creates a smooth bell-shaped curve that starts and ends exactly at zero
  • Has a simple mathematical form that makes it easy to implement
  • Provides a good balance between frequency resolution and spectral leakage

Think of it like looking through a window with edges that gradually fade to black. When analyzing frequencies in a signal (like audio), the Hanning window helps reduce the artifacts that occur when you’re only looking at a portion of a continuous signal. It’s particularly good for analyzing sounds like musical notes or any other signals that repeat over time.

How It Works

The Hanning window is a popular window function that provides good frequency resolution and reduced spectral leakage. It is defined by the equation: w(n) = 0.5 * (1 - cos(2pn/(N-1))) where n is the sample index and N is the window size. The Hanning window reaches exactly zero at both ends, which makes it particularly useful for analyzing periodic signals.

Example

using AiDotNet.WindowFunctions;
using AiDotNet.Tensors.LinearAlgebra;

var window = new HanningWindow<double>();
Vector<double> w = window.Create(16);
Console.WriteLine($"HanningWindow: {w.Length}-point window, center = {w[w.Length / 2]:F4}");

Constructors

Constructor Summary
HanningWindow() Initializes a new instance of the HanningWindow class.

Methods

Method Summary
Vector<T> Create(int windowSize) Creates a Hanning window of the specified size.
WindowFunctionType GetWindowFunctionType() Gets the type identifier for this window function.