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

dft-easy

v1.2.0

Published

Discrete Fourrier Transform made easy

Downloads

5

Readme

Dft-Easy

Discrete Fourrier Transform made easy

Example

let data = [
	[0.00,  1],
	[0.25,  0],
	[0.50, -1],
	[0.75,  0],
	[1.00,  1],
	[1.25,  0],
	[1.50, -1],
	[1.75,  0],
]
let dftResult = require("dft-easy")(data)
[
	[frequency0, frequency0Magnitude, frequency0Phase],
	[frequency1, frequency1Magnitude, frequency1Phase],
	...
]
require("gnu-plot")().plot([ {data: dftResult} ])
let dftResult = require("dft-easy")(data, {frequencies:{list:[0.5,1,2]}})
[
	[ 0.5, 0.36..., 2.7... ],
	[   1, 0.91..., 2e-16 ],
	[   2, 0.02..., 5e-16 ]
]

For exemples using realistic data please see:

Methods

dft(data, options)

execute dft

return

result formatted as :

[
	[frequency0, frequency0Magnitude, frequency0Phase],
	[frequency1, frequency1Magnitude, frequency1Phase],
	...
]

data

Ordered data points formatted as :

[
	[sample0Time, sample0Amplitude],
	[sample1Time, sample1Amplitude],
	...
]

options

Note that the object is cloned and therefore not modified.
If you want to read or optimize the calculation of default options, see dft.constructOptions().

options.frequencies

default: {}
There are 3 possibilities:

  • provide an Array of frequencies in options.frequencies.list
  • provide {min, max, number, logBase} parameters to generate this list (see default)
  • provide some or none of these parameters. The rest will be infered from the data (see default)

options.frequencies.min

default: 1/(data[data.length-1][0]-data[0][0])
Maximum frequency of the dft
Default is calculated from data duration, because you need at least one full period to detect a certain frequency

options.frequencies.max

default: (1/<minimum time Delta>) / 2
Minimum frequency of the dft
Default is calculated from the minimum time delta between every data point. Nyquist says that a frequency can only be correctly represented by a double sample frequency.

options.frequencies.number

default: 4096
Number of equally spaced points (at log options.frequencies.logBase)

options.frequencies.logBase

default: 10
Base of the logarithmic spacing of frequencies

options.frequencies.list

default: <Array containining options.frequencies.number frequencies in [options.frequencies.min, options.frequencies.max], equally spaced in a logarithmic space of base options.frequencies.logBase>
Array of frequencies where the dft will calculate the Magnitude and Phase

options.window(t)

default: dft.windows.Taylor()
Function taking t from 0->1 and returning a multiplication factor.
Integral(window(t), 0, 1) should be equal to 1.
You can provide your own window function, or pick one from dft.windows :

[
	Box(),
	Triangular(),
	Welch(),
	Hann(),
	Hamming(),
	Blackman(),
	Nuttal(),
	BlackmanNuttal(),
	BlackmanHarris(),
	FlatTop(),
	Taylor({interpolationSteps:256, sidelobesNumber:4, sidelobesAttenuation:35/*dB*/}),
	Tukey({alpha:.5})
]

Some have configurable parameters that are indicated with their defaults
Most of these come from wikipedia.org/wiki/Window_function

dft.constructOptions(data, options)

This is the method that fills all the options values that aren't provided with their defaults.
You should cache this object when calling the dft quickly or when you want the frequency list to be stable.

let dftOptions = dft.constructOptions(dataChunks[0])
for(let i=0; i<iMax; i++){
	dft(dataChunks[i], dftOptions)
}

return

Constructed options object

options

See dft().

dft.peak(dftResult)

Utility to find Magnitude peak in dftResult

returns

[frequency, magnitude, phase]

dftResult

Result returned from dft()