基于信号在MATLAB中的表示和运算
连续信号的MATLAB表示
表示连续信号有两种方法:
1.数值法.(定义某一时间范围和取样时间间隔,然后调用该函数计算这些点的函数值,得到两组矢量值,绘图语句绘制波形)
2.符号法.(利用M的符号运算功能,需定义符号变量和符号函数,运算结果是符号函数解析式,可以绘出波形)
例1-1指数函数
A = 1; a = -0.4;
t = 0: 0.01: 10;
ft = A * exp( a * t );
plot( t, ft);
grid on;
例1-2正弦信号(sin)
A = 1; w = 2 * pi; phi = pi / 6;
t = 0: 0.01: 8;
ft = A * sin( w * t + phi );
plot( t, ft );
例1-3抽样信号(sinc)
t = -3 * pi : pi / 100 : 3 * pi;
ft = sinc( t / pi );
plot( t, ft );
grid on;
axis( [ -10, 10, -0.5, 1.2] );%定义画图范围,横轴,纵轴
title( ‘抽样信号’)
例1-4虚指数信号( f=exp( ( j * b ) * t )
t = 0 : 0.01 : 15;
w = pi / 4 ;
X = exp( j * w * t );
Xr = real( X );
Xi = imag( X );
Xa = abs ( X );
Xn = angle ( X );
%subplot是将多个图画到一个平面subplot(m行,n列,figure位置)
subplot ( 2, 2, 1 ), plot( t, Xr ), axis( [ 0, 15, -( max( Xa ) + 0.5 ), max( Xa ) + 0.5 ] );
title( ‘实部’ );
subplot ( 2, 2, 3 ), plot( t, Xi ), axis( [ 0, 15, -( max( Xa ) + 0.5 ), max( Xa ) + 0.5 ] );
title( ‘虚部’ );
subplot ( 2, 2, 2 ), plot( t, Xa ), axis( [ 0, 15, 0 , max( Xa ) + 1 ] );
title( ‘模’ );
subplot ( 2, 2, 4 ), plot( t, Xn ), axis( [ 0, 15, -( max( Xn ) + 1 ) , max( Xn ) + 1 ] );
title( ‘相角’ );
例1-5复指数信号( f=exp( ( a + j * b ) * t ) )
t = 0 : 0.01 : 3;
a = -1;
b = 10;
f = exp( ( a + b * j ) * t );
subplot( 2, 2, 1 ), plot( t, real( f ) ), title( ‘实部’ );
subplot( 2, 2, 3 ), plot( t, imag( f ) ), title( ‘虚部’ );
subplot( 2, 2, 2 ), plot( t, abs( f ) ), title( ‘模’ );
subplot( 2, 2, 4 ), plot( t, angle( f ) ), title( ‘相角’ );
例1-6矩形脉冲(rectpuls)
t = -2 : 0.01 : 2;
width = 1;
ft = 2 * rectpuls( t, width );%rectpilse幅值为1,宽度width
plot( t, ft );
grid on;
例1-7单位阶跃信号(ft = ( t > 0 ))
t= -1 : 0.01 : 5;
ft = ( t >= 0 );
plot( t, ft );
grid on;
axis( [ -1, 5, -0.5, 1.5 ] );
例1-8正弦信号符号运算
syms t %定义符号变量
y = sin( pi / 4 * t ); %符号函数表达式
ezplot( y,[ -16, 16 ] ); %符号函数画图命令
例1-9单位阶跃信号(Heaviside)
heaviside.m文件
function f = Heaviside(t)
f = ( t >= 0 );
命令行
t = -1 : 0.01 : 3;
f = heaviside( t );
plot( t, f );
axis( [ -1, 3, -0.2, 2 ] );
信号基本运算符的MATLAB实现(乘法、加法、平移、尺度、反转、微分、积分)
例1-11 f(t)–> f (2t)、f(2-2t)
t = -3 : 0.01 : 3;
ft = tripuls( t, 4 ,0.5 );%非周期三角波(时间,宽度,斜率)
subplot( 3, 1, 1);
plot( t, ft );
grid on;
title( ‘f(t)’ );
ft1 = tripuls( 2 * t, 4, 0.5 );
subplot( 3, 1, 2 );
plot( t, ft1 );
grid on;
title( ‘f(2t)’ );
ft2 = tripuls( 2 - 2 * t, 4, 0.5 );
subplot( 3, 1, 3 );
plot( t, ft2 );
grid on;
title( ‘f(2t)’ );
例1-12 f1(t) 、 f2(t)—> f1(t) +f2(t)、 f1(t)* f2(t)
w = 2 * pi;
t = 0 : 0.01 : 3;
f1 = sin( w * t );
f2 = sin ( 8 * w * t );
subplot( 2, 1, 1 );
plot( t, f1 + 1, ‘:’, t, f1 - 1,’:’, t, f1 + f2 );
grid on;
title( ‘f1(t) + f2(t)’ );
subplot( 2, 1, 2 );
plot( t, f1 , ‘:’, t, -f1, ‘:’, t, f1 .* f2 );
grid on;
title( ‘f1(t) * f2(t)’ );
例1-13求一阶导数
微分diff( function, ‘variable’,n)
积分int(function,‘variable’,a,b)
function为函数,variable运算(求导积分)变量,n求导阶数,a积分下限,b积分上限
syms a x y1 y2
y1 = sin( a * x^2 );
y2 = x * sin( x ) * log( x );
dy1 = diff( y1, ‘x’ )
dy2 = diff( y2, ‘x’ )
例1-14求积分
syms a x y1 y2%符号变量
y1 = x^5 - a * x + sqrt( x ) / 2;
y2 = ( x * exp( x ) ) / ( 1 + x )^2;
iy1 = int( y1, ‘x’ )
iy2 = int( y2, ‘x’, 0, 1)
课后习题
2.1
A = -1; a = -2;
t = 0: 0.01: 10;
ft1 = 2 + A * exp( a * t );
ft2 = ( t >= 0 );
ft3 = ft1 .* ft2;
plot( t, ft3 );
grid on;
2.2
w = pi;
t = -1 : 0.01 : 8;
ft1 = 1 + cos( w * t);
ft2 = ( t >= 0 );
ft3 = ( ( t - 2 ) >= 0 );
ft4 = ft1 .* ( ft2 - ft3 );
plot( t, ft4 );
grid on;
3
A = -1; a = -2;
t = 0: 0.01: 10;
ft1 = 2 + A * exp( a * t );
ft2 = ( t >= 0 );
ft3 = ft1 .* ft2;
subplot ( 2, 2, 1 ), plot( t, ft3 ),grid on;;
title( ‘f(t)’ );
ft4 = 2 + A * exp( a * 2 * t );
ft5 = ( 2 * t >= 0 );
ft6 = ft4 .* ft5;
subplot ( 2, 2, 2 ), plot( t, ft6 ),grid on;;
title( ‘f(2t)’ );
ft7 = 2 + A * exp( a * (2 - t) );
ft8 = ( (2 - t ) >= 0 );
ft9 = ft7 .* ft8;
subplot ( 2, 2, 3 ), plot( t, ft9 ),grid on;;
title( ‘f(2-t)’ );