How to Inverse FFT in Arduino

前端 未结 1 1202
暖寄归人
暖寄归人 2021-01-20 23:54

I am trying to filter some data based on the the following code using Arduino FFT library for FFT (fast Fourier transform)

/*
fft_adc_serial.pde
guest openmusic         


        
相关标签:
1条回答
  • 2021-01-21 00:36

    The inverse FFT can be obtained by making use of the forward transform:

    for (int i = 0 ; i < 512 ; i += 2) {
      fft_input[i] =  (fft_input[i] >> 8);
      fft_input[i+1] = -(fft_input[i+1] >> 8);
    }
    fft_reorder();
    fft_run();
    // For complex data, you would then need to negate the imaginary part
    // but we can skip this step since you have real data.
    

    Note however that your filtering code has a few issues.

    First, the results of the forward FFT are complex numbers which carry both magnitude and phase information. Using fft_mag_log only takes the magnitude, which alone is not sufficient for recovery of the original signal. You should thus use the complete FFT output left in fft_input array as input to your filtering code.

    Second, the FFT of real valued data results in a spectrum with Hermitian symmetry. To get a real valued filtered output, you must preserve that symmetry. So, you should not completely zero out the values in the upper half of the spectrum:

    for (byte i = 0; i < FFT_N; i+=2) {
      if (! ((i>=20 && i<=40) || (i>=FFT_N-40 && i<=FFT_N-20)))
      {
        fft_input[i] = 0;
        fft_input[i+1] = 0;
      }
    }
    

    Third, the filtering would be applied to each block of data independently of each other, always assuming that previous inputs were zeros. This typically results in discontinuities at the block boundaries. To avoid this, you should consider using the overlap-add method.

    0 讨论(0)
提交回复
热议问题