Demodulation of a data
Think of the widely spaced pulses as missing a pulse.

The rising edge of the bottom signal would be where you detect no missing pulse. (marked in red)

The falling edge would be when the pulse start to miss again. (marked in yellow) 

The resulting waveform would have ~66% duty cycle.

The blue line is midpoint between the red lines and its position would have to be calculated (if you want 50% duty cycle).

If you  want a waveform with 50% duty cycle, then you could also have the falling edge at the first pulse after a wide space, then count pulses to obtain the rising edge. (purple waveform)