MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / dft

Function dft

contents/cooley_tukey/code/javascript/fft.js:3–15  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

1const Complex = require("complex.js");
2
3function dft(x) {
4 const N = x.length;
5
6 // Initialize an array with N elements, filled with 0s
7 return Array(N)
8 .fill(new Complex(0, 0))
9 .map((temp, i) => {
10 // Reduce x into the sum of x_k * exp(-2*sqrt(-1)*pi*i*k/N)
11 return x.reduce((a, b, k) => {
12 return a.add(b.mul(new Complex(0, (-2 * Math.PI * i * k) / N).exp()));
13 }, new Complex(0, 0)); // Start accumulating from 0
14 });
15}
16
17function cooley_tukey(x) {
18 const N = x.length;

Callers 1

fft.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected