实验一++离散信号的产生和运算.docx
《实验一++离散信号的产生和运算.docx》由会员分享,可在线阅读,更多相关《实验一++离散信号的产生和运算.docx(20页珍藏版)》请在冰豆网上搜索。
实验一++离散信号的产生和运算
实验目的:
掌握利用Matlab产生各种离散时间信号,实现信号的相加、相乘及卷积运算
实验函数:
参考课本77-19页,注意式(2.11.1)的表达与各matlab子函数间的关系。
1、stem(x,y)%绘制以x为横轴,y为纵轴的离散序列图形
2、[h,t]=impz(b,a)%求解数字系统的冲激响应h,取样点数为缺省值
[h,t]=impz(b,a,n)%求解数字系统的冲激响应h,取样点数为n
impz(b,a)%在当前窗口用stem(t,h)函数出图
3、[h,t]=dstep(b,a)%求解数字系统的阶跃响应h,取样点数为缺省值
[h,t]=dstep(b,a,n)%求解数字系统的阶跃响应h,取样点数为n
dstep(b,a)%在当前窗口用stairs(t,h)函数出图
4、y=filter(b,a,x)%在已知系统差分方程或转移函数的情况下求系统输出
实验原理:
一、常用的时域离散信号及其程序
1、产生单位抽样函数δ(n)
n1=-5;
n2=5;
n0=0;
n=n1:
n2;
x=[n==n0];%x在n=n0时为1,其余为0
stem(n,x,'filled');%filled:
序列圆心处用实心圆表示
axis([n1,n2,0,1.1*max(x)])
title('单位抽样序列')
xlabel('time(n)')
ylabel('Amplitude:
x(n)')
2、产生单位阶跃序列u(n)
n1=-2;
n2=8;
n0=0;
n=n1:
n2;
x=[n>=n0];%x在n>=n0时为1,其余为0
stem(n,x,'filled');
axis([n1,n2,0,1.1*max(x)])
title('单位阶跃序列')
xlabel('time(n)')
ylabel('Amplitude:
x(n)')
3、复指数序列
复指数序列的表示式为
,当
时,
为实指数序列;当
时,
为虚指数序列,即
,即其实部为余弦序列,虚部为正弦序列。
产生
、
复指数连续信号与离散序列的Matlab程序如下:
n1=30;
sigma=-0.1;
omega=0.6;
n=0:
n1;
x=exp((sigma+i*omega)*n);
subplot(2,2,1),plot(n,real(x));
title('复指数信号的实部')
subplot(2,2,3),stem(n,real(x),'filled');
title('复指数序列的实部')
subplot(2,2,2),plot(n,imag(x));
title('复指数信号的虚部')
subplot(2,2,4),stem(n,imag(x),'filled');
title('复指数序列的虚部')
4、正(余)弦序列
正(余)弦序列的表示式为
。
已知一时域周期性正弦信号的频率为1Hz,振幅值幅度为1V。
在窗口上显示两个周期的信号波形,并对该信号的一个周期进行32点采样获得离散信号。
试显示原连续信号和其采样获得的离散信号波形。
Matlab程序如下:
f=1;
Um=1;
nt=2;
N=32;
T=1/f;
dt=T/N;
n=0:
nt*N-1;
tn=n*dt;
x=Um*sin(2*f*pi*tn);
subplot(2,1,1),plot(tn,x);
title('连续时间正弦信号和离散正弦序列')
ylabel('x(t)')
subplot(2,1,2),stem(tn,x);
ylabel('x(n)')
5、sinc函数
求
,Matlab程序如下:
n=-20:
20;
f=sinc(n/4);
subplot(2,1,1),plot(n,f);
title('sinc信号')
subplot(2,1,2),stem(n,f);
title('sinc序列')
二、离散序列的基本运算
离散序列的时域运算包括信号的相加、相乘,信号的时域变换包括信号的移位、反折、倒相以及信号的尺度变换等。
在Matlab中,离散序列的相加、相乘等运算时两个向量之间的运算,因此参加运算的两个序列向量必须具有相同的维数,否则应进行相应的处理。
1、序列移位
将一个离散信号序列进行移位,形成新的序列:
。
当
时,原序列
向右移
位,形成的新序列称为
的延时序列;当
时,原序列
向左移
位,形成的新序列称为
的超前序列。
编写Matlab程序对
序列进行移位,并比较三者间的关系。
Matlab程序如下:
n1=10;
k1=-6;
k2=4;
n=-n1:
n1;
x0=[n>=0];
x1=[n>=k1];
x2=[n>=k2];
subplot(3,1,1),stem(n,x0,'filled');title('u(n)')
subplot(3,1,2),stem(n,x1,'filled');title('x1(n)=u(n-6)')
subplot(3,1,3),stem(n,x2,'filled');title('x2(n)=u(n+4)')
2、序列相加
当参加运算的两个序列具有相同的维数时,可直接对应相加。
现考虑参加运算的两个序列的维数不同的情况。
求
。
要求上述两个序列之和,必须对长度较短的序列补零,同时保持位置一一对应。
Matlab程序如下:
n1=-4:
6;
x1=[n1>=-2];
n2=-5:
8;
x2=[n2>=4];
n=min([n1,n2]):
max([n1,n2]);%为x信号建立时间序列
N=length(n);%确定时间序列n的点数N
y1=zeros(1,N);y2=zeros(1,N);
y1(find((n>=min(n1))&(n<=max(n1))))=x1;
y2(find((n>=min(n2))&(n<=max(n2))))=x2;
x=y1+y2;
subplot(3,1,1),stem(n,y1,'filled');title('x1(n)')
subplot(3,1,2),stem(n,y2,'filled');title('x2(n)')
subplot(3,1,3),stem(n,x,'filled');title('x(n)')
3、序列反折
离散序列反折是指离散序列的两个向量以零时刻的取值的基本点,以纵轴为对称轴反折。
在Matlab中提供了fliplr函数,可是实现序列的反折。
已知一个信号
,求它的反折序列
。
Matlab程序如下:
n=-4:
4;
x=exp(-0.3*n);
x1=fliplr(x);
n1=-fliplr(n);
subplot(2,1,1),stem(n,x,'filled');title('x(n)')
subplot(2,1,2),stem(n1,x1,'filled');title('x(-n)')
4、序列的尺度变换
对于给定的离散序列
,序列
是
每隔
点取一点形成,相当于时间轴
压缩了
倍;反之,序列
是
作
倍插值而形成的,相当于时间轴
扩展了
倍。
已知信号
,求
和
的信号波形。
为研究问题方便,取
,并将
缩小20倍进行波形显示。
Matlab程序如下:
n=(0:
20)/20;
x=sin(2*pi*n);
x1=sin(2*pi*n*2);
x2=sin(2*pi*n/2);
subplot(3,1,1),stem(n,x,'filled');title('x(n)')
subplot(3,1,2),stem(n,x1,'filled');title('x1(n)')
subplot(3,1,3),stem(n,x2,'filled');title('x2(n)')
5、序列卷积的计算
Matlab中的卷积函数conv默认两个信号的时间序列从n=0开始。
序列f1=0.8n(0≤n≤20),f2=u(n)(0≤n≤10)的卷积可用以下程序进行计算:
n1=0:
20;
f1=0.8.^n1;
subplot(2,2,1),stem(n1,f1);
title('f1(n)')
n2=0:
10;
l2=length(n2);
f2=ones(1,l2);
subplot(2,2,2),stem(n2,f2);
title('f2(n)')
y=conv(f1,f2);
subplot(2,1,2),stem(y);
title('y(n)=f1*f2')
如果信号不是从0开始,则编程时必须用两个数组确定一个信号,其中,一个数组是信号波形的幅度样值,另一个数组是其对应的时间向量。
此时程序的编写较为复杂,可以将其处理过程编写成一个可调用的通用子函数convnew,这个函数适用于信号从任意时间开始的通用程序。
function[y,ny]=convnew(x,nx,h,nh)%建立convnew子函数
%x为一信号幅度样值向量,nx为x对应的时间向量
%h为另一信号或系统冲激函数的非零样值向量,nh为h对应的时间向量
%y为卷积积分的非零样值向量,ny为其对应的时间向量
n1=nx
(1)+nh
(1);%计算y的非零样值的起点位置
n2=nx(length(x))+nh(length(h));%计算y的非零样值的宽度
ny=[n1:
n2];%确定y的非零样值时间向量
y=conv(x,h);
用上述程序可以计算两个离散时间序列的卷积和,求解信号通过一个离散系统的响应。
实验任务:
1、在Matlab中运行各例题程序,理解时域离散信号的产生方法和离散序列的运算性质,了解各条语句的意义。
2、完成以下习题:
(1)编写程序产生下列离散序列:
①
n1=-3;
n2=4;
n0=0;
n=n1:
n2;
x=[n==n0];%x在n=n0时为1,其余为0
stem(n,x,'filled');%filled:
序列圆心处用实心圆表示
axis([n1,n2,0,1.1*max(x)])
title('单位抽样序列')
xlabel('time(n)')
ylabel('Amplitude:
x(n)')
②
n1=-5;
n2=5;
n0=0;
n=n1:
n2;
x=[n>=n0];%x在n>=n0时为1,其余为0
stem(n,x,'filled');
axis([n1,n2,0,1.1*max(x)])
title('单位阶跃序列')
xlabel('time(n)')
ylabel('Amplitude:
x(n)')
③
n1=16;
sigma=-0.1;
omega=0.6;
n=0:
n1;
x=exp((sigma+i*omega)*n);
subplot(2,2,1),plot(n,real(x));
title('复指数信号的实部')
subplot(2,2,3),stem(n,real(x),'filled');
title('复指数序列的实部')
subplot(2,2,2),plot(n,imag(x));
title('复指数信号的虚部')
subplot(2,2,4),stem(n,imag(x),'filled');
title('复指数序列的虚部')
④
f=1/8;
Um=3;
nt=2;
N=32;
T=1/f;
dt=T/N;
n=0:
nt*N-1;
tn=n*dt;
x=Um*sin(2*f*pi*tn);
subplot(2,1,1),plot(tn,x);
title('连续时间正弦信号和离散正弦序列')
ylabel('x(t)')
subplot(2,1,2),stem(tn,x);
ylabel('x(n)')
⑤
n=-20:
20;
f=sinc(n/5);
subplot(2,1,1),plot(n,f);
title('sinc信号')
subplot(2,1,2),stem(n,f);
title('sinc序列')
(2)一个连续的周期性三角波信号频率为50Hz,信号幅度在0~+2V之间,在窗口上显示2个周期的信号波形,对信号的一个周期进行16点采样来获得离散信号。
试显示连续信号和采样获得的离散信号波形。
(用sawtooth产生三角波)
f=50;
Um=2;
nt=2;
N=16;
T=1/f;
dt=T/N;
n=0:
nt*N-1;
tn=n*dt;
x=Um*sin(2*f*pi*tn);
subplot(2,1,1),plot(tn,x);
title('连续时间正弦信号和离散正弦序列')
ylabel('x(t)')
subplot(2,1,2),stem(tn,x);
ylabel('x(n)')
(3)用Matlab实现下列信号序列:
n1=-5:
5;
x1=[n1==-3];
n2=-5:
5;
x2=[n2==4];
n=min([n1,n2]):
max([n1,n2]);%为x信号建立时间序列
N=length(n);%确定时间序列n的点数N
y1=zeros(1,N);y2=zeros(1,N);
y1(find((n>=min(n1))&(n<=max(n1))))=x1;
y2(find((n>=min(n2))&(n<=max(n2))))=2*x2;
x=y1+y2;
subplot(3,1,1),stem(n,y1,'filled');title('x1(n)')
subplot(3,1,2),stem(n,y2,'filled');title('x2(n)')
subplot(3,1,3),stem(n,x,'filled');title('x(n)')
(4)已知
,显示
、
和
在
区间的波形。
f=1/10;
Um=3;
nt=2;
N=20;
T=1/f;
dt=T/N;
n=0:
nt*N-1;
tn=n*dt;
x=Um*cos(2*f*pi*tn);
subplot(3,1,1),plot(tn,x);
title('连续时间余弦信号X(n)')
ylabel('x(t)')
n=n+3;
subplot(3,1,2),plot(tn-3,x);
title('连续时间余弦信号X(n-3)')
ylabel('x(t)')
n=n-6;
subplot(3,1,3),plot(tn+3,x);
title('连续时间余弦信号X(n+3)')
ylabel('x(t)')
(5)已知
,试显示
、
、
和
在
区间的波形。
n=0:
20;
x=n.*sin(n);
x1=fliplr(x);
n1=-fliplr(n);
x2=n/2.*sin(n/2);
subplot(4,1,1),plot(n,x);
title('X(n)')
ylabel('x(n)')
subplot(4,1,2),plot(n1,x1);
title('X(-n)')
ylabel('x(n)')
subplot(4,1,3),plot(n,-x);
title('-X(n)')
ylabel('x(n)')
subplot(4,1,4),plot(n,x2);
title('X(n/2)')
ylabel('x(n)')
(6)编写Matlab程序,描绘下列信号序列的卷积波形:
①
n=0:
10
x1=[n>=0];
x2=exp(0.2*n).*x1;
subplot(2,1,1),plot(n,x1);title('x1(n)')
subplot(2,1,2),plot(n,x2);title('x2(n)')
②
(7)已知一个IIR系统的转移函数为
输入矩形序列可用以下指令产生:
x=square(n/5)(-2画出该系统单位抽样相应以及输入、输出序列的波形。
提示:
求出系统的单位抽样响应h(n),再利用y(n)=x(n)*h(n)得出输出序列。