node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Build Status npm version Dependency Status

Window functions for digital signal processing


Among other uses, window functions help control spectral leakage when doing Fourier Analysis. This collection of window functions is copied directly from Wikipedia. Caveat emptor.


To require all window functions, include the top-level scijs-window-functions module:

var wfuncs = require('scijs-window-functions')
var value = wfuncs.blackmanHarris( 50, 101 )

You can also require a single window function:

var blackmanHarris = require('scijs-wind-wfunctions/blackman-harris')
var value = blackmanHarris( 50, 101 )

To calculate the value of a window function, pass the sample number and total number of samples to one of the window functions listed below, along with any additional parameters it may require. The plots below are calculated from the npm module and plotted with Fourier transform to illustrate the spectral leakage. See the Wikipedia page on window functions for more details.

bartlettHann( i, N ):

Bartlett-Hann Window Equation 1

Bartlett-Hann Window Equation 2


bartlett( i, N ):


blackman( i, N ):

Blackman Window Equation 1

Blackman Window Equation 2


blackmanHarris( i, N ):

Blackman-Harris Window Equation 1

Blackman-Harris Window Equation 2


blackmanNuttall( i, N ):

Blackman-Nuttall Window Equation 1

Blackman-Nuttall Window Equation 2


cosine( i, N ):

Cosine Window Equation 1


exactBlackman( i, N ):

Exact Blackman

The same as the Blackman window, except a0 = 0.42659 a1 = 0.49656, and a2 = 0.076849. These place zeros at the third and fourth sidelobes.

flatTop( i, N ):

Flat top Window Equation 1

Flat top Window Equation 2

Flat Top

gaussian( i, N, sigma ):

Sigma controls the width of the window.

Gaussian Window Equation 1

Gaussian Window Equation 2


hamming( i, N ):

Hamming Window Equation 1

Hamming Window Equation 2


hann( i, N ):

Hann Window Equation


lanczos( i, N ):

Lanczos Window Equation


nuttall( i, N ):

Nuttall Window Equation 1

Nuttall Window Equation 2


rectangular( i, N ):

Rectangular Window Equation


triangular( i, N ):

Triangular Window Equation


tukey( i, N, alpha ):

A tapered cosine window. Alpha controls the relative width of the flat section. Alpha=0 is rectangular, alpha=1 is Hann. Tukey Window Equation


welch( i, N ):

Welch Window Equation



The tests ensure the window functions aren't returning NaN, but it's hard to have confidence in the accuracy with tests. Instead, I opted to focus on visual testing via plots and Fourier Transforms. To generate the plots, run

$ npm run generate-plots

It pipes them through matplotlib. Don't worry. I realize the irony.


Window function definitions and equation images from Wikipedia: Window Function.

(c) 2015 Ricky Reusser. MIT License