@@ -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