Style fixes for FFT code.

This commit is contained in:
Oleksii Trekhleb 2018-08-15 13:32:09 +03:00
parent ac9920a0f3
commit d736b2f355
2 changed files with 7 additions and 5 deletions

View File

@ -28,7 +28,7 @@ function sequencesApproximatelyEqual(sequence1, sequence2, delta) {
const delta = 1e-6; const delta = 1e-6;
describe('fastFourierTransform', () => { 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 input = [new ComplexNumber({ re: 0, im: 0 })];
const expectedOutput = [new ComplexNumber({ re: 0, im: 0 })]; const expectedOutput = [new ComplexNumber({ re: 0, im: 0 })];
const output = fastFourierTransform(input); const output = fastFourierTransform(input);
@ -38,7 +38,7 @@ describe('fastFourierTransform', () => {
expect(sequencesApproximatelyEqual(input, invertedOutput, delta)).toBe(true); 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 = [ const input = [
new ComplexNumber({ re: 1, im: 2 }), new ComplexNumber({ re: 1, im: 2 }),
new ComplexNumber({ re: 2, im: 3 }), new ComplexNumber({ re: 2, im: 3 }),
@ -59,7 +59,7 @@ describe('fastFourierTransform', () => {
expect(sequencesApproximatelyEqual(input, invertedOut, delta)).toBe(true); 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 = [ const input = [
new ComplexNumber({ re: -83656.9359385182, im: 98724.08038374918 }), new ComplexNumber({ re: -83656.9359385182, im: 98724.08038374918 }),
new ComplexNumber({ re: -47537.415125808424, im: 88441.58381765135 }), new ComplexNumber({ re: -47537.415125808424, im: 88441.58381765135 }),

View File

@ -54,8 +54,10 @@ export default function fastFourierTransform(inputData, inverse = false) {
let phase = new ComplexNumber({ re: 1, im: 0 }); let phase = new ComplexNumber({ re: 1, im: 0 });
for (let idx = blockStart; idx < blockStart + blockLength / 2; idx += 1) { for (let idx = blockStart; idx < blockStart + blockLength / 2; idx += 1) {
const upd1 = output[idx].add(output[idx + blockLength / 2].multiply(phase)); const component = output[idx + blockLength / 2].multiply(phase);
const upd2 = output[idx].subtract(output[idx + blockLength / 2].multiply(phase));
const upd1 = output[idx].add(component);
const upd2 = output[idx].subtract(component);
output[idx] = upd1; output[idx] = upd1;
output[idx + blockLength / 2] = upd2; output[idx + blockLength / 2] = upd2;