Mercurial > hg > js-dsp-test
changeset 24:e705de983b67
Put the comments back in!
author | Chris Cannam |
---|---|
date | Wed, 07 Oct 2015 08:57:11 +0100 |
parents | 16cefafeafcf |
children | 66f9fd5ac611 |
files | fft/nayuki-obj/fft.js |
diffstat | 1 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/fft/nayuki-obj/fft.js Tue Oct 06 17:51:43 2015 +0100 +++ b/fft/nayuki-obj/fft.js Wed Oct 07 08:57:11 2015 +0100 @@ -3,7 +3,7 @@ * * Copyright (c) 2014 Project Nayuki * http://www.nayuki.io/page/free-small-fft-in-multiple-languages - * + * * (MIT License) * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -20,10 +20,15 @@ * liability, whether in an action of contract, tort or otherwise, arising from, * out of or in connection with the Software or the use or other dealings in the * Software. + * + * Slightly restructured by Chris Cannam, cannam@all-day-breakfast.com */ "use strict"; +/* + * Construct an object for calculating the discrete Fourier transform (DFT) of size n, where n is a power of 2. + */ function FFTNayuki(n) { this.n = n; @@ -45,10 +50,15 @@ this.sinTable[i] = Math.sin(2 * Math.PI * i / n); } + /* + * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector. + * The vector's length must be equal to the size n that was passed to the object constructor, and this must be a power of 2. Uses the Cooley-Tukey decimation-in-time radix-2 algorithm. + */ this.forward = function(real, imag) { var n = this.n; + // Bit-reversed addressing permutation for (var i = 0; i < n; i++) { var j = reverseBits(i, this.levels); if (j > i) { @@ -61,6 +71,7 @@ } } + // Cooley-Tukey decimation-in-time radix-2 FFT for (var size = 2; size <= n; size *= 2) { var halfsize = size / 2; var tablestep = n / size; @@ -78,6 +89,7 @@ } } + // Returns the integer whose value is the reverse of the lowest 'bits' bits of the integer 'x'. function reverseBits(x, bits) { var y = 0; for (var i = 0; i < bits; i++) { @@ -88,6 +100,10 @@ } } + /* + * Computes the inverse discrete Fourier transform (IDFT) of the given complex vector, storing the result back into the vector. + * The vector's length must be equal to the size n that was passed to the object constructor, and this must be a power of 2. This is a wrapper function. This transform does not perform scaling, so the inverse is not a true inverse. + */ this.inverse = function(real, imag) { forward(imag, real); }