How do I generate a pulse train which starts at the origin using functions in the Signal Processing Toolbox 6.10 (R2008b) ?
33 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2012-8-10
编辑: MathWorks Support Team
2022-11-16
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).
采纳的回答
MathWorks Support Team
2012-8-10
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]);
0 个评论
更多回答(1 个)
Sriram Narayanan
2014-9-25
编辑:MathWorks Support Team
2022-11-16
Please note that the above pulse is in fact in discrete-form as you can infer from the time vector "t" which is sampled at 100 hz (0.01s) for 10 seconds of signal length. Therefore, if your sample rate is denoted by "fs" and the signal duration is "tend", you would define a time vector t as:
fs = 1e3; %1KHz sample rate
tend = 1; % duration of signal
t = 0:1/fs:tend; % time vector
For a repetition frequency of 3 Hz and pulse width of 0.1s, we can define the delay vector as:
repfreq = 3; %3 Hz w = 0.1; % 0.1s pulse width
d = 0:1/repfreq:tend % Delay starts at t = 0 and therefore the pulse function is evaluated length(d) times
Please note here that delay vector is an arbitrary vector that defines the number of times the pulse function is evaluated and may also be defined in terms of being a multiple of the pulse width as you see above.
Finally, we can call the PULSTRAN function with appropriate arguments as follows:
y = pulstran(t,d,'rectpuls',w);
The documentation for PULSTRAN function below also explains in greater detail about how the "delay" vector is defined.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!