# node-fftw

> nodejs port for fftw

Latest version **1.0.0** (published 2018-04-05) · GPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install node-fftw
pnpm add node-fftw
yarn add node-fftw
bun add node-fftw
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-04-05 |
| First published | 2018-04-05 |
| Weekly downloads | 0 |
| License | GPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 43.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | zszszsz |
| Maintainers | zszszsz |
| Keywords | fft, fftw |

## Links

- npm: https://www.npmjs.com/package/node-fftw
- Repository: https://github.com/zszszsz/node-fftw
- Homepage: https://github.com/zszszsz/node-fftw#readme
- Issues: https://github.com/zszszsz/node-fftw/issues
- npm.io page: https://npm.io/package/node-fftw

## Recent versions

- 1.0.0 (latest) — 2018-04-05

## README

# node-fftw
This repo is for nodejs port and bindings with fftw, the fft library.

This repo **DOES NOT** contain fftw code, you need to install fftw first.

You can download fftw from http://www.fftw.org/download.html

You can install it following http://www.fftw.org/fftw3_doc/Installation-and-Customization.html

## Functions:
* discrete fourier transform(dft) using fftw 
    * real-to-complex, arbitrary dimensions.
    * complex-to-complex, arbitrary dimensions.


* inverse dft using fftw, using dft with sign=+1
* chirp z transform, accept only 1d real number, using [Bluestein's algorithm](https://en.wikipedia.org/wiki/Chirp_Z-transform).

## Examples
* dft and idft : **`new fftw.dftPlan(isReal, size, sign, flags)`**
    * isReal: indicate real number or complex number. The result is always complex,
    * size : an array, the rank of the array indicate the dimension, 
    the values indicate length of each dimension,
    * sign: -1 for dft, +1 for idft,
    * flags: the flags passed to fftw.

````js
const fftw = require("./index.js");
const dftPlan = new fftw.dftPlan(true, [16], -1, fftw.flags.FFTW_DESTROY_INPUT);
for(var i = 0; i < 16; i++)
{
    dftPlan.in[i] = Math.sin(Math.PI / 4 * i) + Math.cos(Math.PI / 4 * i);
}

dftPlan.calcAsync(function(plan) {
    console.log("dft result", this.out, plan.out);
});
````
* czt : **`new fftw.cztr1dPlan(inSize, outSize, sampleRate, fstart, fstop, flags)`**
    * inSize: the size of input buffer, 1d real
    * outSize: the size of output buffer, 1d complex
    * sampleRate: the sample rate
    * fstart: the frequency to start calculation,
    * fstop: the frequency to stop calculation,
    * flags: the flags passed to fftw.
        * we use w = expi(-2pi *(f2 - f1) / (outSize * sampleRate)),
        * and a = expi(2pi * f1 / sampleRate)

````js
const fftw = require("./index.js");
const cztPlan = new fftw.cztr1dPlan(16, 8, 1, 1, 8, fftw.flags.FFTW_DESTROY_INPUT);
for(var i = 0; i < 16; i++)
{
    cztPlan.in[i] = Math.sin(Math.PI / 4 * i) + Math.cos(Math.PI / 4 * i);
}

cztPlan.calcAsync(function(plan){
    console.log("czt result", this.out, plan.out);
});
````
## Supported flags
````js
const fftw = require("./index.js");
const flags = fftw.flags;
````
* FFTW_MEASURE
* FFTW_DESTROY_INPUT
* FFTW_UNALIGNED
* FFTW_CONSERVE_MEMORY
* FFTW_EXHAUSTIVE
* FFTW_PRESERVE_INPUT
* FFTW_PATIENT
* FFTW_ESTIMATE
* FFTW_WISDOM_ONLY


## TODO
* nodejs implementation for `sid::complex` compatible complex number
* Testing and bug fix
* fftw wisdom interface
* discrete cos transform (DCT)
* DST
* DHT
* fftw multi thread, openmp and MPI interface
* other fftw functionalities

---
_Source: https://npm.io/package/node-fftw · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
