单位冲激序列
function dwxl(k1,k2,k0) %定义函数
k=k1:k2;
n=length(k);
f=zeros(1,n);
f(1,-k0-k1+1)=1; %在k0时刻,信号赋值为1
stem(k,f,'filled') %以实心的方式
axis([k1,k2,0,1.5]) %限制X,Y轴范围
title('单位序列')
单位阶跃序列
function jyxl(k1,k2,k0)
k=k1:-k0-1;
kk=-k0:k2;
n=length(k);
nn=length(kk);
u=zeros(1,n);
uu=ones(1,nn);
stem(kk,uu,'filled')
hold on
stem(k,u,'filled')
hold off
axis([k1,k2,0,1.5])
title('单位阶跃序列')
正弦序列
k=0:40;
subplot(2,1,1)
stem(k,cos(k*pi/8),'filled')
title('cos(k*pi/8)')
subplot(2,1,2)
stem(k,cos(2*k),'filled')
title('cos(2*k)')
图像:
指数序列
function dszs(c,a,k1,k2) %幅度 底数 起始序号 终止序号
k=k1:k2;
x=c*(a.^k);
stem(k,x,'filled')
hold on
plot([k1,k2],[0,0])
hold off
离散序列相加
function[f,k]=lsadd(f1,f2,k1,k2)
k=min(min(k1),min(k2)):max(max(k1),max(k2));
s1=zeros(1,length(k));
s2=s1;
s1(find((k>=min(k1))&(k<=max(k1))==1))=f1;
s2(find((k>=min(k2))&(k<=max(k2))==1))=f2;
f=s1+s2;
stem(k,f,'filled')
axis([(min(min(k1),min(k2)-1)),(max(max(k1),max(k2))+1),(min(f)-0.5),(max(f)+0.5)])
离散序列相乘
function[f,k]=lsmul(f1,f2,k1,k2)
k=min(min(k1),min(k2)):max(max(k1),max(k2));
s1=zeros(1,length(k));
s2=s1;
s1(find((k>=min(k1))&(k<=max(k1))==1))=f1;
s2(find((k>=min(k2))&(k<=max(k2))==1))=f2;
f=s1.*s2;
stem(k,f,'filled')
axis([(min(min(k1),min(k2)-1)),(max(max(k1),max(k2))+1),(min(f)-0.5),(max(f)+0.5)])
离散序列反褶
function[f,k]=lsfz(f1,k1)
f=fliplr(f1);
k=-fliplr(k1);
stem(k,f,'filled')
axis([min(k)-1,max(k)+1,min(f)-0.5,max(f)+0.5])
离散序列平移
function[f,k]=lsyw(ff,kk,k0)
k=kk+k0;
f=ff;
stem(k,f,'filled')
axis([min(k)-1,max(k)+1,min(f)-0.5,max(f)+0.5])
离散序列的倒相变换
function[f,k]=lsdx(ff,kk)
k=kk;
f=-ff;
stem(k,f,'filled')
axis([min(k)-1,max(k)+1,min(f)-0.5,max(f)+0.5])
例题:
实现代码
k=-4:5
f=[0,0,1,2,3,3,3,3,0,0]
stem(k,f,'filled')
subplot(2,3,1)
axis([min(k)-1,max(k)+1,min(f)-0.5,max(f)+0.5])
title('f(k)');
subplot(2,3,2)
[f1,k1]=lsyw(f,k,2);
g=[zeros(1,4),ones(1,6)] %g=jyxl(-2,3,0)报错
lsmul(f1,g,k1,k)
title('f(k-2)u(k)');
subplot(2,3,3)
[f2,k2]=lsfz(f,k);
title('f(-k)');
subplot(2,3,4)
[f3,k3]=lsyw(f2,k2,-2);
title('f(-k+2)');
subplot(2,3,5)
[g1,k4]=lsyw(g,k,2)
lsmul(f1,g1,k1,k4)
title('f(k-2)u(k-2)');
图像: