1、程序:
>> t=-1:0.001:1;>>y=-3*heaviside(2*t-1);>>plot(t,y)>>axis([-1,1,-5,5]);-1-0.8-0.6-0.4-0.2 0 0.2 0.4 0.6 0.8 1-5-4-3-2-1012345 2、程序:
t=-2:0.001:2;x=exp(-0.5*t).*heaviside(t);plot(t,x)axis([-1,3,-0.2,1.6]);-1-0.5 0 0.5 1 1.5 2 2.5 3-0.200.20.40.60.811.21.41.6 3、程序:
t=-4:0.001:2;y=exp(-0.5*(1.5*t+3)).*heaviside(1.5*t+3);plot(t,y)axis([-3,3,-1,2]);
-3-2-1 0 1 2 3-1-0.500.511.52(一)产生信号波形的方法 a.产生正弦波 >> t=0:0.01:3*pi;>> y=sin(2*t);>> plot(t,y)0 1 2 3 4 5 6 7 8 9 10-1-0.8-0.6-0.4-0.200.20.40.60.81 b.产生叠加随机噪声的正弦波:
>> t=0:0.01:3*pi;>>y=10*sin(2*t);>>s=y+randn(size(t));>>plot(t,s)0 1 2 3 4 5 6 7 8 9 10-15-10-5051015 c.产生周期方波:
>>t=0:0.01:1;
>>y=square(4*pi*t);>>plot(t,y)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1-0.8-0.6-0.4-0.200.20.40.60.81 d.产生周期锯齿波 >> t=(0:0.001:2.5);>>y=sawtooth(2*pi*30*t);>>plot(t,y),axis([0 0.2-1 1])0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2-1-0.8-0.6-0.4-0.200.20.40.60.81 e.产生 sinc 函数:
>> x=linspace(-5,5);>>y=sinc(x);>>plot(x,y)-5-4-3-2-1 0 1 2 3 4 5-0.4-0.200.20.40.60.81 f.产生指数函数波形:
>> x=linspace(0,1,100);
>> y=exp(-x);>> plot(x,y)0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10.40.50.60.70.80.91(二)信号的运算 1 加 乘运算 t=0:0.01:2;f1=exp(-3*t);f2=0.2*sin(4*pi*t);f3=f1+f2;f4=f1.*f2;subplot(2,2,1);plot(t,f1);title("f1(t)");subplot(2,2,2);plot(t,f2);title("f2(t)");subplot(2,2,3);plot(t,f3);title("f1+f2");subplot(2,2,4);plot(t,f4);title("f1*f2");0 0.5 1 1.5 200.20.40.60.81f1(t)0 0.5 1 1.5 2-0.2-0.100.10.2f2(t)0 0.5 1 1.5 2-0.500.51f1+f20 0.5 1 1.5 2-0.100.10.20.3f1*f2 2 变换: syms t;f=sym("sin(t)/t");f1=subs(f,t,t+3);f2=subs(f1,t,2*t);f3=subs(f2,t,-t);subplot(2,2,1);ezplot(f1,[-8,8]);grid on;subplot(2,2,2);ezplot(f2,[-8,8]);grid on;
subplot(2,2,3);ezplot(f3,[-8,8]);grid on;subplot(2,2,4);ezplot(f4,[-8,8]);grid on;-5 0 500.51tsin(t+3)/(t+3)-5 0 5-0.200.20.40.60.8tsin(2 t+3)/(2 t+3)-5 0 5-0.200.20.40.60.8t-sin(2 t-3)/(-2 t+3)0 0.5 1 1.5 2-0.100.10.20.3f1*f2(三)卷积运算 二个方波信号的卷积 y1=[ones(1,20),zeros(1,20)];y2=[ones(1,10),zeros(1,20)];y=conv(y1,y2);n1=1:length(y1);n2=1:length(y2);L=length(y)subplot(3,1,1);plot(n1,y1);axis([1,L,0,2]);subplot(3,1,2);plot(n2,y2);axis([1,L,0,2]);n=1:L;subplot(3,1,3);plot(n,y);axis([1,L,0,20]);10 20 30 40 50 6001210 20 30 40 50 6001210 20 30 40 50 6001020 二个指数信号的卷积 t=0:0.01:1;y1=exp(-6*t);y2=exp(-3*t);y=conv(y1,y2);
l1=length(y1);l2=length(y2);l=length(y);subplot(3,1,1);plot(t,y1);subplot(3,1,2);plot(t,y2);t1=0:0.01:2;subplot(3,1,3);plot(t1,y);0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.510 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.510 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20510