【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls

这个函数在MATLAB的帮助文档中,称为采样非周期矩形波(Sampled aperiodic rectangle),说白了,也就是一个矩形脉冲,你可以通过该函数控制脉冲的位置,以及脉冲的宽度等。

语法:

【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls

帮助文档对这两种语法形式的描述为:

y = rectpuls(t) returns a continuous, aperiodic, unity-height rectangular pulse at the sample times indicated in array t, centered about t = 0 and with a default width of 1. Note that the interval of nonzero amplitude is defined to be open on the right, that is, rectpuls(-0.5) = 1 while rectpuls(0.5) = 0.

y = rectpuls(t,w) generates a rectangle of width w.

不仔细分析还真的让人看不太懂,我简单的理解下,然后用例子说明:

y = rectpuls(t)返回一个连续的、非周期的、单位高度的矩形脉冲,数组t指示了矩形脉冲显示在多大的一个时间范围内,矩形脉冲的中心位于 t = 0时刻,默认的脉宽为1.最后需要说明的是,矩形脉冲的非零幅度值位于区间[-0.5,0.5)内,注意是左闭右开。

如下:

t = -1:.5:1

【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls

x = rectpuls(t)

【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls

可见,t = -0.5时,x = 1;t = 0.5, x = 0。

作个小图来看看:

clc
clear
close all

fs = 10e3;
t = -1:1/fs:1;

x = rectpuls(t);



plot(t,x);
ylim([-0.2 1.2])
xlabel('t/s');
ylabel('amplititude');
title('rectpuls');

【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls

明白了吧。

y = rectpuls(t,w) ,这种语法形式,只不过指定了该矩形脉冲的位宽,其他和上一种形式一样。

给一个例子:

% Generate 200 ms of a rectangular pulse with a sample rate of 10 kHz and a width of 20 ms.

clc
clear
close all

fs = 10e3;
t = -0.1:1/fs:0.1;
w = 20e-3;
x = rectpuls(t,w);

% One displaced 45 ms into the past.
tpast = -45e-3;
xpast = rectpuls(t-tpast,w);

% One displaced 60 ms into the future and half as wide.
tfutr = 60e-3;
xfutr = rectpuls(t-tfutr,w/2);

% Plot the original pulse and the two copies on the same axes.
plot(t,x,t,xpast,t,xfutr)
ylim([-0.2 1.2])
xlabel('t/s');
ylabel('amplititude');
title('rectpuls');

%add legend for the above function
lgd = legend('now', 'past', 'further');
lgd.Location = 'northwest';
title(lgd,'my legend title');
legend boxoff

【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls


画了这张图,才发现,如果改变一下,像这样:

【 MATLAB 】信号处理工具箱之波形产生函数 rectpuls

多么像无奈的友情或者爱情呀,从肥到瘦,曾经的热情像火焰般点燃,到最后只留被灼伤的自我。

就这样吧!