1、数字信号处理实验2实验2离散时间系统的时域表示2.1模拟的离散时间系统p2_1代码如下: % Program P2_1 % Simulation of an M-point Moving Average Filter% Generate the input signaln = 0:100;s1 = cos(2*pi*0.05*n); % A low-frequency sinusoids2 = cos(2*pi*0.47*n); % A high frequency sinusoidx = s1+s2;% Implementation of the moving average filterM
2、 = input(Desired length of the filter = );num = ones(1,M);y = filter(num,1,x)/M;% Display the input and output signalsclf;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); ylabe
3、l(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.1 令M=2,运行上述程序,生成输出信号。输入x【n】的哪个分量被离散时间系统控制:频率
4、Q2.2 线性时不变系统改为 yn = 0.5(xnxn1) 对 xn = s1n+s2n 的影响: 造成的结果是 - 该系统现在是一个高通滤波器。它通过高频率的输入分量S2,而不是低频分量输入S1。Q2.3 程序p2_1运行以下值滤波器长度m和以下的正弦信号S1n和S2 n的频率频率值。输出产生这些不同的m值和频率如下所示。从这些图中我们提出以下意见 f1=0.05; f2=0.47; M=15Q2.4 修改程序p2_1通过改变输入序列的扫频正弦信号(长度为101,最小频率为0,和最大频率0.5)作为输入信号(见程序p1_7)如下: % Program P1_7% Generation of
5、 a swept frequency sinusoidal sequencen = 0:100;a = pi/2/100;b = 0;arg = a*n.*n + b*n;x = cos(arg);% Program P2_1% Simulation of an M-point Moving Average Filter% Generate the input signal % Implementation of the moving average filterM = input(Desired length of the filter = );num = ones(1,M);y = fil
6、ter(num,1,x)/M;% Display the input and output signalsclf;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, 1
7、00, -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; The output signal generated by running this program is plotted below. The从这个系统的扫频信号的响应问题q2.1和q2.2结果可以解释如下: 我们又看到,该系
8、统是一个低通滤波器。在图中的左,其输入是一个低频率的正弦曲线,通过对输出无衰减。作为nincreases,输入的频率上升,增加的衰减是出现在输出。在q2.1,输入的是一个两个正弦曲线的总和s1and s2with F1 = 0.05and F2 = 0.47。扫频输入q2.4达到在n = 10的频率为0.05,那里几乎没有衰减输出所示。这种“解释“为什么s1was通过系统q2.1。扫频输入q2.4大约在n = 94的频率达到0.47,其中的衰减系统的充实。这种“解释“为什么s2was几乎完全抑制在输出中q2.1。没有直接的关系,结果表明上述q2.4和取得的结果有q2.2。然而,使用频率域的概念
9、(3章)我们可以推测,如果扫频信号输入到系统的 = 0.5(x的 1 X),我们会看到什么是如上所示相反的结果。由于该系统将是一个高通滤波器,将有大量的输出衰减在图表的左边,几乎没有衰减在图表的右侧。这种“解释“为什么inq2.2低频分量s1was抑制系统的输出,而高频分量s2was过去了。Project 2.3 线性和非线性系统P2_3 代码如下:% Program P2_3% Generate the input sequencesclf;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
10、*x2;num = 2.2403 2.4908 2.2403;den = 1 -0.4 0.75;ic = 0 0; % Set zero initial conditionsy1 = filter(num,den,x1,ic); % Compute the output y1ny2 = filter(num,den,x2,ic); % Compute the output y2ny = filter(num,den,x,ic); % Compute the output ynyt = a*y1 + b*y2; d = y - yt; % Compute the difference outp
11、ut dn% Plot the outputs and the difference signalsubplot(3,1,1)stem(n,y);ylabel(Amplitude);title(Output Due to Weighted Input: a cdot x_1n + b cdot x_2n);subplot(3,1,2)stem(n,yt);ylabel(Amplitude);title(Weighted Output: a cdot y_1n + b cdot y_2n);subplot(3,1,3)stem(n,d);xlabel(Time index n);ylabel(A
12、mplitude);title(Difference Signal);Answers:Q2.7 输出Y N,加权得到的输入,和YT N,OB获得由两个输出Y1和Y2的 具有相同的权重相结合,如下图所示随着两个信号之间的差异: 这两个序列 相同的数值舍入 系统是 线性的Q2.8 用三中不同的权系数以及三中不同的输入频率重做习题2.71. a=1; b=-1; f1=0.05; f2=0.4; 2. a=10; b=2; f1=0.10; f2=0.25; 3. a=2; b=10; f1=0.15; f2=0.20; 根据图片得出系统是 线性的Q2.9 改变2_3的初始条件 - ic = 5 1
13、0;图像如下 - 我们可以得到非零初始条件的系统是 非线性Q2.10 当初始条件非零时重做习题2.81. a=1; b=-1; f1=0.05; f2=0.4; 2. a=10; b=2; f1=0.10; f2=0.25; 3. a=2; b=10; f1=0.15; f2=0.20; 根据图像可以得出非零初始条件的系统是 非线性Q2.11 将2_3的系统改为: yn = xnxn1 输出序列y1n, y2n,和yn 的图像如下: 比较 yn 和ytn我们可以得到两个序列是 不一样的 系统是 非线性Project 2.4 Time-invariant and Time-varying Sys
14、tems A copy of Program P2_4 is given below: % Program P2_4% Generate the input sequencesclf;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; % Set initial conditions% Compute the output yny = filter(num
15、,den,x,ic);% Compute the output ydnyd = filter(num,den,xd,ic);% Compute the difference output dnd = y - yd(1+D:41+D);% Plot the outputssubplot(3,1,1)stem(n,y);ylabel(Amplitude); title(Output yn); grid;subplot(3,1,2)stem(n,yd(1:41);ylabel(Amplitude);title(Output due to Delayed Input xn ?, num2str(D),
16、); grid;subplot(3,1,3)stem(n,d);xlabel(Time index n); ylabel(Amplitude);title(Difference Signal); grid;Answers:Q2.12 The output sequences yn and ydn-10 generated by running Program P2_4 are shown below - These two sequences are related as follows - yn-10 = ydn 系统是 时不变的Q2.13采用不同的延时变量重做习题2.12 D=2 D=4D
17、=8 得到两个序列的关系是 - yn-D = ydn 系统是 时不变Q2.14 采用3种不同的输入频率重做习题2.121. f1=0.05; f2=0.40; 2.f1=0.10; f2=0.25;3. f1=0.15; f2=0.20; 我们可以得到两个序列- ydn不是经过yn经过以为得到的 系统是 时不变Q2.15 在非零的初始条件下重做习题2.14。 系统是 非时变Q2.16 在非零的初始条件下重做2.141. f1=0.05; f2=0.40; 2.f1=0.10; f2=0.25;3.f1=0.15; f2=0.20; 这两个序列的关系是- ydn不是经过yn经过以为得到的系统是
18、非时变Q2.17 将2_4的系统改成: yn = n xn + xn-1 源代码为: % Modification of P2_4 to implement the system% given by (2.16).% Generate the input sequencesclf;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;nd = 0:length(xd)-1;% Compute the output yny = (n .* x) + 0 x(1:40)
19、;% Compute the output ydnyd = (nd .* xd) + 0 xd(1:length(xd)-1);% Compute the difference output dnd = y - yd(1+D:41+D);% Plot the outputssubplot(3,1,1)stem(n,y);ylabel(Amplitude); title(Output yn); grid;subplot(3,1,2)stem(n,yd(1:41);ylabel(Amplitude);title(Output due to Delayed Input xn -, num2str(D
20、),); grid;subplot(3,1,3)stem(n,d);xlabel(Time index n); ylabel(Amplitude);title(Difference Signal); grid; 输出序列yn and ydn-10 根据 P2_4 改编之后得到: These two sequences are related as follows - 2.2 线性离散时间系统项目 2.5 系统的脉冲响应计算 P2_5的源代码: % Program P2_5% Compute the impulse response yclf;N = 40;num = 2.2403 2.4908
21、 2.2403;den = 1 -0.4 0.75;y = impz(num,den,N);% Plot the impulse responsestem(y);xlabel(Time index n); ylabel(Amplitude);title(Impulse Response); grid;Answers:Q2.19 运行2.5得到的图像:Q2.20 修改P2_5的程序产生因果线性时不变系统的冲击响应的前45个样本: yn + 0.71yn-1 0.46yn-2 0.62yn-3 = 0.9xn 0.45xn-1 + 0.35xn-2 + 0.002xn-3 clf;N = 45;n
22、um = 0.9 -0.45 0.35 0.002; den = 1.0 0.71 -0.46 -0.62;y = impz(num,den,N);% Plot the impulse responsestem(y);xlabel(Time index n); ylabel(Amplitude);title(Impulse Response); grid; Q2.21 利用filter命令编写一个程序生成因果线性时不变系统的冲击响应并画出前40个样本: % Program Q2_21% Compute the impulse response yclf;N = 40;num = 0.9 -0.
23、45 0.35 0.002;den = 1.0 0.71 -0.46 -0.62;% input: unit pulsex = 1 zeros(1,N-1);% outputy = filter(num,den,x);% Plot the impulse response% NOTE: the time axis will be WRONG; h0 will% be plotted at n=1; but this will agree with% the INCORRECT plotting that was also done% by program P2_5.stem(y);xlabel
24、(Time index n); ylabel(Amplitude);title(Impulse Response); grid; 前40个样本结果如下: 和问题2.20比较,两个序列是- 一样Q2.22 MATLAB程序生成和绘制一个LTI因果系统的阶跃响应是表示如下:% Program Q2_22% Compute the step response sclf;N = 40;n = 0:N-1;num = 2.2403 2.4908 2.2403;den = 1.0 -0.4 0.75;% input: unit stepx = ones(1,N);% outputy = filter(nu
25、m,den,x);% Plot the step responsestem(n,y);xlabel(Time index n); ylabel(Amplitude);title(Step Response); grid; 图像:项目 2.6 LTI系统的级联 P2_6的源代码: % Program P2_6% Cascade Realizationclf;x = 1 zeros(1,40); % Generate the inputn = 0:40;% Coefficients of 4th order systemden = 1 1.6 2.28 1.325 0.68;num = 0.06
26、-0.19 0.27 -0.26 0.12;% Compute the output of 4th order systemy = filter(num,den,x);% Coefficients of the two 2nd order systemsnum1 = 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;% Output y1n of the first stage in the cascadey1 = filter(num1,den1,x);% Output y2n of the second
27、stage in the cascadey2 = filter(num2,den2,y1);% Difference between yn and y2nd = y - y2;% Plot output and difference signalssubplot(3,1,1);stem(n,y);ylabel(Amplitude);title(Output of 4th order Realization); grid;subplot(3,1,2);stem(n,y2)ylabel(Amplitude);title(Output of Cascade Realization); grid;su
28、bplot(3,1,3);stem(n,d)xlabel(Time index n);ylabel(Amplitude);title(Difference Signal); grid;回答:Q2.23 输出序列 yn, y2n, 不同信号 dn 根据P2_6: yn, y2n的关系是 -他们是相同的数值舍入。Q2.24 将输入改成正弦序列重做2.23: yn 和 y2n 在这里的关系是 -他们是相同的数值舍入。Q2.25 用任意的非零初始向量来重做习题2.23: yn 和y2n 在这里的关系式- 一样的Q2.26 修改程序2.6,将2个二阶系统顺序颠倒并零初始条件下重复此过程: % Progr
29、am Q2_26% Cascade Realizationclf;x = 1 zeros(1,40); % Generate the inputn = 0:40;% Coefficients of 4th order systemden = 1 1.6 2.28 1.325 0.68;num = 0.06 -0.19 0.27 -0.26 0.12;% Compute the output of 4th order systemy = filter(num,den,x);% Coefficients of the two 2nd order systemsnum1 = 0.3 -0.2 0.4;den1 = 1 0.9 0.8;num2 = 0.2 -0.5 0.3;den2 = 1 0.7