文档详情

17-18-离散时间信号和离散时间系统-Matlab实现-A.ppt

发布:2016-12-02约4.64千字共25页下载文档
文本预览下载声明
% 线性卷积 x = [1 2 3 4]; h = [1 2 3]; y = conv(h,x); n = 0:5; %画图 stem(n,y); xlabel(Time index n); ylabel(Amplitude); title(Output Obtained by Convolution); grid on; function [y,ny] = conv_m (x,nx,h,nh) % 序列y为序列x和序列h的卷积 % ny,nx,nh 分别为y,x和h的位置向量 ny0 = nx(1)+nh(1); % 卷积后位置初值的计算 nyf = nx(end) + nh(end); % 卷积后位置终值的计算 y = conv(x,h); % 卷积序列数值的计算 ny = [ny0 : nyf]; % 卷积序列位置向量的计算 % 给定输入序列 nx = [-4:2]; x = [3,-3,7,0,-1,5,2]; % 给定脉冲响应序列 nh = [-1:4]; h = [2,3,0,-5,2,1]; % 带位置序列的卷积结果 [y,ny] = conv_m (x,nx,h,nh) stem(ny,y); xlabel(Time index n); ylabel(Amplitude); title(Output Obtained by Convolution); grid on; 例:求序列x(n)和h(n)的线性卷积y(n)=x(n)*h(n)。 x(n) = {3,-3,7,0,-1,5,2} , h(n) = {2,3,0,-5,2,1}. y = 6 3 5 6 19 -31 30 18 -27 -1 9 2 ny = -5 -4 -3 -2 -1 0 1 2 3 4 5 6 Matlab程序 % 单位脉冲序列 % Generation of a Unit Sample Sequence % Generate a vector from -10 to 20 n = -10:20; % Generate the unit sample sequence u = [zeros(1,10) 1 zeros(1,20)]; % Plot the unit sample sequence stem(n,u); grid on; xlabel(Time index n);ylabel(Amplitude); title(Unit Sample Sequence); axis([-10 20 0 1.2]); function [x,n] = impseq(np,ns,nf) % 单个脉冲序列生成函数 % 产生 x(n) = delta(n-np); % np=脉冲信号施加的位置, % ns=序列的起点位置, nf=序列的终点位置 % 检查输入参数正确性 if ((np ns) | (np nf) | (ns nf)) error(参数必须满足 ns = np = nf) end n = ns:nf; % 生成位置向量 x = [(n-np) == 0]; % 生成单个脉冲序列 % 阶跃序列生成函数 function [x,n] = stepseq(np,ns,nf) % 产生 x(n) = u(n-np); ns = n,np = nf % 检查输入参数正确性 if ((np ns) | (ns nf) | (np nf)) error(参数必须满足 ns = np = nf) end n = ns:nf; % 生成位置向量 x = [(n-np) = 0]; % 生成阶跃序列 x = [zeros(1,(np-ns)), ones(1,(nf-np+1))]; % 生成阶跃序列的另一种语句 %复指数序列 c = -(1/12)+(pi/6)*i; K = 2; n = 0:40; x = K*exp(c*n); subplot(2,1,
显示全部
相似文档