I'm trying to model a pulse waveform in my application and I need a way to keep track of the pulses so that I can repeat their sequence. From the figure shown below, what I'd like to do is simulate the first three pulses (pulse 1-3), then simulate pulse 4 immediately after pulse 3, and simulate pulse 5 immediately after 4. Then repeat the whole sequence N times.
As shown in the diagram, I have the interval in seconds, the start time of the first pulse in seconds, and the duration of each pulse also in seconds. My application will be running real time in a run loop where it will be executing at 1 Hz.
My question is, how do I keep track of all the pulses and make sure they are all simulated with respect to each other? What I mean by simulated is, for example I'd like to print a simple statement during the duration of the 1st three pulses, and the same for pulse 4 and 5. Can someone suggest a pseudo algorithm at the very least for this operation?
Defining the class
sequence
as follows, we can simply check activity of each pulse bysequence::isActive
. DEMO is here.