![](https://csdnimg.cn/release/download_crawler_static/86933694/bg4.jpg)
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
% 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