基数 2 逆 FFT
由于傅立叶变换的强对偶性,调整正向变换的输出可以产生逆 FFT。可以通过以下方法将频域中的数据转换为时域:
- 通过反转 K 的所有实例的虚部来找到频域数据的复共轭。
- 对共轭频域数据执行正向 FFT。
- 将此 FFT 结果的每个输出除以 N,得到真实的时域值。
- 通过反转 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
}
}