
学院:计算机科学与信息学院 专业: 网络工程 班级:网络092
| 姓名 | 王荣森 | 学号 | 0908060386 | 实验组 | ||
| 实验时间 | 2012/5/9 | 指导教师 | 吕晓丹 | 成绩 | ||
| 实验项目名称 | 实验二、离散系统的时域分析 | |||||
| 实验目的 | 1、熟悉并掌握离散系统的差分方程表示法; 2、加深对冲激响应和卷积分析方法的理解。 | |||||
| 实验要求 | 1、在MATLAB中,熟悉利用函数实现差分方程的仿真; 2、在MATLAB中,熟悉用函数 计算卷积,用求系统冲激响应的过程。 | |||||
| 实验原理 | 在时域中,离散时间系统对输入信号或者延迟信号进行运算处理,生成具有所需特性的输出信号,具体框图如下: 其输入、输出关系可用以下差分方程描述: 输入信号分解为冲激信号, 记系统单位冲激响应,则系统响应为如下的卷积计算式: 当时,h[n]是有限长度的(n:[0,M]),称系统为FIR系统;反之,称系统为IIR系统。 | |||||
| 实验仪器 | Pc MATLAB | |||||
| 实验内容 | 1、以下程序中分别使用conv和filter函数计算h和x的卷积y和y1,运行程序,并分析y和y1是否有差别,为什么要使用x[n]补零后的x1来产生y1;具体分析当h[n]有i个值,x[n]有j个值,使用filter完成卷积功能,需要如何补零? % Program P2_7 clf; h = [3 2 1 -2 1 0 -4 0 3]; %impulse response x = [1 -2 3 -4 3 2 1]; %input sequence y = conv(h,x); n = 0:14; subplot(2,1,1); stem(n,y); xlabel('Time index n'); ylabel('Amplitude'); title('Output Obtained by Convolution'); grid; x1 = [x zeros(1,8)]; y1 = filter(h,1,x1); subplot(2,1,2); stem(n,y1); xlabel('Time index n'); ylabel('Amplitude'); title('Output Generated by Filtering'); grid; 2、编制程序求解下列两个系统的单位冲激响应和阶跃响应,并绘出其图形。要求分别用 filter、conv、impz三种函数完成。, , 给出理论计算结果和程序计算结果并讨论。 | |||||
| 实验步骤 及实验数据 | 1、以下程序中分别使用conv和filter函数计算h和x的卷积y和y1,运行程序,并分析y和y1是否有差别,为什么要使用x[n]补零后的x1来产生y1;具体分析当h[n]有i个值,x[n]有j个值,使用filter完成卷积功能,需要如何补零? % Program P2_7 clf; h = [3 2 1 -2 1 0 -4 0 3]; %impulse response x = [1 -2 3 -4 3 2 1]; %input sequence y = conv(h,x); n = 0:14; subplot(2,1,1); stem(n,y); xlabel('Time index n'); ylabel('Amplitude'); title('Output Obtained by Convolution'); grid; x1 = [x zeros(1,8)]; y1 = filter(h,1,x1); subplot(2,1,2); stem(n,y1); xlabel('Time index n'); ylabel('Amplitude'); title('Output Generated by Filtering'); grid; 程序运行结果: 由图可看出,y与y1并无差别。 使用x[n]补零后的x1来产生y1,是因为存在边界效应,只要脉冲响应采样电部分位于输入信号采样值之外,输出就不确定,如: x 1 -2 3 -4 3 2 1 2 h 3 0 -4 0 1 -2 1 2 3 2 4 1 需变换成如下才能确定输出: x 1 -2 3 -4 3 2 1 2 0 0 0 0 0 0 0 0 0 0 0 h 3 0 -4 0 1 -2 1 2 3 2 4 1 此时n=18。 用conv函数计算能再输入序列后自动补零,而filter函数不能。 分析: (1) h = [1 4 2 3 2 1 -2 1 0 -4 0 3]; % impulse response i=12 x = [1 -2 3 -4 3 2 1 2]; % input sequence j=8 n = 0:17; x1 = [x zeros(1,10)]; %补十个零值 y1 = filter(h,1,x1); stem(n,y1); xlabel('Time index n'); ylabel('Amplitude'); title('Output Generated by Filtering'); grid (1)图 (2) h = [1 4 2 3 2 1 -2 1 0 -4 0 3]; % impulse response i=12 x = [1 -2 3 -4 3 2 1 2]; % input sequence j=8 n = 0:18; x1 = [x zeros(1,11)]; %补11个零值 y1 = filter(h,1,x1); stem(n,y1); xlabel('Time index n'); ylabel('Amplitude'); title('Output Generated by Filtering'); grid (2)图 (3) h = [1 4 2 3 2 1 -2 1 0 -4 0 3]; % impulse response i=12 x = [1 -2 3 -4 3 2 1 2]; % input sequence j=8 n = 0:30; x1 = [x zeros(1,23)]; %补23个零值 y1 = filter(h,1,x1); stem(n,y1); xlabel('Time index n'); ylabel('Amplitude'); title('Output Generated by Filtering'); grid; (3)图 对照(1)、(2)图,当n=18时两图有区别,(2)图能完全卷积,当补零数少于j-1,就不能完全卷积。 对照(2)、(3)图可知,不零数可大于 j-1,须满足n的长度与补零后x1的长度相等。 h[n]有i个值,x[n]有j个值, 以n为x轴,n=0:N,使用x[n]补零后的x1来产生y1,由上述图可知,要完全卷积,x1至少需补j-1个零值。其中N>=(i+j-1)-1, n的长度与补零后x1的长度相等,若x1中补a个零值(a>=j-1),则N=i+a-1。 2、编制程序求解下列两个系统的单位冲激响应和阶跃响应,并绘出其图形。要求分别用 filter、conv、impz三种函数完成。 给出理论计算结果和程序计算结果并讨论。 理论计算结果: 单位冲激响应: n 0 1 2 3 4 5 …… h[n] 1 -1.75 1.19 -0.67 0.355 -0.18 ……. Y[n] 1 -1.75 1.19 -0.67 0.355 -0.18 …… 单位阶跃响应: n 0 1 2 3 4 5 …… Y[n] 1 -0.75 0.44 -0.234 0.12 -0.06 …… 单位冲激响应: n 0 1 2 3 4 5 …… Y[n] 0 0.25 0.25 0.25 0.25 0…… 单位阶跃响应: n 0 1 2 3 4 5 …… Y[n] 0 0.25 0.5 0.75 1 1 …… 程序计算结果: I. a. 单位冲激响应: (1)用filter函数 a1=[1,0.75,0.125]; b1=[1,-1]; n=0:20; x1=[1 zeros(1,20)]; y1filter=filter(b1,a1,x1); stem(n,y1filter); title('y1filter'); xlabel('x'); ylabel('y'); (2)用conv函数 a1=[1,0.75,0.125]; b1=[1,-1]; x1=[1 zeros(1,10)]; [h]=impz(b1,a1,10); y1conv=conv(h,x1); n=0:19; stem(n,y1conv,'filled') (3)用impz函数 a1=[1,0.75,0.125]; b1=[1,-1]; impz(b1,a1,21); b. 单位阶跃响应: (1)用filter函数 a1=[1,0.75,0.125]; b1=[1,-1]; n=0:20; x2=ones(1,21); y1filter=filter(b1,a1,x2); stem(n,y1filter); title('y1filter_step'); xlabel('x'); ylabel('y'); (2)用conv函数 a1=[1,0.75,0.125]; b1=[1,-1]; x2=ones(1,21); [h]=impz(b1,a1,20); y1=conv(h,x2); y1conv=y1(1:21); %为何y1conv要取y1中1:21的值,解释见 n1=0:20; %y2 单位阶跃响应 用conv函数中注释 stem(n1,y1conv,'filled'); title('y1conv'); xlabel('n'); ylabel('y1[n]'); (3)用impz函数 a=[1,0.75,0.125]; b=1; impz(b,a) II. y[n]=0.25(x[n-1]+x[n-2]+x[n-3]+x[n-4]) a. 单位冲激响应: (1)用filter函数 a2=1; b2=[0 0.25*ones(1,4)]; n=0:9; x1=[1 zeros(1,9)]; y2filter=filter(b2,a2,x1); stem(n,y2filter); title('y2filter'); xlabel('x'); ylabel('y') (2)用conv函数 a2=1; b2=[0 0.25*ones(1,4)]; x1=[1 zeros(1,5)]; [h]=impz(b2,a2,5); y2conv=conv(h,x1); n=0:9; stem(n,y2conv,'filled') (3)用impz函数 a2=1; b2=[0 0.25*ones(1,4)]; impz(b2,a2,10); b. 单位阶跃响应: (1)用filter函数 a2=1; b2=[0 0.25*ones(1,4)]; n=0:20; x2=ones(1,21); y2filter=filter(b2,a2,x2); stem(n,y2filter); title('y2filter_step'); xlabel('x'); ylabel('y') (2)用conv函数 h=[0 0.25*ones(1,4)]; x2=ones(1,21); n=0:20; y2=conv(h,x2); y2conv=y2(1:21); %当x[n]输入序列为无限时,因为画图需取有 stem(n,y2conv,'filled'); %限个值,题中x2取21个值,h有5个值,卷积 title('y2conv'); %结果y2有21+5—1=25个值,进行卷积时, xlabel('n'); %x2有限个值后与y2对应位置以补零进行计 ylabel('y[n]') %算,而实际这部分值为1,所以,应将y2中对 %应x2补零位置的值去掉。当x[n]为有限序列 %时,不用如上考虑。 (3)用impz函数 S[n]=y[n]=0.25+0.5+0.75+u[n-4] 源程序: n=0:20; b=[0,0.25,0.5,0.75,ones(1,17)]; a=1; impz(b,a,21) | |||||
| 实验总结 | ||||||
| 指导教师意见 | 签名: 年 月 日 | |||||
