加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

信号与系统的MATLAB仿真(4.1-4.9)

(2011-10-05 06:40:31)
标签:

信号与系统

matlab

仿真

信号时域分析

常用信号

杂谈

分类: 信号系统MATLAB仿真
信号与系统的MATLAB仿真(4.1-4.9) 
参考文献:赵鸿图,茅艳主编.通信原理MATLAB仿真教程[M].北京:人民邮电出版社,2010.11
% 4.1 信号时域分析
% 4.1.1 常用信号的MATLAB表示
% 1. 常用奇异信号表示
% 图(1)单位冲激信号
http://s10/middle/59a069d5gc3bc44975019&690
% 例4-1 单位冲激信号的产生
% MATLAB中,单位冲激信号的直接实现为:n=n1:dt:n2;x=(n==0)
%  (file name: zht_ex4_1_p69.m)
t = -5:0.01:5;
y = (t==0);
subplot(121);
plot(t,y,'r');
n = -5:5;
x = (n==0);
subplot(122);
stem(n,x);
%————————————————————————————————
图2  不同的实指数信号
http://s1/middle/59a069d5gc3bbddf1a0e0&690
% 例4-2 比较不同的实指数信号
% 实指数信号的MATLAB实现为:n=n1:dt:n2;x=a.^n
% (file name: zht_ex4_2_p70.m )
clear;
n=0:1:10;
a1=0.5;a2=-0.5;a3=1.2;a4=-1.2;
x1=a1.^n; x2=a2.^n;
x3=a3.^n; x4=a4.^n;
subplot(221),stem(n,x1);
title('实指数序列(0<a1<1)');
xlabel('n'); ylabel('x1(n)');

subplot(222),stem(n,x2);
title('实指数序列(-1<a2<0)');
xlabel('n'); ylabel('x2(n)');

subplot(223),stem(n,x3);
title('实指数序列(1<a3)');
xlabel('n'); ylabel('x3(n)');

subplot(224),stem(n,x4);
title('实指数序列(a4<-1)');
xlabel('n'); ylabel('x4(n)');
% --------------------------------------------------------------
图3  复指数信号
http://s14/middle/59a069d5gc3bc01a46f3d&690
例题4-3 生成复指数信号
% (4) 复指数信号 x(n)=e^(Δ+jw)n
% 复指数信号的MATLAB实现为: n = n1:n2; x = exp(delta+jw)*n
% (file name: zht_ex4_3_p71.m )
clear;
n=0:10;
delta=-0.2; w0=0.7;
x=exp((delta+j*w0)*n);
subplot(211),stem(n,real(x));
title('复指数序列');
ylabel('复指数序列的实部');

subplot(212),stem(n,imag(x));
ylabel('复指数序列的虚部');
xlabel('n');
% ————————————————————————————-———
图4  正(余)弦信号
http://s4/middle/59a069d5nc3c01ecc7e73&690
例题4-4 生成正弦波
% (5) 正(余)弦信号x(n)=cos(wn+θ)
%  正(余)弦信号的MATLAB实现为: n=n1:n2; x=cos(w*n+sita)
% ( file name: zht_ex4_4_p72.m)
clear;
n=0: 10;
w0=pi/5; w1=pi/4;
subplot(211);
x=sin(n*w0+w1); stem(n,x);
line([0,10],[0,0]);
title('正弦型序列');
xlabel('n'); ylabel('x(n)');

subplot(212);
t=0:0.01:10;
y=sin(t*w0+w1); plot(t,y);
title('正弦型信号');
xlabel('t'); ylabel('y(t)');
line([0,10],[0,0]);
%——————————————————————————————--
%———————————————————————————————
2.工具箱中的信号产生函数

函数名

功能(产生***信号)

函数名

功能(产生***信号)

sawtooth

锯齿波(三角波)

pulstran

冲激串

square

方波

rectpuls

非周期的方波

sinc

抽样(sinc)函数

tripuls

非周期的三角波

chirp

调频余弦

diric

Dirichlet(sinc)函数

gauspuls

高斯正弦脉冲

gmonopuls

高斯单脉冲

vco

电压控制振荡器

 

 

 (1)周期性三角波或者锯齿波函数sawtooth

调用格式:x = sawtooth(t,width)     (width:最大幅度出现的位置)

【例题4-5】 产生周期为0.2的三角波,width取值分别为0、1、0.5.

