Hi,
If the upper waveform is not deterministic and known in advance the lower pattern can not be generated. I guess you want this related to pulse width modulation?
If so, you can use a symmetrical PWM block from the PLECS library and just modify the input index m of the block. Similar to the attached model.
Best regards,
NF
modulator.plecs (7.32 KB)