基-2DIT-FFT算法的原理及MATLAB简单实现

DFT的矩阵表示
[ X ( 0 ) X ( 1 ) X ( 2 ) ⋮ X ( k ) ⋮ X ( N − 1 ) ] = [ W N i j ] [ x ( 0 ) x ( 1 ) x ( 2 ) ⋮ x ( k ) ⋮ x ( N − 1 ) ] \begin{bmatrix}X(0) \\ X(1) \\ X(2) \\ \vdots \\ X(k) \\ \vdots \\ X(N-1)\end{bmatrix}= [W_N^{ij}]\begin{bmatrix}x(0) \\ x(1) \\ x(2) \\ \vdots \\ x(k) \\ \vdots \\ x(N-1)\end{bmatrix} X(0)X(1)X(2)X(k)X(N1)=[WNij]x(0)x(1)x(2)x(k)x(N1)
忽略复数加法,DFT方法需要N2次复数乘法。

基-2DIT-FFT算法(该算法只适用于 N = 2 l N=2^l N=2l的情况)

将N点序列( N = 2 l N=2^l N=2l)分解为奇序列和偶序列两个 N / 2 N/2 N/2序列,分别计算其DFT。
X N ( k ) = ∑ n = 0 N − 1 x ( n ) W N n k      k = 0 , 1 , … , N − 1 = ∑ n=偶整数 x ( n ) W N n k + ∑ n=奇整数 x ( n ) W N n k = ∑ r = 0 ( N / 2 ) − 1 x ( 2 r ) W N 2 r k + ∑ r = 0 ( N / 2 ) − 1 x ( 2 r + 1 ) W N ( 2 r + 1 ) k = ∑ r = 0 ( N / 2 ) − 1 x ( 2 r ) ( W N 2 ) r k + W N k ∑ r = 0 ( N / 2 ) − 1 x ( 2 r + 1 ) ( W N 2 ) r k = ∑ r = 0 ( N / 2 ) − 1 x ( 2 r ) W N / 2 r k + W N k ∑ r = 0 ( N / 2 ) − 1 x ( 2 r + 1 ) W N / 2 r k = G N / 2 ( k ) + W N k H N / 2 ( k ) \begin{aligned}X_N(k) &= \sum_{n=0}^{N-1} x(n)W_N^{nk} \ \ \ \ k=0,1,\dots,N-1 \\&= \sum_{\text{n=偶整数}}x(n)W_N^{nk} + \sum_{\text{n=奇整数}}x(n)W_N^{nk} \\&= \sum_{r=0}^{(N/2)-1}x(2r)W_N^{2rk} + \sum_{r=0}^{(N/2)-1}x(2r+1)W_N^{(2r+1)k} \\&= \sum_{r=0}^{(N/2)-1}x(2r)(W_N^2)^{rk} + W_N^k\sum_{r=0}^{(N/2)-1}x(2r+1)(W_N^2)^{rk} \\&= \sum_{r=0}^{(N/2)-1}x(2r)W_{N/2}^{rk} + W_N^k\sum_{r=0}^{(N/2)-1}x(2r+1)W_{N/2}^{rk} \\&= G_{N/2}(k) + W_N^k H_{N/2}(k) \end{aligned} XN(k)=n=0N1x(n)WNnk    k=0,1,,N1=n=偶整数x(n)WNnk+n=奇整数x(n)WNnk=r=0(N/2)1x(2r)WN2rk+r=0(N/2)1x(2r+1)WN(2r+1)k=r=0(N/2)1x(2r)(WN2)rk+WNkr=0(N/2)1x(2r+1)(WN2)rk=r=0(N/2)1x(2r)WN/2rk+WNkr=0(N/2)1x(2r+1)WN/2rk=GN/2(k)+WNkHN/2(k)

X N ( k + N 2 ) = G N / 2 ( k ) + W N k + N 2 H N / 2 ( k ) = G N / 2 ( k ) − W N k H N / 2 ( k ) \begin{aligned}X_N(k+\frac{N}{2})&= G_{N/2}(k) + W_N^{k+\frac{N}{2}} H_{N/2}(k) \\&= G_{N/2}(k) - W_N^k H_{N/2}(k)\end{aligned} XN(k+2N)=GN/2(k)+WNk+2NHN/2(k)=GN/2(k)WNkHN/2(k)

方便讨论,记N点DFT计算中的DFT矩阵 [ W N i j ] [W_N^{ij}] [WNij] F N F_N FN

F N F_N FN分解,则得到
F N = [ I N / 2 D N / 2 I N / 2 − D N / 2 ] [ F N / 2 O O F N / 2 ] P N F_N = \begin{bmatrix}I_{N/2} & D_{N/2} \\I_{N/2} & -D_{N/2}\end{bmatrix}\begin{bmatrix}F_{N/2} & \Omicron \\\Omicron & F_{N/2}\end{bmatrix}P_N FN=[IN/2IN/2DN/2DN/2][FN/2OOFN/2]PN
其中,
D N / 2 = d i a g [ W N k ]       k = 0 , 1 , … , N 2 − 1 D_{N/2} = diag[W_N^k] \ \ \ \ \ k=0,1,\dots,\frac{N}{2}-1 DN/2=diag[WNk]     k=0,1,,2N1
P N P_N PN为置换矩阵,用于将 x ( n ) x(n) x(n)的奇偶序列分开,举例说明,当 N = 4 N=4 N=4 N = 8 N=8 N=8时, P 4 P_4 P4 P 8 P_8 P8
P 4 = [ 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 ] P_4 = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} P4=1000001001000001

