信号与系统实验教程(MATLAB) 联系客服

发布时间 : 星期一 文章信号与系统实验教程(MATLAB)更新完毕开始阅读

用函数曲线表示一个信号,图1.1就是一个连续时间信号和一个离散时间信号的波形图。

图1.1 连续时间信号与离散时间信号的波形图

1.3将信号用一个数据序列来表示

对于离散时间信号,还可以表示成一个数的序列,例如: x[n]={...., 0.1, 1.1, -1.2, 0, 1.3, ….} ↑n=0

在《信号与系统》和《数字信号处理》课程中,上述三种信号的描述方法是经常要使用的。

2 用MATLAB仿真连续时间信号和离散时间信号

在MATLAB中,无论是连续时间信号还是离散时间信号,MATLAB都是用一个数字序列

来表示信号,这个数字序列在MATLAB中叫做向量(vector)。通常的情况下,需要与时间变量相对应。

如前所述,MATLAB有很多内部数学函数可以用来产生这样的数字序列,例如sin()、cos()、exp()等函数可以直接产生一个按照正弦、余弦或指数规律变化的数字序列。

2.1连续时间信号的仿真

程序Program1_1是用MATLAB对一个正弦信号进行仿真的程序,请仔细阅读该程序,

并在计算机上运行,观察所得图形。

% Program1_1

% This program is used to generate a sinusoidal signal and draw its plot clear, % Clear all variables

close all, % Close all figure windows

dt = 0.01; % Specify the step of time variable t = -2:dt:0.2; % Specify the interval of time x = sin(2*pi*t); % Generate the signal

plot(t,x) % Open a figure window and draw the plot of x(t) title('Sinusoidal signal x(t)') xlabel('Time t (sec)')

常用的图形控制函数

axis([xmin,xmax,ymin,ymax]):图型显示区域控制函数,其中xmin为横轴的显示起点,xmax为横轴的显示终点,ymin为纵轴的显示起点,ymax为纵轴的显示终点。

5

有时,为了使图形具有可读性,需要在所绘制的图形中,加上一些网格线来反映信号的幅度大小。MATLAB中的grid on/grid off可以实现在你的图形中加网格线。

grid on:在图形中加网格线。 grid off:取消图形中的网格线。

x = input(‘Type in signal x(t) in closed form:’) 在《信号与系统》课程中,单位阶跃信号u(t) 和单位冲激信号δ(t) 是二个非常有用的信号。它们的定义如下

?t?????(t)dt?1t?0 1.1(a)

?(t)?0,?1,u(t)???0,t?0 1.1(b) t?0这里分别给出相应的简单的产生单位冲激信号和单位阶跃信号的扩展函数。产生单位冲激信号的扩展函数为:

function y = delta(t) dt = 0.01;

y = (u(t)-u(t-dt))/dt;

产生单位阶跃信号的扩展函数为: % Unit step function function y = u(t)

y = (t>=0); % y = 1 for t > 0, else y = 0

请将这二个MATLAB函数分别以delta 和u为文件名保存在work文件夹中,以后,就可以像教材中的方法使用单位冲激信号δ(t) 和单位阶跃信号u(t)。

2.2离散时间信号的仿真

程序Program1_2用来产生离散时间信号x[n]=sin(0.2πn)。

% Program1_2

% This program is used to generate a discrete-time sinusoidal signal and draw its plot clear, % Clear all variables

close all, % Close all figure windows n = -10:10; % Specify the interval of time x = sin(0.2*pi*n); % Generate the signal

stem (n,x) % Open a figure window and draw the plot of x[n] title ('Sinusoidal signal x[n]') xlabel ('Time index n')

请仔细阅读该程序,比较程序Program1_1和Program1_2中的不同之处,以便自己编程时能够正确使用这种方法方针连续时间信号和离散时间信号。 程序Program1_3用来仿真下面形式的离散时间信号: x[n]={...., 0.1, 1.1, -1.2, 0, 1.3, ….} ↑n=0

6

% Program1_3

% This program is used to generate a discrete-time sequence % and draw its plot

clear, % Clear all variables

close all, % Close all figure windows

n = -5:5; % Specify the interval of time, the number of points of n is 11. x = [0, 0, 0, 0, 0.1, 1.1, -1.2, 0, 1.3, 0, 0]; % Generate the signal

