Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 13ed506

Browse files
committed
Update FFT tests.
1 parent c2f7e49 commit 13ed506

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

‎src/algorithms/math/fourier-transform/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ Stuart Riffle has a great interpretation of the Fourier Transform:
120120
## References
121121

122122
- [An Interactive Guide To The Fourier Transform](https://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/)
123-
- [YouTube by Better Explained](https://www.youtube.com/watch?v=iN0VG9N2q0U&t=0s&index=77&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
124-
- [YouTube by 3Blue1Brown](https://www.youtube.com/watch?v=spUNpyF58BY&t=0s&index=76&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
123+
- [DFT on YouTube by Better Explained](https://www.youtube.com/watch?v=iN0VG9N2q0U&t=0s&index=77&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
124+
- [FT on YouTube by 3Blue1Brown](https://www.youtube.com/watch?v=spUNpyF58BY&t=0s&index=76&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
125+
- [FFT on YouTube by Simon Xu](https://www.youtube.com/watch?v=htCj9exbGo0&index=78&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8&t=0s)
125126
- Wikipedia
126127
- [FT](https://en.wikipedia.org/wiki/Fourier_transform)
127128
- [DFT](https://www.wikiwand.com/en/Discrete_Fourier_transform)

‎src/algorithms/math/fourier-transform/__test__/fastFourierTransform.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ describe('fastFourierTransform', () => {
5353
];
5454

5555
const output = fastFourierTransform(input);
56-
const invertedOut = fastFourierTransform(output, true);
56+
const invertedOutput = fastFourierTransform(output, true);
5757

5858
expect(sequencesApproximatelyEqual(expectedOutput, output, delta)).toBe(true);
59-
expect(sequencesApproximatelyEqual(input, invertedOut, delta)).toBe(true);
59+
expect(sequencesApproximatelyEqual(input, invertedOutput, delta)).toBe(true);
6060
});
6161

6262
it('should calculate the radix-2 discrete fourier transform #3', () => {

‎src/algorithms/math/fourier-transform/fastFourierTransform.js‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import bitLength from '../bits/bitLength';
44
/**
55
* Returns the number which is the flipped binary representation of input.
66
*
7-
* @param {Number} [input]
8-
* @param {Number} [bitsCount]
9-
* @return {Number}
7+
* @param {number} input
8+
* @param {number} bitsCount
9+
* @return {number}
1010
*/
1111
function reverseBits(input, bitsCount) {
1212
let reversedBits = 0;
1313

14-
for (let i = 0; i < bitsCount; i += 1) {
14+
for (let bitIndex = 0; bitIndex < bitsCount; bitIndex += 1) {
1515
reversedBits *= 2;
1616

17-
if (Math.floor(input / (1 << i)) % 2 === 1) {
17+
if (Math.floor(input / (1 << bitIndex)) % 2 === 1) {
1818
reversedBits += 1;
1919
}
2020
}
@@ -39,8 +39,8 @@ export default function fastFourierTransform(inputData, inverse = false) {
3939
}
4040

4141
const output = [];
42-
for (let i = 0; i < N; i += 1) {
43-
output[i] = inputData[reverseBits(i, bitsCount)];
42+
for (let dataSampleIndex = 0; dataSampleIndex < N; dataSampleIndex += 1) {
43+
output[dataSampleIndex] = inputData[reverseBits(dataSampleIndex, bitsCount)];
4444
}
4545

4646
for (let blockLength = 2; blockLength <= N; blockLength *= 2) {
@@ -53,23 +53,23 @@ export default function fastFourierTransform(inputData, inverse = false) {
5353
for (let blockStart = 0; blockStart < N; blockStart += blockLength) {
5454
let phase = new ComplexNumber({ re: 1, im: 0 });
5555

56-
for (let idx = blockStart; idx < blockStart + blockLength / 2;idx += 1) {
57-
const component = output[idx + blockLength / 2].multiply(phase);
56+
for (let signalId = blockStart; signalId < (blockStart + blockLength / 2);signalId += 1) {
57+
const component = output[signalId + blockLength / 2].multiply(phase);
5858

59-
const upd1 = output[idx].add(component);
60-
const upd2 = output[idx].subtract(component);
59+
const upd1 = output[signalId].add(component);
60+
const upd2 = output[signalId].subtract(component);
6161

62-
output[idx] = upd1;
63-
output[idx + blockLength / 2] = upd2;
62+
output[signalId] = upd1;
63+
output[signalId + blockLength / 2] = upd2;
6464

6565
phase = phase.multiply(phaseStep);
6666
}
6767
}
6868
}
6969

7070
if (inverse) {
71-
for (let idx = 0; idx < N; idx += 1) {
72-
output[idx] /= N;
71+
for (let signalId = 0; signalId < N; signalId += 1) {
72+
output[signalId] /= N;
7373
}
7474
}
7575

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /