Implementation of the Discrete Fourier Transform for 2D inputs, and its inverse, from its definition equation.
npm install dft-2d-fromdefinitionThis Node module is an implementation of the two-dimensional Discrete Fourier Transform (2D-DFT), and its inverse, from its very definition. It is intended for educational and research purposes. You should use this module with small inputs only, since calculating the transform from the definition is inefficient.
The equations below show the definition of the 2D-DFT and the conventions supported in this module.
npm install dft-2d-fromdefinition
Note that the inputs and outputs are matrices of complex values, so as to support complex signals. If your signal is real, just convert it to complex first, e.g., [[8,9],[7,6]] becomes [[[8,0],[9,0]],[[7,0],[6,0]]].
##### Forward transform
``
const dft2ddef = require('dft-2d-fromdefinition');
let signal = [[[1,1],[2,0]],[[4,4],[5,0]]]; // corresponds to the complex signal [[1+j,2],[4+4j,5]]
let transform = dft2ddef.dft(signal, 'unnormalized_forward');
console.log(transform);
// Gives approx. [[[12,5],[-2,5]],[[-6,-3],[0,-3]]]
`
##### Inverse transform
`
const dft2ddef = require('dft-2d-fromdefinition');
let transform = [[[12,5],[-2,5]],[[-6,-3],[0,-3]]];
let signal = dft2ddef.idft(transform, 'unnormalized_forward');
console.log(signal);
// Gives approx. [[[1,1],[2,0]],[[4,4],[5,0]]] // corresponds to the complex signal [[1+j,2],[4+4j,5]]
``
The project that gave rise to these results received the support of a fellowship from ”la Caixa” Foundation (ID 100010434). The fellowship code is LCF/BQ/DI22/11940036. This work was also supported by FCT through the LASIGE Research Unit (UID/00408/2025).
This work is licensed under CC BY 4.0. See LICENSE for more details.