您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 演示增采样和减采样信号的频谱
演示增采样、减采样的MATLAB程序(读者原封不动拷贝成MATLAB程序,加快即可`运行)%演示增采样、减采样的过程,给出信号及其频谱。%h_fig1=figure;set(h_fig1,'unit','normalized','position',[0.0,0.0,0.99,0.94]);set(h_fig1,'defaultuicontrolunits','normalized');h_text1=uicontrol(gcf,'Style','text','Position',[0.22,0.89,0.62,0.07],...'String','演示信号的增采样与减采样','FontName','黑体','ForegroundColor','r',...'FontSize',32,'FontWeight','Bold','BackgroundColor',[1,1,1]);set(gcf,'color','w')h_pushbutton1=uicontrol(h_fig1,'Style','PushButton','Position',[0.8,0.9,0.08,0.07],...'string','往下页','BackgroundColor','y','ForegroundColor','r','FontSize',14,'FontWeight','Bold',...'callback',['set(h_fig1,''visible'',''off''),',...'set(h_fig2,''visible'',''on'')'])h_pushbutton2=uicontrol(h_fig1,'Style','PushButton','Position',[0.9,0.9,0.08,0.07],...'string','退出','BackgroundColor',[0.80.90.8],'ForegroundColor','r','FontSize',14,'FontWeight','Bold',...'callback',['delete(h_fig1),','delete(h_fig2)'])h_axes01=axes('Box','on','Position',[0.07,0.17,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes02=axes('Box','on','Position',[0.4,0.17,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes03=axes('Box','on','Position',[0.72,0.17,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes04=axes('Box','on','Position',[0.07,0.52,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes05=axes('Box','on','Position',[0.4,0.52,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes06=axes('Box','on','Position',[0.72,0.520.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_fig2=figureset(h_fig2,'unit','normalized','position',[0.0,0.0,0.99,0.94]);set(h_fig2,'defaultuicontrolunits','normalized');h_text2=uicontrol(h_fig2,'Style','text','Position',[0.22,0.92,0.62,0.07],...'String','演示信号的增采样与减采样','FontName','黑体','ForegroundColor','r',...'FontSize',28,'FontWeight','Bold','BackgroundColor',[1,1,1]);set(gcf,'color','w')h_pushbutton3=uicontrol(h_fig2,'Style','PushButton','Position',[0.8,0.92,0.08,0.07],...'string','往前页','BackgroundColor','y','ForegroundColor','r','FontSize',14,'FontWeight','Bold',...'callback',['set(h_fig2,''visible'',''off''),',...'set(h_fig1,''visible'',''on'')'])h_pushbutton4=uicontrol(h_fig2,'Style','PushButton','Position',[0.9,0.92,0.08,0.07],...'string','退出','BackgroundColor',[0.80.90.8],'ForegroundColor','r','FontSize',14,'FontWeight','Bold',...'callback',['delete(h_fig1),','delete(h_fig2)'])set(gcf,'color','w')h_axes1=axes('Box','on','Position',[0.07,0.07,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes2=axes('Box','on','Position',[0.4,0.07,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes3=axes('Box','on','Position',[0.72,0.07,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes4=axes('Box','on','Position',[0.07,0.37,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes5=axes('Box','on','Position',[0.4,0.37,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes6=axes('Box','on','Position',[0.72,0.370.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes7=axes('Box','on','Position',[0.07,0.67,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes8=axes('Box','on','Position',[0.4,0.67,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象h_axes9=axes('Box','on','Position',[0.72,0.67,0.25,0.2],'FontSize',8)%在第2个图形窗中创建轴对象set(0,'CurrentFigure',h_fig1);%----------------------------------------------------%产生复合正弦序列x(n)n1=0:15;x=sin(pi*n1/8)+2*sin(pi*n1*2/8);w=[0:1:500]*2*pi/500;%求一个复合正弦序列x(n)的DTFTX=x*exp(-j*n1'*w);magX=abs(X);%通过FFT求周期(16点)的复合正弦序列x(n)的DFTk=0:15;Xk=fft(x,16);magXk=abs(Xk(1:1:16));%显示复合正弦序列x(n)subplot(h_axes04)H=stem(n1,x);grid;set(H,'markersize',2);line([016],[00]);axis([0,15,-3.1,3.1]);xlabel('n','FontSize',12);ylabel('x(n)','FontSize',12);title('(1)给定的复合正弦序列','FontSize',12);set(h_axes04,'LineWidth',2)%----------------------------------------------------%显示复合正弦序列x(n)的DTFT模值subplot(h_axes05)plot(w/pi,magX,'b');grid;set(gca,'XTickMode','manual','XTick',[0,0.125,0.5,1,1.5,1.875,2]);xlabel('w/\pi','FontSize',12);ylabel('|X(exp(jw))|','FontSize',12);title('(2)x(n)的DTFT模值','FontSize',12);%显示复合正弦序列x(n)的DFTsubplot(h_axes06)H=stem(k,magXk,'b');grid;set(H,'markersize',2);xlabel('k','FontSize',12);ylabel('|X(k)|','FontSize',12');title('(3)x(n)的DFT模值','FontSize',12);axis([0,16,0,20]);set(h_axes05,'LineWidth',2)%----------------------------------------------------%在序列x(n)的每两个样点之间插入两个零值样点,得扩张序列w(n)x1=[100];w1=x1'*x;w=(w1(:)');subplot(h_axes01)%显示w(n)H=stem(w,'b');grid;set(H,'markersize',2);axis([0,48,-4.1,4.1]);line([048],[00]);text(25,3,'U=3','FontWeight','Bold');xlabel('n','FontSize',12);ylabel('w(n)','FontSize',12);title('(4)x(n)的样点之间补两个零值样点','FontSize',12);%求w(n)的DTFTm=length(w);n2=0:m-1;w2=[0:1:500]*2*pi/500;W=w*exp(-j*n2'*w2);magW=abs(W);%通过FFT求w(n)的DFTk1=0:47;Wk=fft(w);magWk=abs(Wk(1:1:48));%显示w(n)的DTFTsubplot(h_axes02)plot(w2/pi,magW,'b');grid;xlabel('w/\pi','FontSize',12);ylabel('|W(exp(jw))|','FontSize',12);title('(5)w(n)的DTFT','FontSize',12);set(h_axes02,'LineWidth',2)%显示w(n)的DFTsubplot(h_axes03)H=stem(k1,magWk,'b');grid;set(H,'markersize',2);axis([0,48,0,20]);xlabel('k','FontSize',12);ylabel('|W(k)|','FontSize',12);title('(6)w(n)的DFT','FontSize',12);set(h_axes01,'LineWidth',2)%----------------------------------------------------set(0,'Cur
本文标题:演示增采样和减采样信号的频谱
链接地址:https://www.777doc.com/doc-4695250 .html