diff --git a/src/algorithms/math/fourier-transform/__test__/fastFourierTransform.test.js b/src/algorithms/math/fourier-transform/__test__/fastFourierTransform.test.js index 20e1dae5..00586ae1 100644 --- a/src/algorithms/math/fourier-transform/__test__/fastFourierTransform.test.js +++ b/src/algorithms/math/fourier-transform/__test__/fastFourierTransform.test.js @@ -28,7 +28,7 @@ function sequencesApproximatelyEqual(sequence1, sequence2, delta) { const delta = 1e-6; describe('fastFourierTransform', () => { - it('should calculate the radix-2 discrete fourier transform after zero padding', () => { + it('should calculate the radix-2 discrete fourier transform #1', () => { const input = [new ComplexNumber({ re: 0, im: 0 })]; const expectedOutput = [new ComplexNumber({ re: 0, im: 0 })]; const output = fastFourierTransform(input); @@ -38,7 +38,7 @@ describe('fastFourierTransform', () => { expect(sequencesApproximatelyEqual(input, invertedOutput, delta)).toBe(true); }); - it('should calculate the radix-2 discrete fourier transform after zero padding', () => { + it('should calculate the radix-2 discrete fourier transform #2', () => { const input = [ new ComplexNumber({ re: 1, im: 2 }), new ComplexNumber({ re: 2, im: 3 }), @@ -59,7 +59,7 @@ describe('fastFourierTransform', () => { expect(sequencesApproximatelyEqual(input, invertedOut, delta)).toBe(true); }); - it('should calculate the radix-2 discrete fourier transform after zero padding', () => { + it('should calculate the radix-2 discrete fourier transform #3', () => { const input = [ new ComplexNumber({ re: -83656.9359385182, im: 98724.08038374918 }), new ComplexNumber({ re: -47537.415125808424, im: 88441.58381765135 }), diff --git a/src/algorithms/math/fourier-transform/fastFourierTransform.js b/src/algorithms/math/fourier-transform/fastFourierTransform.js index 5fa75688..76c4e45a 100644 --- a/src/algorithms/math/fourier-transform/fastFourierTransform.js +++ b/src/algorithms/math/fourier-transform/fastFourierTransform.js @@ -54,8 +54,10 @@ export default function fastFourierTransform(inputData, inverse = false) { let phase = new ComplexNumber({ re: 1, im: 0 }); for (let idx = blockStart; idx < blockStart + blockLength / 2; idx += 1) { - const upd1 = output[idx].add(output[idx + blockLength / 2].multiply(phase)); - const upd2 = output[idx].subtract(output[idx + blockLength / 2].multiply(phase)); + const component = output[idx + blockLength / 2].multiply(phase); + + const upd1 = output[idx].add(component); + const upd2 = output[idx].subtract(component); output[idx] = upd1; output[idx + blockLength / 2] = upd2;