%复指数序列
close all;clc;
n=-20:20;x=exp((0.05+1i*pi/4)*n);
xr=real(x);xi=imag(x);xamp=abs(x);xpha=angle(x);subplot(2,2,1);stem(n,xr,'.');axis([-2323-33]);xlabel('n');ylabel('xr');title('实部');subplot(2,2,2);stem(n,xi,'.');axis([-2323-33]);xlabel('n');ylabel('xi');title('虚部');subplot(2,2,3);stem(n,xamp,'.');axis([-2323-0.13]);xlabel('n');ylabel('xamp');title('幅值');subplot(2,2,4);stem(n,xpha,'.');axis([-2323-44]);xlabel('n');ylabel('xamp');title('相位');
%离散序列相加和相乘
close all;clc;
n1=-2:2;x1=[-12-314];
n2=0:3;x2=[2-32-3];%把计算用的序列调整到相同长度
n=min(min(n1),min(n2)):max(max(n1),max(n2));
x11=zeros(1,length(n));x22=zeros(1,length(n));x11((n>=min(n1))&(n<=max(n1)))=x1;x22((n>=min(n2))&(n<=max(n2)))=x2;
xa=x11+x22;
xm=x11.*x22;subplot(2,2,1);stem(n,x11);axis([-34-45]);xlabel('n');ylabel('x11(n)');title('x1(n)的扩展序列');subplot(2,2,2);stem(n,x22);axis([-34-43]);xlabel('n');ylabel('x22(n)');title('x2(n)的扩展序列');subplot(2,2,3);stem(n,xa);axis([-34-47]);xlabel('n');ylabel('xa(n)');title('x1+x2');subplot(2,2,4);stem(n,xm);axis([-34-79]);xlabel('n');ylabel('xm(n)');title('x1*x2');
%序列翻转
close all;clc;
nx=-2:5;x=[12345678];
ny=-fliplr(nx);%翻转函数
y=fliplr(x);subplot(2,1,1);stem(nx,x,'.');axis([-66-19]);grid;xlabel('n');ylabel('x(n)');title('原序列');subplot(2,1,2);stem(ny,y,'.');axis([-66-19]);grid;xlabel('n');ylabel('y(n)');title('翻转后序列');
%序列移位
close all;clc;
nx=-2:5;x=[12345555];
y=x;ny1=nx+3;ny2=nx-2;subplot(1,2,1);stem(nx,x,'.');axis([-59-16]);grid;xlabel('n');ylabel('x(n)');title('原序列');subplot(2,2,2);stem(ny1,y,'.');axis([-59-16]);grid;xlabel('n');ylabel('y1(n)');title('右移三位序列');%这里左右容易错
subplot(2,2,4);stem(ny2,y,'.');axis([-59-16]);grid;xlabel('n');ylabel('y2(n)');title('左移两位序列');
%尺度变换
close all;clc;
nx=-4:3;x=[12345678];
m1=2;m2=3;[ny1,y1,ny2,y2]=SeqCDBH(nx,x,m1);[ny3,y3,ny4,y4]=SeqCDBH(nx,x,m2);subplot(1,2,1);stem(nx,x,'.');axis([-97-19]);grid;xlabel('n');ylabel('x(n)');title('原序列');subplot(2,2,2);stem(ny1,y1,'.');axis([-97-19]);grid;xlabel('n');ylabel('y1(n)');title('2倍抽取后的序列');subplot(2,2,4);stem(ny2,y2,'.');axis([-97-19]);grid;xlabel('n');ylabel('y2(n)');title('2倍插值后的序列');set(gcf,'color','w');
figure
subplot(1,2,1);stem(nx,x,'.');axis([-1310-19]);grid;xlabel('n');ylabel('x(n)');title('原序列');subplot(2,2,2);stem(ny3,y3,'.');axis([-1310-19]);grid;xlabel('n');ylabel('y3(n)');title('3倍抽取后的序列');subplot(2,2,4);stem(ny4,y4,'.');axis([-1310-19]);grid;xlabel('n');ylabel('y2(n)');title('3倍插值后的序列');set(gcf,'color','w');