Skip to content

Commit c93555f

Browse files
committed
Update FFT computation
1 parent f4983f4 commit c93555f

File tree

3 files changed

+57
-60
lines changed

3 files changed

+57
-60
lines changed

package-lock.json

Lines changed: 44 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"html2canvas": "^1.4.1",
4242
"jszip": "^3.10.1",
4343
"lucide-react": "^0.460.0",
44-
"next": "^14.2.21",
44+
"next": "^14.2.26",
4545
"next-pwa": "^5.6.0",
4646
"next-themes": "^0.3.0",
4747
"react": "^18",

src/components/FFT.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const FFT = forwardRef(
195195
() => ({
196196
updateData(data: number[]) {
197197
for (let i = 0; i < 1; i++) {
198-
const sensorValue = data[selectedChannel ];
198+
const sensorValue = data[selectedChannel];
199199
fftBufferRef.current[i].push(sensorValue);
200200
updatePlot(sensorValue, Zoom);
201201

@@ -251,7 +251,7 @@ const FFT = forwardRef(
251251
return mags;
252252
}
253253

254-
private fft(real: Float32Array, imag: Float32Array): void {
254+
private fft(real: Float32Array, imag: Float32Array) {
255255
const n = this.size;
256256
let j = 0;
257257
for (let i = 0; i < n - 1; i++) {
@@ -263,19 +263,16 @@ const FFT = forwardRef(
263263
while (k <= j) { j -= k; k /= 2; }
264264
j += k;
265265
}
266-
for (let l = 2; l <= n; l *= 2) {
267-
const le2 = l / 2;
268-
for (let k = 0; k < le2; k++) {
269-
const kth = k * (n / l);
270-
const c = this.cosTable[kth], s = this.sinTable[kth];
271-
for (let i = k; i < n; i += l) {
272-
const i2 = i + le2;
273-
const tr = c * real[i2] - s * imag[i2];
274-
const ti = c * imag[i2] + s * real[i2];
275-
real[i2] = real[i] - tr;
276-
imag[i2] = imag[i] - ti;
277-
real[i] += tr;
278-
imag[i] += ti;
266+
for (let len = 2; len <= n; len *= 2) {
267+
const half = len / 2;
268+
for (let i = 0; i < n; i += len) {
269+
for (let j = i, k = 0; j < i + half; j++, k++) {
270+
const tRe = real[j + half] * this.cosTable[k] - imag[j + half] * this.sinTable[k];
271+
const tIm = real[j + half] * this.sinTable[k] + imag[j + half] * this.cosTable[k];
272+
real[j + half] = real[j] - tRe;
273+
imag[j + half] = imag[j] - tIm;
274+
real[j] += tRe;
275+
imag[j] += tIm;
279276
}
280277
}
281278
}

0 commit comments

Comments
 (0)