许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  常用序列的MATLAB代码(一):单位冲激、阶跃等

常用序列的MATLAB代码(一):单位冲激、阶跃等

阅读数 6
点赞 0
article_banner


1、典型序列 函数

1)单位冲激序列

function[x,n] = impseq(n0,ns,nf)
% ns=序列的起点;nf=序列的终点;n0=序列在n0处有一个单位脉冲。
% x=产生的单位采样序列;n=产生序列的位置信息
n = [ns:nf];
x = [(n-n0)==0];

2)单位阶跃序列
function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n,n0 <= n2
% ------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
if ((n0 < n1) | (n0 > n2) | (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
n = [n1:n2];
%x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))];
x = [(n-n0) >= 0];

2、基本运算函数

1)加法函数

function [y,n] = sigadd(x1,n1,x2,n2)
% implements y(n) = x1(n)+x2(n)
% -----------------------------
% [y,n] = sigadd(x1,n1,x2,n2)
% y = sum sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n)
y1 = zeros(1,length(n)); y2 = y1;
% initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1+y2;
% sequence addition


2)反折函数
function [y,n]=sigfold(x,n)
% implements y(n) = x(-n)
% -----------------------------
% [y,n] = sigfold(x,n)
y=fliplr(x);
n=-fliplr(n);


3)乘法函数
function [y,n] = sigmult(x1,n1,x2,n2)
% implements y(n) = x1(n)*x2(n)
% -----------------------------
% [y,n] = sigmult(x1,n1,x2,n2)
% y = produce sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n)
y1 = zeros(1,length(n)); y2 = y1;
% initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1.*y2;
% sequence multiplication


4)移位函数
function [y,n]=sigshift(x,m,n0)
% implements y(n) = x(n-n0)
% -----------------------------
% [y,n] = sigshift(x,m,n0)
n=m+n0;
y=x;

///////////************************************************************////////////

例1:

在这里插入图片描述
代码:

%1.1
clc
clear
close all

n = [0:25];
x=0;
for m=0:10
    x=x+(m+1)*(impseq(2*m,0,25)-impseq(2*m+1,0,25));
end
stem(n,x);
xlabel('n');ylabel('x(n)');
%ylim([-2,3]);

运行结果:
在这里插入图片描述

例2:在这里插入图片描述

代码:

clc
clear
close all
 
n = [-10:10];
x1 = n.*n.*(stepseq(-5,-10,10) - stepseq(6,-10,10));
x2=10*impseq(0,-10,10);
x3 = 20*0.5.^n.*(stepseq(4,-10,10) - stepseq(10,-10,10));
x = x1+x2+x3;
stem(n,x);
xlabel('n');ylabel('x(n)');
%ylim([0,50]);

运行结果:
在这里插入图片描述

例3:

在这里插入图片描述

代码:

clc
clear
close all
 
n = [0:20];
x =0.9.^n.*(cos(0.2 * pi * n+pi/3));
stem(n,x,'r');
xlabel('n');
ylabel('x(n)');

运行结果:
在这里插入图片描述
注:

1、clc:清除命令窗口的内容,对工作环境中的全部变量无任何影响 2、clear:清除工作空间的所有变量 3、close all:关闭所有的Figure窗口 4、stem(n,x,‘r’);函数的第三个入口参数为绘制线的颜色,“r”表示红色 “k”为黑色,默认浅蓝色。


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空