stem(n,x,'.') % Open a figure window and draw the plot of x[n] grid on,

title ('A discrete-time sequence x[n]') xlabel ('Time index n')

由于在程序的stem(n,x,'.') 语句中加有'.'选项,因此绘制的图形中每根棒条线的顶端是一个实心点。

如果需要在序列的前后补较多的零的话,可以利用函数zeros(),其语法为:

zeros(1, N):圆括号中的1和N表示该函数将产生一个一行N列的矩阵,矩阵中的所有元素均为零。利用这个矩阵与序列x[n]进行组合,从而得到一个长度与n相等的向量。

例如,当 x[n]={ 0.1, 1.1, -1.2, 0, 1.3} 时,为了得到程序Program1_3中的序列, ↑n=0

可以用这个MATLAB语句x = [zeros(1,4) x zeros(1, 2)] 来实现。用这种方法编写的程序如下:

% Program1_4

% This program is used to generate a discrete-time sinusoidal signal % and draw its plot

clear, % Clear all variables

close all, % Close all figure windows n = -5:5; % Specify the interval of time

x = [zeros(1,4), 0.1, 1.1, -1.2, 0, 1.3, zeros(1,2)]; % Generate the sequence stem (n,x,'.') % Open a figure window and draw the plot of x[n] grid on,

title ('A discrete-time sequence x[n]') xlabel ('Time index n')

离散时间单位阶跃信号u[n]定义为 u[n]???1,?0,n?0 1.2 n?0离散时间单位阶跃信号u[n]除了也可以直接用前面给出的扩展函数来产生,还可以利用MATLAB内部函数ones(1,N) 来实现。这个函数类似于zeros(1,N),所不同的是它产生的矩阵的所有元素都为1。

值得注意的是,利用ones(1,N) 来实现的单位阶跃序列并不是真正的单位阶跃序列,而是一个长度为N单位门(Gate)序列,也就是u[n]-u[n-N]。但是在一个有限的图形窗口中,我们看到的还是一个单位阶跃序列。

在绘制信号的波形图时,有时我们需要将若干个图形绘制在图一个图形窗口中,这就需要

7

使用MATLAB的图形分割函数subplot(),其用法是在绘图函数stem或plot之前,使用图形分割函数subplot(n1,n2,n3),其中的参数n1,n2和n3的含义是,该函数将把一个图形窗口分割成n1xn2个子图,即将绘制的图形将绘制在第n3个子图中。

2.3信号的时域变换 2.3.1 信号的时移

信号的时移可用下面的数学表达式来描述:

设一个连续时间信号为x(t),它的时移y(t) 表示为:

y(t) = x(t - t0) 1.3

其中,t0为位移量。若t0为正数,则y(t)等于将x(t)右移t0秒之后的结果。反之,若t0为负数,则y(t)等于将x(t)左移t0秒之后的结果。

在MATLAB中,时移运算与数学上习惯表达方法完全相同。 程序Program1_5对给定一个连续时间信号x(t) = e-0.5tu(t),对它分别左移2秒钟和右移2秒钟得到信号x1(t) = e-0.5(t+2)u(t+2)和x2(t) = e-0.5(t-2)u(t-2)。

% Program1_5

% This program is used to implement the time-shift operation

% on a continuous-time signal and to obtain its time-shifted versions % and to draw their plots. clear,close all, t = -5:0.01:5;

x = exp(-0.5*t).*u(t); % Generate the original signal x(t)

x1 = exp(-0.5*(t+2)).*u(t+2); % Shift x(t) to the left by 2 second to get x1(t) x2 = exp(-0.5*(t-2)).*u(t-2); % Shift x(t) to the right by 2 second to get x2(t) subplot(311)

plot(t,x) % Plot x(t) grid on,

title ('Original signal x(t)') subplot (312)

plot (t,x1) % Plot x1(t) grid on,

title ('Left shifted version of x(t)') subplot (313)

plot (t,x2) % Plot x2(t) grid on,

title ('Right shifted version of x(t)') xlabel ('Time t (sec)')

2.3.2 信号的时域反褶

对一个信号x[n]的反褶运算在数学上表示为

y[n] = x[-n] 1.4

这种反褶运算,用MATLAB实现起来也是非常简单的。有多种方法可以实现信号的反褶

8