MATLAB: How to generate a pulse train which starts at the origin using functions in the Signal Processing Toolbox 6.10 (R2008b)

offsetoriginpulsespulstranrectangularSignal Processing Toolbox

I am trying to generate a train of rectangular pulses. I want the train to start at the origin (t=0) and would like to know how to do this using functions in Signal Processing Toolbox 6.10 (R2008b).

Best Answer

This can be done using the PULSTRAN function in the Signal Processing Toolbox.
As mentioned in the Signal Processing Toolbox 6.10 (R2008b) documentation, the default 'rectpuls' function extends from -0.5 to 0.5. Additionally, the PULSTRAN function returns "func(t-d(1))+func(t-d(2)) +...", where 't' and 'd' are the time and delay vectors respectively. Thus, the number of "pulses" in the "train" will be the same as the number of elements in 'd'.
In order to generate pulses that do not overlap, the elements of 'd' must be greater than the pulse width (which is 1 by default for the 'rectpuls' function). Therefore, as an example, the first term should be "func(t-0.5)" so that the train of rectangular pulses starts at "t=0". In other words, the first element of 'd' must be half the width of the function (i.e. 'rectpuls') if the pulse train is to start at "t=0".
The following code is an example of how this can be implemented:
t=0:.01:10; %Time vector
w = 1; %pulse width
d= w/2:w*2:10; %delay vector
y2=pulstran(t,d,'rectpuls',w);
plot(t,y2);
set(gca,'Ylim',[-0.1 1.1]);