📄 dft.m
字号:
%M-file function,DFT.m
clear all
clf
j=sqrt(-1);
f1=2; f2=2.5; f3=3;
fs=10;
w1=2*pi*f1/fs; w2=2*pi*f2/fs; w3=2*pi*f3/fs;
L1=20; L2=100; L=800;
N1=32; N2=64; N3=40;N4=20; N=800;
n=0:L1-1;
x=cos(w1*n)+cos(w2*n)+cos(w3*n);
vct_w1=0: 2*pi/N1: 2*pi-2*pi/N1;
vct_w2=0: 2*pi/N2: 2*pi-2*pi/N2;
vct_w3=0: 2*pi/N3: 2*pi-2*pi/N3;
vct_w4=0: 2*pi/N4: 2*pi-2*pi/N4;
vct_w =0: 2*pi/N: 2*pi-2*pi/N;
X1=dtft(x,vct_w1); %DFT
X2=dtft(x,vct_w2);
X3=dtft(x,vct_w3);
X4=dtft(x,vct_w4);
X =dtft(x,vct_w);
subplot(4,1,1)
axis([0 fs 0 16])
hold on
bar ((0:N1-1)/N1*fs,abs(X1),0)
plot((0:N1-1)/N1*fs,abs(X1),'r*')
plot(fs*vct_w/pi/2,abs(X),'g:')
xlabel('f in units kHz')
legend('DFT, L=20 N=32','DTFT',0)
ylabel('Magnitude Spectra')
subplot(4,1,2)
axis([0 fs 0 16])
hold on
bar ((0:N2-1)/N2*fs,abs(X2),0)
plot((0:N2-1)/N2*fs,abs(X2),'b*')
plot(fs*vct_w/pi/2,abs(X),'r:')
xlabel('f in units kHz')
legend('DFT, L=20 N=64','DTFT',0)
ylabel('Magnitude Spectra')
subplot(4,1,3)
axis([0 fs 0 16])
hold on
bar ((0:N3-1)/N3*fs,abs(X3),0)
plot((0:N3-1)/N3*fs,abs(X3),'b*')
plot(fs*vct_w/pi/2,abs(X),'b:')
xlabel('f in units kHz')
legend('DFT, L=20 N=40','DTFT',0)
ylabel('Magnitude Spectra')
subplot(4,1,4)
axis([0 fs 0 16])
hold on
bar ((0:N4-1)/N4*fs,abs(X4),0)
plot((0:N4-1)/N4*fs,abs(X4),'b*')
plot(fs*vct_w/pi/2,abs(X),'b:')
xlabel('f in units kHz')
legend('DFT, L=20 N=20','DTFT',0)
ylabel('Magnitude Spectra')
pause
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -