MATLAB中没有DTFT函数,计算机不可能给出连续结果,可以只能利用DFT的fft
函数来实现。
%%
L = 7;
x = ones(1, L)
figure; tiledlayout(2,3,"TileSpacing","tight")
nexttile; stem([0:L-1],x)
box off
title([num2str(L),' points rectangular pulse'])
axis tight
%%
X = fft(x);
nexttile; plot([0:L-1],abs(X),'o-')
box off
title([num2str(L),' points DFT'])
axis tight
%%
N = 256;
X = fft(x, N);
nexttile; plot([0:N-1],abs(X),'.')
title('256 points DFT')
box off
axis tight
%%
nexttile; plot([0:N-1],abs(fftshift(X)),'.')
title('256 points zero-centered DFT')
box off
axis tight
%%
w = 2*pi * (0:(N-1)) / N;
w2 = fftshift(w);
% plot(w2)
w3 = unwrap(w2 - 2*pi);
% plot(w3)
nexttile; plot(w3, abs(fftshift(X)))
axis tight
xlim([-pi, pi])
xticks([-pi:pi:pi])
xticklabels({'-\pi',0,'\pi'})
xlabel('radians')
title('plot DTFT the normalized angular frequency')
box off
%%
nexttile; plot(w3/pi, abs(fftshift(X)))
axis tight
xlim([-1, 1])
xlabel('radians / \pi')
title('plot DTFT using normalized frequency')
box off
附unwarp
函数