http://s3/middle/59a069d5nc44771040562&690

% zht_ex4_5_p73.m

% 【例题4-5】 产生周期为0.2的三角波,width取值分别为0、1、0.5.

td = 1/100000;  % td - 时间间隔

t = 0:td:1

x1 = sawtooth(2*pi*5*t,0);

x2 = sawtooth(2*pi*5*t,1);

x3 = sawtooth(2*pi*5*t,0.5);


subplot(311); td1=plot(t,x1);set(td1,'linewidth',2);

title('周期性三角波');

subplot(312); td2=plot(t,x2);set(td2,'linewidth',2);

subplot(313); td3=plot(t,x3);set(td3,'linewidth',2);

%_________________________________________________________________
【例4-6】 仔细观察由下面代码产生的3个三角波信号之间的区别。
http://s5/middle/59a069d5g7a072b7ae0b4&690
% 【例4-6】 仔细观察由下面代码产生的3个三角波信号之间的区别。
%  (filename:zht_ex4_6_p74.m

t = -3:0.001:3;
x1=tripuls(t,4,0);
subplot(131); td1=plot(t,x1);set(td1,'linewidth',2);
axis([-4 4 0 1]);
grid

t=-6:0.001:6;
x2=tripuls(t,4,0.5);
subplot(132); td2=plot(t,x2);set(td2,'linewidth',2);
axis([-4 4 0 1]);title('非周期三角波');
grid;

x3=tripuls(t+2,4,0.5);
subplot(133); td3=plot(t,x3);set(td3,'linewidth',2);
axis([-4 4 0 1]);
grid

%______________________________________________________________

http://s11/middle/59a069d5g7a073754029a&690

% [【例题4-7】 产生频率为40Hz,占空比分别为25%,50%,75%的周期性方波。

% filename: zht_ex_4_7_p75.m

% 调用格式:x=square(t,duty)

% 产生周期为2π、幅度为±1的周期性方波。duty表示占空比。

clear;

td=1/100000;    % td - 时间间隔

t = 0:td:1;

x1 = square(2*pi*40*t, 25);

x2 = square(2*pi*40*t, 50);

x3 = square(2*pi*40*t, 75);

subplot(311);td1=plot(t,x1);set(td1,'linewidth',2);

title('占空比 25%'); axis([0 0.1 -1.5 1.5]);grid;

subplot(312);td2=plot(t,x2);set(td2,'linewidth',2);

title('占空比 50%'); axis([0 0.1 -1.5 1.5]);grid;

subplot(313);td3=plot(t,x3);set(td3,'linewidth',2);

title('占空比 75%'); axis([0 0.1 -1.5 1.5]);grid

% ------------------------------------------------------------
http://s2/middle/59a069d5gc44883a74451&690
% filename: zht_ex_4_8_p75.m
% 产生一个幅度为1、宽度为width、以t=0为中心左右对称的矩形波信号。
% 该函数横坐标范围由向量t决定,其矩形波形是以t=0为中心向左右各展开
% width/2的范围。width的默认值为1.
% 调用格式:x=rectpuls(t,width)
% 【例题4-8】 生成幅度为2,宽度T=4、中心在t=0的矩形波x(t)以及x(t-T/2).

clear;
td=1/10000;    % td - 时间间隔
t = -4:td:4; 
T =4;
x1 = 2*rectpuls(t, T);
x2 = 2*rectpuls(t-T/2, T);
subplot(121);td1=plot(t,x1);set(td1,'linewidth',2);
title('x(t)'); axis([-4 6 0 2.2]);grid;
subplot(122);td2=plot(t,x2);set(td2,'linewidth',2);
title('x(t-T/2)'); axis([-4 6 0 2.2]);grid;
% -------------------------------------------------------------------
http://s3/middle/59a069d5gc448c50f1892&690
% filename: zht_ex_4_9_p77.m
% 功能:产生一个抽样函数,其值为sinx/x。
% 调用格式:x=sinc(x)
% 【例题4-9】 生成抽样信号Sa(at)  ( a=2π).

clear;
td=1/1000;    % td - 时间间隔
t = -1:td:1; 
y = sinc(2*pi*t);
td1=plot(t,y);set(td1,'linewidth',2);
xlabel('时间t'); ylabel('幅度值(y)');
title('抽样信号Sinc(x)=Sin(x)/x')
%----------------------------------------------------------


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有