MATLAB示例1
实践 冲浪&实验教学
绪论 1.2&1.4 典型连续时间信号的matlab描述 1 列出单位冲激信号、单位阶跃、复指数函数等连续信号的matlab表达式
clear, t0 0;tf 5;dt 0.05;t1 1; t [t0:dt:tf];
% 1 单位脉冲信号,
% 在t1 t0≤t1≤tf 处有一持续时间为dt,面积为1的脉冲信号,其余时间均为零。
t [t0:dt:tf];st length t ;
n1 floor t1-t0 /dt ;% 求t1对应的样本序号
x1 zeros 1,st ; % 把全部信号先初始化为零
x1 n1 1/dt;% 给出t1处的脉冲信号
subplot 2,2,1 ,stairs t,x1 ,grid % 绘图,注意为何用stairs命令
axis [0,5,0,1.1/dt] % 2 单位阶跃信号,
%信号从t0到tf,在t1 t0≤t1≤tf 前为0,到t1处有一跃变,以后为1.
%程序前几句即求t,st,n1的语句与上同,只把x1处改为x2
x2 [zeros 1,n1-1 ,ones 1,st-n1+1 ];%产生阶跃信号
subplot 2,2,3 ,stairs t,x2 ,grid % 绘图
axis [0,5,0,1.1]
% 3 复数指数信号
u -0.5;w 10;x3 exp u+j*w *t ;
subplot 2,2,2 ,plot t,real x3 ,grid % 绘图,
subplot 2,2,4 ,plot t,imag x3 ,grid % 绘图, 2)列出抽样信号Sa t 的matlab描述 t -10:0.02:10; f sin t ./t; plot t,f ; title 'f t Sa t ' ; xlabel 't' ; ff axis [-10,-10,-0.4,1.1] 3 先定义阶跃函数heaviside,再用符号运输表示法画出f t u t+3 -2u t 的波形; function f heaviside t %%%定义阶跃函数heaviside f t 0 ;
k sym ' heaviside t+3 -2* heaviside t '
ezplot k,[-5,4] ,
hold on ;
plot [0,0],[-1,1] ;
axis [-5,4,-1.1,1.1] ;
hold off
k
heaviside t+3 -2* heaviside t
画出连续信号的波形 k sym ' sin pi/4*t ' ;
ezplot k,[-16,16] ;
hold on ;
plot [0,0],[-16,16] ;
axis [-16,16,-1,1] ;
hold off
5)
解:对应的MATLAB程序如下:
t 0:0.01:3;
a -1;b 10;
z exp a+i*b *t ;
subplot 2,2,1 ,plot t,real z ,title '实部'
subplot 2,2,3 ,plot t,imag z ,title '虚部' subplot 2,2,2 ,plot t,abs z ,title '模'
subplot 2,2,4 ,plot t,angle z ,title '相角'
6
解:对应的 MATLAB命令如下:
k 0:40;
subplot 2,1,1 ,stem k,cos k*pi/8 , '.'
title 'cos k*pi/8 '
subplot 2,1,2 , stem k,cos 2*k , '.'
title 'cos 2*k '
由绘制的序列波形图,我们可以明显看出,序列f1 为周期序列,而f 2为非
1 2
序列。
。
%单位阶跃序列
k -50:50;
delta [zeros 1,50 ,ones 1,51 ];
stem k,delta,'.' %单位阶跃序列,函数形式 k1 -10;k2 10;k0 3;
k [k1:k2];
f [ k-k0 0];
stem k,f,'.' %单位脉冲序列
k -50:50;
delta [zeros 1,50 ,1,zeros 1,50 ];
stem k,delta,'.' %单位脉冲序列,函数形式
k1 -10;k2 10;k0 3;
k [k1:k2];
f [ k-k0 0];
stem k,f,'.' 信号的运算与变换
1)
解:我们可用符号运算来实现上述过程,MATLAB命令如下:
syms t
f sym ' t/2+1 * heav