npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

window-function

v2.1.0

Published

Window functions for spectral analysis

Downloads

340

Readme

window-function

Build Status npm version Dependency Status

Window functions for digital signal processing

Introduction

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.

Usage

Apply window to a signal:

var blackmanHarris = require('window-function/blackman-harris')
var applyWindow = require('window-function/apply')

var signal = [-1, 0, 1, 0, -1, 0]

var windowedSignal = applyWindow(signal, blackmanHarris)

Apply the window functions yourself:

var wfuncs = require('window-function')

var value = wfuncs.blackmanHarris( 50, 101 )

API

require('window-funciton/<type>')(i, total)

To calculate the value of a window function, pass the sample number i 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-Hann

bartlett( i, N ):

Bartlett

blackman( i, N ):

Blackman Window Equation 1

Blackman Window Equation 2

Blackman

blackmanHarris( i, N ):

Blackman-Harris Window Equation 1

Blackman-Harris Window Equation 2

Blackman-Harris

blackmanNuttall( i, N ):

Blackman-Nuttall Window Equation 1

Blackman-Nuttall Window Equation 2

Blackman-nuttall

cosine( i, N ):

Cosine Window Equation 1

Cosine

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

Gaussian

hamming( i, N ):

Hamming Window Equation 1

Hamming Window Equation 2

Hamming

hann( i, N ):

Hann Window Equation

Hann

lanczos( i, N ):

Lanczos Window Equation

Lanczos

nuttall( i, N ):

Nuttall Window Equation 1

Nuttall Window Equation 2

Nuttall

rectangular( i, N ):

Rectangular Window Equation

Rectangular

triangular( i, N ):

Triangular Window Equation

Triangular

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

Tukey

welch( i, N ):

Welch Window Equation

Welch

require('window-function/apply')(array, fn)

Apply a windowing function to an array, modifies an array in-place.

require('window-function/generate')(fn, n)

Generate an array of n samples of the window function fn.

Testing

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.

Credits

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

(c) 2015 Ricky Reusser. MIT License