您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 数字信号处理实验Matlab代码
%x(n)µÄ[0~6*pi]DTFTclc;clear;xn=[1,1,1,1];N=4;M=1000;w=6*pi/M*[0:M-1];Xejw=dtft(xn,w)plot(w/pi,abs(Xejw));title('R4(n)µÄDTFT²¨ÐÎͼ');xlabel('w/pi');ylabel('·ù¶È');gridon%x(n)X(k)ÓëX(ejw)±È½Ïclc;clear;N1=4;N2=32;xn=[1,1,1,1];k1=(2*pi/N1)*[0:N1-1];k2=(2*pi/N2)*[0:N2-1];xn=[xn,zeros(1,N1-length(xn))];Xk=dft(xn,N1);%x(n)µÄ4µãDFTsubplot(221);stem(k1/pi,abs(Xk));title('X(k)n=4µãDFT');xlabel('w/pi');ylabel('·ù¶È');gridonM=1000;w=2*pi/M*[0:M-1];Xejw=dtft(xn,w);%x(n)µÄ4µãDTFTsubplot(222);plot(w/pi,abs(Xejw));title('X(ejw)n=4DTFT');xlabel('w/pi');ylabel('·ù¶È');gridonxn=[xn,zeros(1,N2-length(xn))];Xk1=dft(xn,N2);%x(n)µÄ32µãDFTsubplot(223);stem(k2/pi,abs(Xk1));title('X1(k)n=32µã²¹ÁãºóDFT');xlabel('w/pi');ylabel('·ù¶È');gridonXejw1=dtft(xn,w);%x(n)µÄ32µãDTFTsubplot(224);plot(w/pi,abs(Xejw1));title('X1(ejw)n=32²¹ÁãºóDTFT');xlabel('w/pi');ylabel('·ù¶È');gridonclc,clear;%%%%%%%%%xtÐźÅt=-0.5:0.001:0.5;f1=5;f2=30;N=64;%²ÉÑùµãÊýFs=64;%²ÉÑùƵÂÊTs=1/Fs;figure(1);subplot(221);xt=sin(2*pi*f1*t)+0.5*cos(2*pi*f2*t);plot(t,xt);title('xtµÄʱÓò²¨ÐÎͼ');xlabel('t');ylabel('xt');gridon%%%%%%%%xtƵÆ×ÐźÅF=Fs/N;%²ÉÑù·Ö±æÂÊTp=1/F;%¹Û²ìʱ¼ät=0:Ts:Tp-Ts;xt=sin(2*pi*f1*t)+0.5*cos(2*pi*f2*t);k=0:N-1;wk=2*pi/N*k;%k¶ÔÓ¦µÄÊý×ÖƵÂÊXk=fft(xt,N);Xk=Ts*Xk;subplot(222);stem(wk/pi,abs(Xk)/max(abs(Xk)));%Ϊ±ÜÃâ·ù¶ÈÖµËæ±ä»»Çø¼äN±ä»¯µÄȱµã£¬»Í¼Ê±¿É¹éÒ»»¯·ù¶ÈÆס£title('xtµÄƵÆ×ͼ');xlabel('wk/pi');ylabel('Xk');gridon%%%%%%%%µÍͨÊý×ÖÂ˲¨Æ÷ËðºÄº¯Êýwpz=0.2;%ͨ¡¢×è´ø½ØֹƵÂÊwsz=0.3;wp=2/Ts*tan(wpz*pi/2);%±ß½çƵÂÊת»»¹Øϵws=2/Ts*tan(wsz*pi/2);rp=1;%ͨ¡¢×è´øË¥¼õrs=15;[N,wc]=buttord(wp,ws,rp,rs,'s');%µ÷Óú¯ÊýÖ±½ÓÉæ¼°Êý×ÖÂ˲¨Æ÷[B,A]=butter(N,wc,'s');[Bz,Az]=bilinear(B,A,Fs);[H,w]=freqz(Bz,Az,N);subplot(223);plot(w/pi,20*log10(abs(H)/max(abs(H))));%DFËðºÄº¯ÊýµÄ»æÖÆ¡£title('µÍͨÊý×ÖÂ˲¨Æ÷ËðºÄº¯Êý');xlabel('w/pi');ylabel('·ù¶È/dB');gridon;%%%%%%%%xtÂ˲¨Ê±Óòͼsubplot(224);yt=filter(Bz,Az,xt);plot(t,yt);title('xtÂ˲¨ºó²¨ÐÎͼ');xlabel('t');ylabel('yt');gridonclc,clear%%%%%%%%%FDMÐźÅf1=30;f2=60;f3=120;F1=300;F2=600;F3=1200;Fs=4096;Ts=1/Fs;N=2048;t=0:Ts:(N-1)*Ts;st1=cos(2*pi*f1*t).*cos(2*pi*F1*t);st2=cos(2*pi*f2*t).*cos(2*pi*F2*t);st3=cos(2*pi*f3*t).*cos(2*pi*F3*t);st=st1+st2+st3;figure(1)subplot(2,1,1);plot(t,st);title('FDM¸´ÓÃÐźÅʱÓò²¨ÐÎͼ');gridon%%%%%%%%stƵÆ×ÐźÅF=Fs/N;%²ÉÑù·Ö±æÂÊTp=1/F;%¹Û²ìʱ¼ät=0:Ts:Tp-Ts;k=0:N-1;wk=2*pi/N*k;%k¶ÔÓ¦µÄÊý×ÖƵÂÊSk=fft(st,N);Sk=Ts*Sk;subplot(212);stem(wk/pi,abs(Sk)/max(abs(Sk)));%Ϊ±ÜÃâ·ù¶ÈÖµËæ±ä»»Çø¼äN±ä»¯µÄȱµã£¬»Í¼Ê±¿É¹éÒ»»¯·ù¶ÈÆס£title('stµÄƵÆ×ͼ');xlabel('wk/pi');ylabel('Sk');gridon%%%%%%%Â˲¨Æ÷½â¸´ÓÃWp1=340*2*pi;Ws1=350*2*pi;Rp1=0.1;Rs1=60;Wp21=450*2*pi;Wp22=800*2*pi;Ws21=400*2*pi;Ws22=810*2*pi;Wp3=1070*2*pi;Ws3=1050*2*pi;Wp2=[Wp21,Wp22];Ws2=[Ws21,Ws22];[N1,wp1]=ellipord(Wp1/(Fs*pi),Ws1/(Fs*pi),Rp1,Rs1);[N2,wp2]=ellipord(Wp2/(Fs*pi),Ws2/(Fs*pi),Rp1,Rs1);[N3,wp3]=ellipord(Wp3/(Fs*pi),Ws3/(Fs*pi),Rp1,Rs1);[Bz1,Az1]=ellip(N1,Rp1,Rs1,wp1);%µÍͨ[Bz2,Az2]=ellip(N2,Rp1,Rs1,wp2);%´øͨ[Bz3,Az3]=ellip(N3,Rp1,Rs1,wp3,'high');%¸ßͨfigure(2);yt1=filter(Bz1,Az1,st);yt2=filter(Bz2,Az2,st);yt3=filter(Bz3,Az3,st);subplot(3,1,1);plot(t,yt1);title('µÍͨÂ˲¨²¨ÐÎ');gridon;subplot(3,1,2);plot(t,yt2);title('´øͨÂ˲¨²¨ÐÎ');gridon;subplot(3,1,3);plot(t,yt3);title('¸ßͨÂ˲¨²¨ÐÎ');gridon;%%%%%%%%%%%%ËðºÄº¯Êýfigure(3)subplot(3,1,1)[H1,w1]=freqz(Bz1,Az1,N1);plot(w1/pi,20*log10(abs(H1)/max(abs(H1))));title('µÍͨÂ˲¨Æ÷µÄËðºÄº¯Êý');xlabel('w/pi');ylabel('·ù¶È/dB');gridonsubplot(3,1,2)[H2,w2]=freqz(Bz2,Az2,N2);plot(w2/pi,20*log10(abs(H2)/max(abs(H2))));title('´øͨÂ˲¨Æ÷µÄËðºÄº¯Êý');xlabel('w/pi');ylabel('·ù¶È/dB');axis([0.2,0.5,-100,2]);gridonsubplot(3,1,3)[H3,w3]=freqz(Bz3,Az3,N3);plot(w3/pi,20*log10(abs(H3)/max(abs(H3))));title('¸ßͨÂ˲¨Æ÷µÄËðºÄº¯Êý');xlabel('w/pi');ylabel('·ù¶È/dB');gridonclc,clear;N=4;M=4;L=N+M;n=0:L-1;xn=[1/2,1,1,1/2];xn=[xn,zeros(1,(L-M))];Xk=fft(xn,L);Yk=Xk.*Xk;ycn=ifft(Yk,L);stem(n,ycn);title('ÏßÐÔ¾í»ýycn');xlabel('n');ylabel('ycn');gridon;clc;clear;Fs=64;%²ÉÑùµãÊýN1=16;N2=32;N3=64;%²ÉÑù¼ä¸ô¼´·Ö±æÂÊFF1=Fs/N1;F2=Fs/N2;F3=Fs/N3;f1=0:F1:(N1-1)*F1;f2=0:F2:(N2-1)*F2;f3=0:F3:(N3-1)*F3;Ts=1/Fs;%¹Û²ìʱ¼äTp1=1/F1;Tp2=1/F2;Tp3=1/F3;t1=0:Ts:Tp1;t2=0:Ts:Tp2;t3=0:Ts:Tp3;xn1=cos(8*pi*t1)+cos(16*pi*t1)+cos(20*pi*t1);Xk1=fft(xn1,N1);xn2=cos(8*pi*t2)+cos(16*pi*t2)+cos(20*pi*t2);Xk2=fft(xn2,N2);xn3=cos(8*pi*t3)+cos(16*pi*t3)+cos(20*pi*t3);Xk3=fft(xn3,N3);XaKF1=Ts*Xk1;XaKF2=Ts*Xk2;XaKF3=Ts*Xk3;subplot(311);stem(f1,abs(XaKF1)/max(abs(XaKF1)));title('N=16,Tp=0.5¸öÖÜÆÚF=4');xlabel('f/hz');ylabel('·ù¶È');subplot(312);stem(f2,abs(XaKF2)/max(abs(XaKF2)));title('N=32,Tp=1¸öÖÜÆÚF=2');xlabel('f/hz');ylabel('·ù¶È');subplot(313);stem(f3,abs(XaKF3)/max(abs(XaKF3)));title('N=64,Tp=2¸öÖÜÆÚF=1')xlabel('f/hz');ylabel('·ù¶È');clc;clear;Fs=64;%²ÉÑùµãÊýN1=16;N2=32;N3=64;%²ÉÑù¼ä¸ô¼´·Ö±æÂÊFF1=Fs/N1;F2=Fs/N2;F3=Fs/N3;%²ÉÑùƵÂÊÀëÉ¢»¯f1=0:F1:(N1-1)*F1;f2=0:F2:(N2-1)*F2;f3=0:F3:(N3-1)*F3;Ts=1/Fs;%¹Û²ìʱ¼äTp1=1/F1;Tp2=1/F2;Tp3=1/F3;%²ÉÑùʱ¼äÀëÉ¢»¯t1=0:Ts:Tp1;t2=0:Ts:Tp2;t3=0:Ts:Tp3;xn1=cos(8*pi*t1)+cos(16*pi*t1)+cos(20*pi*t1);Xk1=fft(xn1,N1);xn2=cos(8*pi*t2)+cos(16*pi*t2)+c
本文标题:数字信号处理实验Matlab代码
链接地址:https://www.777doc.com/doc-5072738 .html