window-function [](https://github.com/audiojs/window-function/actions/workflows/test.yml) [](https://www.npmjs.com/package/window-function) [](https://github.com/krishnized/license)
March 26, 2026 · View on GitHub
Collection of window functions for signal processing and spectral analysis.
npm install window-function
import { hann, kaiser, generate, apply } from 'window-function'
// Every window: fn(i, N, ...params) → number
hann(50, 101) // single sample → 1.0
// Generate full window as Float64Array
let w = generate(hann, 1024)
// Apply window to a signal in-place
let signal = new Float64Array(1024).fill(1)
apply(signal, hann) // signal *= hann
// Parameterized windows pass extra args
generate(kaiser, 1024, 8.6) // Kaiser with β = 8.6
Or import individual windows directly:
import hann from 'window-function/hann'
import kaiser from 'window-function/kaiser'
Reference
- Simple
-
rectangular · triangular · bartlett · welch · connes · hann · hamming · cosine · blackman · exactBlackman · nuttall · blackmanNuttall · blackmanHarris · flatTop · bartlettHann · lanczos · parzen · bohman
- Parameterized
-
kaiser · gaussian · generalizedNormal · tukey · planckTaper · powerOfSine · exponential · hannPoisson · cauchy · rifeVincent · confinedGaussian
- Array-computed
-
dolphChebyshev · taylor · kaiserBesselDerived · dpss · ultraspherical
Simple — no parameters
rectangular(i, N)
No windowing. Best frequency resolution, worst spectral leakage. Use for transient signals already zero at edges, or harmonic analysis with integer cycles. -13 dB sidelobe · -6 dB/oct rolloff
triangular(i, N)
Linear taper, nonzero endpoints. Simple smoothing, 2nd-order B-spline. -27 dB sidelobe · -12 dB/oct rolloff
bartlett(i, N)
Linear taper, zero endpoints. Bartlett's method PSD estimation.1 -27 dB sidelobe · -12 dB/oct rolloff
welch(i, N)
Parabolic taper. Welch's method PSD estimation.2 -21 dB sidelobe · -12 dB/oct rolloff
connes(i, N)
Welch squared (4th power parabolic). FTIR spectroscopy, interferogram apodization.3 -24 dB/oct rolloff
hann(i, N)
Raised cosine, zero endpoints. The default general-purpose choice. STFT with 50% overlap (COLA). Also called "Hanning" (misnomer).4 -32 dB sidelobe · -18 dB/oct rolloff
hamming(i, N)
Raised cosine, nonzero endpoints. Optimized for first sidelobe cancellation. FIR filter design, speech processing.5 -43 dB sidelobe · -6 dB/oct rolloff
cosine(i, N)
Half-period sine. MDCT audio codecs: MP3, AAC, Vorbis.6 -23 dB sidelobe · -12 dB/oct rolloff
blackman(i, N)
3-term cosine sum. Better leakage than Hann at the cost of wider main lobe.4 -58 dB sidelobe · -18 dB/oct rolloff
exactBlackman(i, N)
Blackman with exact zero placement at 3rd and 4th sidelobes.7 -69 dB sidelobe · -6 dB/oct rolloff
nuttall(i, N)
4-term cosine sum, continuous 1st derivative. High-dynamic-range analysis without edge discontinuity.8 -93 dB sidelobe · -18 dB/oct rolloff
blackmanNuttall(i, N)
4-term cosine sum, lowest sidelobes among 4-term windows.8 -98 dB sidelobe · -6 dB/oct rolloff
blackmanHarris(i, N)
4-term minimum sidelobe. ADC testing, measurement instrumentation, >80 dB dynamic range.7 -92 dB sidelobe · -6 dB/oct rolloff
flatTop(i, N)
5-term cosine sum, near-zero scalloping. Peak ~4.64 (by design). Amplitude calibration, transducer calibration (~0.01 dB accuracy). ISO 18431.9 -93 dB sidelobe · -6 dB/oct rolloff
bartlettHann(i, N)
Bartlett-Hann hybrid. Balanced near/far sidelobe levels.10 -36 dB sidelobe
lanczos(i, N)
Sinc main lobe. Image resampling, interpolation (FFmpeg, ImageMagick).11 -26 dB sidelobe
parzen(i, N)
for , for ,
4th-order B-spline. Always-positive spectrum. Kernel density estimation.12 -53 dB sidelobe · -24 dB/oct rolloff
bohman(i, N)
,
Autocorrelation of cosine window. Fast sidelobe decay, spectral estimation. -46 dB sidelobe · -24 dB/oct rolloff
Parameterized — adjustable tradeoff
kaiser(i, N, beta)
beta: shape — 0 = rectangular, 5.4 = Hamming, 8.6 (default) = Blackman.
Near-optimal DPSS approximation via Bessel I₀. The standard parameterized window for FIR filter design.13
gaussian(i, N, sigma)
sigma: width, default 0.4.
Gaussian bell, minimum time-bandwidth product. STFT/Gabor transform, frequency estimation via parabolic interpolation.14
generalizedNormal(i, N, sigma, p)
sigma: width (default 0.4), p: shape — 2 = Gaussian, large = rectangular.
Continuous family between Gaussian and rectangular. Adjustable time-frequency tradeoff.
tukey(i, N, alpha)
alpha: taper fraction — 0 = rectangular, 0.5 (default), 1 = Hann.
in tapered edges, in flat center.
Flat center with cosine-tapered edges. Preserves signal amplitude while tapering. Vibration analysis, LIGO.
planckTaper(i, N, epsilon)
epsilon: taper fraction, default 0.1.
C∞-smooth bump function (infinitely differentiable). Gravitational wave analysis (LIGO/Virgo).15
powerOfSine(i, N, alpha)
alpha: exponent — 0 = rectangular, 1 = cosine, 2 (default) = Hann.
family. Codec design, parameterized spectral analysis.
exponential(i, N, tau)
tau: time constant, default 1.
Exponential decay from center. Modal analysis, impact testing.7
hannPoisson(i, N, alpha)
alpha: decay, default 2. At α ≥ 2 the transform has no sidelobes.
Hann × exponential. Unique no-sidelobe property enables frequency estimators using convex optimization.
cauchy(i, N, alpha)
alpha: width, default 3.
Lorentzian shape. Matches spectral line shapes in spectroscopy.7
rifeVincent(i, N, order)
order: 1 (default) = Hann, 2, 3. Throws for other values.
Class I cosine-sum optimized for sidelobe fall-off. Power grid harmonic analysis, interpolated DFT.16
confinedGaussian(i, N, sigmaT)
sigmaT: temporal width, default 0.1.
Optimal RMS time-frequency bandwidth. Time-frequency analysis, audio coding.17
Array-computed — cached
Compute the full window on first call, cache the result. Recomputed when parameters change.
dolphChebyshev(i, N, dB)
dB: sidelobe attenuation, default 100.
,
Optimal: narrowest main lobe for given equiripple sidelobe level. Antenna design, radar.18
taylor(i, N, nbar, sll)
nbar: constant-level sidelobes (default 4), sll: level in dB (default 30).
Monotonically decreasing sidelobes. The radar community standard for SAR image formation.19
kaiserBesselDerived(i, N, beta)
beta: shape, default 8.6. N must be even.
,
Princen-Bradley condition for perfect MDCT reconstruction. AAC, Vorbis, Opus audio codecs.6
dpss(i, N, W)
W: half-bandwidth [0, 0.5], default 0.1.
,
Dominant eigenvector of sinc Toeplitz matrix — provably optimal energy concentration. Also called Slepian window. Multitaper spectral estimation, neuroscience, climate science.20
ultraspherical(i, N, mu, xmu)
mu: 0 = Dolph-Chebyshev, 1 (default) = Saramaki. xmu: sidelobe control (default 1).
,
Gegenbauer polynomial window. Independent control of sidelobe level and taper rate. Antenna design, beamforming.21
Choosing a window
Every window trades frequency resolution (narrow main lobe), spectral leakage (low sidelobes), and amplitude accuracy (flat top). No single window wins all three.
- Just get started
- hann — good all-round, zero edges, 50% COLA
- Design FIR filters
- kaiser or hamming — Kaiser is tunable, Hamming is the classic
- Measure amplitudes accurately
- flatTop — < 0.01 dB scalloping loss
- High dynamic range (>80 dB)
- blackmanHarris — -92 dB equiripple sidelobes
- Audio codec (MDCT)
- kaiserBesselDerived or cosine — Princen-Bradley perfect reconstruction
- Preserve center, taper edges
- tukey — adjustable flat-top fraction
- Robust spectral estimation
- dpss — optimal for multitaper method
- Radar / SAR
- taylor — monotonic sidelobes, radar standard
- Antenna array design
- dolphChebyshev or ultraspherical — optimal equiripple or tunable taper
- Tune resolution/leakage continuously
- kaiser or gaussian — single-parameter adjustment
- Modal / impact analysis
- exponential — controlled decay for underdamped systems
- FTIR spectroscopy
- connes — smooth apodization for interferograms
- Gravitational waves
- planckTaper — C∞ smooth, no spectral artifacts
Metrics
Three functions for quantitative window comparison:
import { hann, enbw, scallopLoss, cola } from 'window-function'
enbw(hann, 1024) // 1.5 — noise bandwidth (bins)
scallopLoss(hann, 1024) // 1.42 — worst-case amplitude error (dB)
cola(hann, 1024, 512) // 0 — perfect STFT reconstruction
enbw(fn, N, ...params)— equivalent noise bandwidth in frequency bins. Rectangular = 1.0, Hann = 1.5, Blackman-Harris = 2.0. Lower = less noise.scallopLoss(fn, N, ...params)— worst-case amplitude error in dB between DFT bins. Rectangular = 3.92, Hann = 1.42, flat-top ≈ 0.cola(fn, N, hop, ...params)— COLA deviation. 0 = perfect STFT reconstruction at given hop size.
Footnotes
-
M.S. Bartlett, "Periodogram Analysis and Continuous Spectra," Biometrika 37, 1950. ↩
-
P.D. Welch, "The Use of FFT for Estimation of Power Spectra," IEEE Trans. Audio Electroacoustics AU-15, 1967. ↩
-
J. Connes, "Recherches sur la spectroscopie par transformation de Fourier," Revue d'Optique 40, 1961. ↩
-
R.B. Blackman & J.W. Tukey, The Measurement of Power Spectra, Dover, 1958. ↩ ↩2
-
R.W. Hamming, Digital Filters, Prentice-Hall, 1977. ↩
-
J.P. Princen, A.W. Johnson & A.B. Bradley, "Subband/Transform Coding Using Filter Bank Designs Based on TDAC," ICASSP, 1987. ↩ ↩2
-
F.J. Harris, "On the Use of Windows for Harmonic Analysis with the DFT," Proc. IEEE 66, 1978. ↩ ↩2 ↩3 ↩4
-
A.H. Nuttall, "Some Windows with Very Good Sidelobe Behavior," IEEE Trans. ASSP 29, 1981. ↩ ↩2
-
G. Heinzel, A. Rudiger & R. Schilling, "Spectrum and Spectral Density Estimation by the DFT," Max Planck Institute, 2002. ↩
-
Y.H. Ha & J.A. Pearce, "A New Window and Comparison to Standard Windows," IEEE Trans. ASSP, 1989. ↩
-
C.E. Duchon, "Lanczos Filtering in One and Two Dimensions," J. Applied Meteorology 18, 1979. ↩
-
E. Parzen, "Mathematical Considerations in the Estimation of Spectra," Technometrics 3, 1961. ↩
-
J.F. Kaiser, "Nonrecursive Digital Filter Design Using the Sinh Window Function," IEEE Int. Symp. Circuits and Systems, 1974. ↩
-
D. Gabor, "Theory of Communication," J. IEE 93, 1946. ↩
-
D.J.A. McKechan et al., "A Tapering Window for Time-Domain Templates," Class. Quantum Grav. 27, 2010. ↩
-
D.C. Rife & G.A. Vincent, "Use of the DFT in Measurement of Frequencies and Levels of Tones," Bell Syst. Tech. J. 49, 1970. ↩
-
S. Starosielec & D. Hagemeier, "Discrete-Time Windows with Minimal RMS Bandwidth," Signal Processing 102, 2014. ↩
-
C.L. Dolph, "A Current Distribution for Broadside Arrays," Proc. IRE 34, 1946. ↩
-
T.T. Taylor, "Design of Line-Source Antennas," IRE Trans. Antennas Propag. AP-4, 1955. ↩
-
D. Slepian, "Prolate Spheroidal Wave Functions — V," Bell Syst. Tech. J. 57, 1978. ↩
-
R.L. Streit, "A Two-Parameter Family of Weights for Nonrecursive Digital Filters and Antennas," IEEE Trans. ASSP 32, 1984. ↩