实验二离散时间系统的时域分析实验室名称: 实验时间:六、实验记录(数据、图表、波形、程序等)Q2、1 程序代码:%产生输入信号n = 0:100;s1 = cos(2*pi*0、05*n); %一个低频正弦s2 = cos(2*pi*0、47*n); %一个高频正弦x = s1+s2;%滑动平均滤波器的实现M = input('Desired length of the filter = ');num = ones(1,M);y = filter(num,1,x)/M;clf;%显示输入与输出信号subplot(2,2,1);plot(n, s1);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Signal #1');subplot(2,2,2);plot(n, s2);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Signal #2');subplot(2,2,3);plot(n, x);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Input Signal');subplot(2,2,4);plot(n, y);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Output Signal'); axis;显示结果:Q2、2 代码(将输出信号的代码做出修改,其余代码与Q2、1相同): n=0:100;s1=cos(2*pi*0、05*n);s2=cos(2*pi*0、47*n);x=s1+s2;M=input(' Desired length of the filter = ');num=(-1)、^[0:M-1];y=filter(num,1,x)/M;clf;%显示输入与输出信号subplot(2,2,1);plot(n, s1);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Signal #1');subplot(2,2,2);plot(n, s2);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Signal #2');subplot(2,2,3);plot(n, x);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Input Signal');subplot(2,2,4);plot(n, y);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Output Signal');axis;显示结果:Q2、4 程序代码:%构造长度为101、最低频率为0、最高频率为0、5的扫频正弦信号n = 0:100;a = pi/2/100;b = 0;arg = a*n、*n + b*n;x = cos(arg);M = input('Desired length of the filter = ');num = ones(1,M);y = filter(num,1,x)/M;clf;subplot(2,1,1);plot(n,x);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('扫频正弦信号');subplot(2,1,2);plot(n, y);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('滤波后的输出信号');显示结果:Q2、7 程序代码:% 生成输入序列clf;n = 0:40;a = 2;b = -3;x1 = cos(2*pi*0、1*n);x2 = cos(2*pi*0、4*n);x = a*x1 + b*x2;num = [2、2403 2、4908 2、2403];den = [1 -0、4 0、75];ic = [0 0]; % 设置零初始条件y1 = filter(num,den,x1,ic); % 计算输出 y1[n]y2 = filter(num,den,x2,ic); % 计算输出 y2[n]y = filter(num,den,x,ic); %计算输出 y[n]yt = a*y1 + b*y2;d = y - yt; % 计算差值输出 d[n]% 画出输出与差信号subplot(3,1,1)stem(n,y);ylabel('振幅');title('加权输入: a \cdot x_{1}[n] + b \cdot x_{2}[n]的输出'); subplot(3,1,2)stem(n,yt);ylabel('振幅');title('加权输出: a \cdot y_{1}[n] + b \cdot y_{2}[n]'); subplot(3,1,3)stem(n,d);xlabel('时间序号');ylabel('振幅');title('差信号');显示结果:Q2、12 程序代码:% 生成输入序列clf;n = 0:40; D = 10;a = 3、0;b = -2;x = a*cos(2*pi*0、1*n) + b*cos(2*pi*0、4*n);xd = [zeros(1,D) x];num = [2、2403 2、4908 2、2403];den = [1 -0、4 0、75];ic = [0 0]; % 设置初始条件% 计算输出 y[n]y = filter(num,den,x,ic);% 计算输出 yd[n]yd = filter(num,den,xd,ic);% 计算差值输出 d[n]d = y - yd(1+D:41+D);% 画出输出subplot(3,1,1)stem(n,y);ylabel('振幅');title('输出 y[n]');grid;subplot(3,1,2)stem(n,yd(1:41));ylabel('振幅');title(['由于延时输入 x[n ', num2str(D),']的输出']); grid;subplot(3,1,3)stem(n,d);xlabel('时间序列n');ylabel('振幅');title('差值信号');grid;显示结果:Q2、19 程序代码:clf;N = 40;num = [2、2403 2、4908 2、2403];den = [1 -0、4 0、75];y = impz(num,den,N);% 画出冲击响应stem(y);xlabel('时间序号');ylabel('振幅');title('冲击响应');grid;显示结果:Q2、20 程序代码:clf;N = 40;num = [0、9 -0、45 0、35 0、002]; den = [1 0、71 -0、46 -0、62];y = impz(num,den,N);% 画出冲击响应stem(y);xlabel('时间序号');ylabel('振幅');title('冲击响应');grid;序列u[n]显示结果:Q2、23 程序代码:%级联实现clf;x=[1 zeros(1,40)];%生成输入n=0:40;%四阶系统的系数den=[1 1、6 2、28 1、325 0、68];num=[0、06 -0、19 0、27 -0、26 0、12]; %计算四阶系统的输出y=filter(num,den,x);%两个二阶系统的系数num1=[0、3 -0、2 0、4];den1=[1 0、9 0、8];num2=[0、2 -0、5 0、3];den2=[1 0、7 0、85];%级联第一级的输出y1[n]y1=filter(num1,den1,x);%级联第二级的输出y2[n]y2=filter(num2,den2,y1);%y与y2[n]之间的差d=y-y2;%画出输出与差值信号subplot(3,1,1);stem(n,y);ylabel('振幅');title('四阶实现的输出'); grid;subplot(3,1,2);stem(n,y2);ylabel('振幅');title('级联实现的输出'); grid;subplot(3,1,3);stem(n,d);xlabel('时间序号 n');ylabel('振幅');title('差值信号');grid;显示结果:Q2、23 程序代码:clf;h=[3 2 1 -2 1 0 -4 0 3];%冲激x=[1 -2 3 -4 3 2 1];%输入序列y=conv(h,x);n=0:14;subplot(2,1,1);stem(n,y);xlabel('时间序号n');ylabel('振幅');title('用卷积得到的输出');grid;x1=[x zeros(1,8)];y1=filter(h,1,x1);subplot(2,1,2);stem(n,y1);xlabel('时间序号n');ylabel('振幅');title('用滤波器生成的输出');grid;显示结果:七、实验思考题及解答Q2、1 输入的那个分量被该离散时间系统抑制。