Name: window-function
Owner: scijs
Description: Collection of window functions
Created: 2015-05-12 19:51:31.0
Updated: 2018-03-28 13:26:48.0
Pushed: 2017-06-23 03:58:07.0
Size: 609
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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 window-function
module:
wfuncs = require('window-function')
value = wfuncs.blackmanHarris( 50, 101 )
You can also require a single window function:
blackmanHarris = require('window-function/blackman-harris')
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( i, N )
:blackman( i, N )
:blackmanHarris( i, N )
:blackmanNuttall( i, N )
:cosine( i, N )
:exactBlackman( i, N )
: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 )
:gaussian( i, N, sigma )
:Sigma controls the width of the window.
hamming( i, N )
:hann( i, N )
:lanczos( i, N )
:nuttall( i, N )
:rectangular( i, N )
:triangular( i, N )
: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.
welch( i, N )
: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
m 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