基數 2 逆 FFT

由於傅立葉變換的強對偶性,調整正向變換的輸出可以產生逆 FFT。可以通過以下方法將頻域中的資料轉換為時域:

  1. 通過反轉 K 的所有例項的虛部來找到頻域資料的複共軛。
  2. 對共軛頻域資料執行正向 FFT。
  3. 將此 FFT 結果的每個輸出除以 N,得到真實的時域值。
  4. 通過反轉 n 的所有例項的時域資料的虛部來找到輸出的複共軛。

注意 :頻域和時域資料都是複雜的變數。通常,逆 FFT 之後的時域訊號的虛部是零,或者作為舍入誤差被忽略。將變數的精度從 32 位浮點數增加到 64 位雙精度或 128 位長雙精度可顯著減少由多個連續 FFT 運算產生的舍入誤差。

程式碼示例(C / C++)

#include <math.h>

#define PI       3.1415926535897932384626433832795    // PI for sine/cos calculations
#define TWOPI    6.283185307179586476925286766559     // 2*PI for sine/cos calculations
#define Deg2Rad  0.017453292519943295769236907684886  // Degrees to Radians factor
#define Rad2Deg  57.295779513082320876798154814105    // Radians to Degrees factor
#define log10_2  0.30102999566398119521373889472449   // Log10 of 2 
#define log10_2_INV 3.3219280948873623478703194294948 // 1/Log10(2)

// complex variable structure (double precision)
struct complex
{
public:
    double  Re, Im;        // Not so complicated after all
}; 

void rad2InverseFFT(int N, complex *x, complex *DFT)
{
    // M is number of stages to perform. 2^M = N
    double Mx = (log10((double)N) / log10((double)2));
    int a = (int)(ceil(pow(2.0, Mx)));
    int status = 0;
    if (a != N) // Check N is a power of 2
    {
        x = 0;
        DFT = 0;
        throw "rad2InverseFFT(): N must be a power of 2 for Radix 2 Inverse FFT";
    }

    complex *pDFT = DFT;        // Reset vector for DFT pointers
    complex *pX = x;            // Reset vector for x[n] pointer
    double NN = 1 / (double)N;  // Scaling factor for the inverse FFT        

    for (int i = 0; i < N; i++, DFT++)
        DFT->Im *= -1;          // Find the complex conjugate of the Frequency Spectrum

    DFT = pDFT;                 // Reset Freq Domain Pointer
    rad2FFT(N, DFT, x); // Calculate the forward FFT with variables switched (time & freq)

    int i;
    complex* x;
    for ( i = 0, x = pX; i < N; i++, x++){
        x->Re *= NN;    // Divide time domain by N for correct amplitude scaling
        x->Im *= -1;    // Change the sign of ImX
    }    
}