[英]create discrete step function in matlab
这是Matlab文档中Heaveside step函数的定义。
heaviside(x)对于x <0返回值0,对于x> 0返回1,对于x = 0返回1/2。
注意该积分的结果,以查看实现是否正确:
syms x
int(exp(-x)*heaviside(x), x, -Inf, Inf)
希望这些功能对您有所帮助,您要找的是最后一个!
%% Functions
function y=us(t) % continuous time unit step function
y=(sign(t)+1)/2;
end
function y=rect(t) % continuous time unit rectangle function
y=us(t+0.5) - us(t-0.5);
end
function y=tri(t) % continuous time unit triangle function
y = (t+1).*rect(t+0.5) + (-t+1).*rect(t-0.5);
end
function y=usD(n) % Discrete time unit step, n must be an integer!
y = 1.*(n>=0);
end
请注意, heaviside
是在符号库中定义的,它主要用于连续计算,例如符号积分,傅立叶变换等。 您也可以在离散设置中使用它,但是是否需要x=0
的行为取决于应用程序。
创建步进函数(没有任何工具箱)的更简单方法是:
step1 = @(x) x>=0;
step2 = @(x) (sign(x)+1)/2;
figure(1);clf;
stem(-5:5,step1(-5:5));
hold on;
stem(-5:5,step2(-5:5),'rx');
而第一个在x=0
处从0跳到1,而第二个则类似于heaviside
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.