P 8 = [ 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 ] P_8 = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix} P8=1000000000001000010000000000010000100000000000100001000000000001

方便理解,我写出第一次迭代完整过程。
[ X ( 0 ) X ( 1 ) X ( 2 ) ⋮ X ( k ) ⋮ X ( N − 1 ) ] = [ W N i j ] [ x ( 0 ) x ( 1 ) x ( 2 ) ⋮ x ( k ) ⋮ x ( N − 1 ) ] = F N x = [ I N / 2 D N / 2 I N / 2 − D N / 2 ] [ F N / 2 O O F N / 2 ] P N x = [ I N / 2 D N / 2 I N / 2 − D N / 2 ] [ F N / 2 O O F N / 2 ] [ x ( 0 ) x ( 2 ) ⋮ x ( N − 2 ) - - - - - - - x ( 1 ) x ( 3 ) ⋮ x ( N − 1 ) ] = [ I N / 2 D N / 2 I N / 2 − D N / 2 ] [ G N / 2 ( k ) H N / 2 ( k ) ] = [ G N / 2 ( k ) + W N k H N / 2 ( k ) G N / 2 ( k ) − W N k H N / 2 ( k ) ] = [ X N ( k ) X N ( k + N 2 ) ]          k = 0 , 1 , … , N 2 − 1 \begin{aligned}\begin{bmatrix}X(0) \\ X(1) \\ X(2) \\ \vdots \\ X(k) \\ \vdots \\ X(N-1)\end{bmatrix}= [W_N^{ij}]\begin{bmatrix}x(0) \\ x(1) \\ x(2) \\ \vdots \\ x(k) \\ \vdots \\ x(N-1)\end{bmatrix}&= F_Nx \\&= \begin{bmatrix}I_{N/2} & D_{N/2} \\I_{N/2} & -D_{N/2}\end{bmatrix}\begin{bmatrix}F_{N/2} & \Omicron \\\Omicron & F_{N/2}\end{bmatrix}P_N x \\&= \begin{bmatrix}I_{N/2} & D_{N/2} \\I_{N/2} & -D_{N/2}\end{bmatrix}\begin{bmatrix}F_{N/2} & \Omicron \\\Omicron & F_{N/2}\end{bmatrix}\begin{bmatrix}x(0) \\ x(2) \\ \vdots \\ x(N-2) \\ \text{- - - - - - -}\\ x(1) \\ x(3) \\ \vdots \\ x(N-1)\end{bmatrix} \\&=\begin{bmatrix}I_{N/2} & D_{N/2} \\I_{N/2} & -D_{N/2}\end{bmatrix}\begin{bmatrix}G_{N/2}(k) \\ H_{N/2}(k)\end{bmatrix} \\&=\begin{bmatrix}G_{N/2}(k) + W_N^k H_{N/2}(k) \\G_{N/2}(k) - W_N^k H_{N/2}(k)\end{bmatrix} \\&=\begin{bmatrix}X_N(k) \\X_N(k+\frac{N}{2})\end{bmatrix}\ \ \ \ \ \ \ \ k=0,1,\dots,\frac{N}{2}-1\end{aligned} X(0)X(1)X(2)X(k)X(N1)=[WNij]x(0)x(1)x(2)x(k)x(N1)=FNx=[IN/2IN/2DN/2DN/2][FN/2OOFN/2]PNx=[IN/2IN/2DN/2DN/2][FN/2OOFN/2]x(0)x(2)x(N2)- - - - - - -x(1)x(3)x(N1)=[IN/2IN/2DN/2DN/2][GN/2(k)HN/2(k)]=[GN/2(k)+WNkHN/2(k)GN/2(k)WNkHN/2(k)]=[XN(k)XN(k+2N)]        k=0,1,,2N1
F N / 2 F_{N/2} FN/2还能继续分解,直到分解到 F 2 F_2 F2
F 2 = [ 1 1 1 − 1 ] F_2 = \begin{bmatrix} 1 & 1 \\ 1 & -1 \\ \end{bmatrix} F2=[1111]
最终只需 N 2 l o g N \dfrac{N}{2}logN 2NlogN次复数乘法。

function [Xk] = myfft(xn,N)

if(N == 2)
    Xk = [xn(1)+xn(2);xn(1)-xn(2)];
else
    xk_e = myfft(xn(1:2:N-1),N/2);
    xk_o = myfft(xn(2:2:N),N/2);

    WN = exp(-1i*2*pi/N);
    n = 0:1:N/2-1;
    D = (WN*(ones(1,N/2))).^n;
    tmp = (D.') .* xk_o;
    Xk = [xk_e+tmp;xk_e-tmp];
end

IFFT同理,将 D N D_N DN中的元素改为 W N − k W_N^{-k} WNk,并将最后结果乘以 1 N \dfrac{1}{N} N1

function [xn] = myifft(Xk,N)

if(N == 2)
    xn = [Xk(1)+Xk(2);Xk(1)-Xk(2)];
else
    xn_e = myifft(Xk(1:2:N-1),N/2);
    xn_o = myifft(Xk(2:2:N),N/2);

    WN = exp(1i*2*pi/N);
    n = 0:1:N/2-1;
    D = (WN*(ones(1,N/2))).^n;
    tmp = (D.') .* xn_o;
    xn = [xn_e+tmp;xn_e-tmp] / N;
end

你可能感兴趣的:(DSP,线性代数,算法,dsp)