离散时间傅里叶变换和离散傅里叶变换
{ X ( k ) = DFT [ x ( n ) ] = ∑ n = 0 N − 1 x ( n ) W N n k k = 0 , 1 , . . . , N − 1 x ( n ) = IDFT [ X ( k ) ] = 1 N ∑ n = 0 N − 1 x ( n ) W N − n k n = 0 , 1 , . . . , N − 1 \begin{cases} X(k)=\textbf{DFT}[x(n)]=\sum\limits_{n=0}^{N-1}x(n)W_N^{nk}\quad k=0,1,...,N-1 \\ x(n)=\textbf{IDFT}[X(k)]=\frac{1}{N}\sum\limits_{n=0}^{N-1}x(n)W_N^{-nk}\quad n=0,1,...,N-1 \end{cases} ⎩ ⎨ ⎧X(k)=DFT[x(n)]=n=0∑N−1x(n)WNnkk=0,1,...,N−1x(n)=IDFT[X(k)]=N1n=0∑N−1x(n)WN−nkn=0,1,...,N−1
{ X ( e j ω ) = DTFT [ x ( n ) ] = ∑ n = − ∞ ∞ x ( n ) e − j ω n k = 0 , 1 , . . . , N − 1 x ( n ) = IDTFT [ X ( e j ω ) ] = 1 2 π ∫ − π π X ( e j ω ) e j ω n d ω \begin{cases} X(e^{j\omega})=\textbf{DTFT}[x(n)]=\sum\limits_{n=-\infty}^{\infty}x(n)e^{-j\omega n}\quad k=0,1,...,N-1 \\ x(n)=\textbf{IDTFT}[X(e^{j\omega})]=\frac{1}{2\pi}\int_{-\pi}^{\pi}X(e^{j\omega})e^{j\omega n}d\omega \end{cases} ⎩ ⎨ ⎧X(ejω)=DTFT[x(n)]=n=−∞∑∞x(n)e−jωnk=0,1,...,N−1x(n)=IDTFT[X(ejω)]=2π1∫−ππX(ejω)ejωndω
自定义dtft()
function [w,X] = dtft(x)
% DTFT变换
N = length(x);
n = 0:N-1;
w = linspace(-2*pi,2*pi,500); %将[-2pi,2pi]分割成500份
X = x * exp(-1j*n'*w);
end
自定义dft()
function X = dft(xn)
% 计算离散傅立叶变换(DFT)
N = length(xn); % 获取序列长度
n = 0:N-1; % 时间序列
X = zeros(1, N); % 初始化频域序列
for k = 0:N-1
X(k+1) = sum(xn .* exp(-1i*2*pi*k*n/N)); % 计算DFT的每个频率分量
end
end
例子:
% DTFT
clear;
xn = [0 1 2 3 4 5 6 7];
[w,X] = dtft(xn);
N = length(xn);
n = 0:N-1;
figure('Color','w');
subplot(2 ,2 ,[1,2])
stem(xn,"filled");
subplot(223)
plot(w,abs(X));
subplot(224)
plot(w,angle(X));
% DFT
clear;
xn = [0 1 2 3 4 5 6 7 zeros(1,92)];
X = dft(xn);
N = length(xn);
n = 0:N-1;
figure('Color','w');
subplot(2 ,2 ,[1,2])
stem(xn,"filled");
subplot(223)
stem(abs(X),'filled');
subplot(224)
stem(angle(X),'filled');