2.离散序列的表示与基本运算(一)

%离散时间信号的表示
clear all;close all;clc;
n=-8:8;
x=0.8.^n;
subplot(1,2,1),stem(n,x,'.');
xlabel('n');ylabel('x(n)');title('线图');axis([-10 10 -0.5 6.5]);
subplot(1,2,2),plot(n,x);
xlabel('n');ylabel('x(n)');title('包络图');axis([-10 10 -0.5 6.5]);
line([-10,10],[0,0]);
set(gcf,'color','w')

在这里插入图片描述

%单位冲激序列
close all;clc;
n=0:15;
x1=[1 zeros(1,15)];
x2=[(n-5)==0];
subplot(1,2,1),stem(n,x1);
grid;xlabel('n');ylabel('x1');title('delta(n)线图');
axis([-1 16 -0.1 1.1]);line([-1 16],[0,0]);
subplot(1,2,2),stem(n,x2);
grid;xlabel('n');ylabel('x2');title('delta(n-5)线图');
axis([-1 16 -0.1 1.1]);line([-1 16],[0,0]);
set(gcf,'color','w');

在这里插入图片描述

%单位阶跃序列
close all;clc;
n=-5:15;
x1=[zeros(1,5),ones(1,16)];
x2=[(n-5)>=0];
subplot(1,2,1),stem(n,x1);
grid;xlabel('n');ylabel('x1');title('u(n)线图');
axis([-6 16 -0.1 1.1]);line([-1 16],[0,0]);
subplot(1,2,2),stem(n,x2);
grid;xlabel('n');ylabel('x2');title('u(n-5)线图');
axis([-6 16 -0.1 1.1]);line([-1 16],[0,0]);
set(gcf,'color','w');

在这里插入图片描述

%矩形序列
close all;clc;
n=-5:10;
R8=[(n>=0)&(n-7)<=0];
stem(n,R8);
grid;xlabel('n');ylabel('x1');title('R8(n)线图');
axis([-6 12 -0.1 1.1]);line([-1 12],[0,0]);
set(gcf,'color','w');

在这里插入图片描述

%正弦序列
clear all;clc;
n=-21:21;x=2*sin(0.2*pi*n+2*pi/3);
n1=-21:0.01:21;x1=2*sin(0.2*pi*n1+2*pi/3);
stem(n,x,'.');hold on;plot(n1,x1,'--');
xlabel('n');ylabel('x(n)');title('线图');
axis([-23.5 23.5 -2.1 2.1]);set(gcf,'color','r');

在这里插入图片描述

%复指数序列
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([-23 23 -3 3]);
xlabel('n');ylabel('xr');title('实部');
subplot(2,2,2);stem(n,xi,'.');axis([-23 23 -3 3]);
xlabel('n');ylabel('xi');title('虚部');
subplot(2,2,3);stem(n,xamp,'.');axis([-23 23 -0.1 3]);
xlabel('n');ylabel('xamp');title('幅值');
subplot(2,2,4);stem(n,xpha,'.');axis([-23 23 -4 4]);
xlabel('n');ylabel('xamp');title('相位');

在这里插入图片描述

%离散序列相加和相乘
close all;clc;
n1=-2:2;x1=[-1 2 -3 1 4];
n2=0:3;x2=[2 -3 2 -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([-3 4 -4 5]);
xlabel('n');ylabel('x11(n)');title('x1(n)的扩展序列');
subplot(2,2,2);stem(n,x22);axis([-3 4 -4 3]);
xlabel('n');ylabel('x22(n)');title('x2(n)的扩展序列');
subplot(2,2,3);stem(n,xa);axis([-3 4 -4 7]);
xlabel('n');ylabel('xa(n)');title('x1+x2');
subplot(2,2,4); stem(n,xm); axis([-3 4 -7 9]);
xlabel('n');ylabel('xm(n)');title('x1*x2');


在这里插入图片描述

%序列翻转
close all;clc;
nx=-2:5;x=[1 2 3 4 5 6 7 8];
ny=-fliplr(nx);%翻转函数
y=fliplr(x);
subplot(2,1,1);stem(nx,x,'.');axis([-6 6 -1 9]);grid;
xlabel('n');ylabel('x(n)');title('原序列');
subplot(2,1,2);stem(ny,y,'.');axis([-6 6 -1 9]);grid;
xlabel('n');ylabel('y(n)');title('翻转后序列');

在这里插入图片描述

%序列移位
close all;clc;
nx=-2:5;x=[1 2 3 4 5 5 5 5];
y=x;ny1=nx+3;ny2=nx-2;
subplot(1,2,1);stem(nx,x,'.');axis([-5 9 -1 6]);grid;
xlabel('n');ylabel('x(n)');title('原序列');
subplot(2,2,2);stem(ny1,y,'.');axis([-5 9 -1 6]);grid;
xlabel('n');ylabel('y1(n)');title('右移三位序列');%这里左右容易错
subplot(2,2,4);stem(ny2,y,'.');axis([-5 9 -1 6]);grid;
xlabel('n');ylabel('y2(n)');title('左移两位序列');

在这里插入图片描述

%尺度变换
close all;clc;
nx=-4:3;x=[1 2 3 4 5 6 7 8];
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([-9 7 -1 9]);grid;
xlabel('n');ylabel('x(n)');title('原序列');
subplot(2,2,2);stem(ny1,y1,'.');axis([-9 7 -1 9]);grid;
xlabel('n');ylabel('y1(n)');title('2倍抽取后的序列');
subplot(2,2,4);stem(ny2,y2,'.');axis([-9 7 -1 9]);grid;
xlabel('n');ylabel('y2(n)');title('2倍插值后的序列');
set(gcf,'color','w');
figure
subplot(1,2,1);stem(nx,x,'.');axis([-13 10 -1 9]);grid;
xlabel('n');ylabel('x(n)');title('原序列');
subplot(2,2,2);stem(ny3,y3,'.');axis([-13 10 -1 9]);grid;
xlabel('n');ylabel('y3(n)');title('3倍抽取后的序列');
subplot(2,2,4);stem(ny4,y4,'.');axis([-13 10 -1 9]);grid;
xlabel('n');ylabel('y2(n)');title('3倍插值后的序列');
set(gcf,'color','w');

在这里插入图片描述

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值