I have power data from a cycling power meter (this is only required for context, not for the mechanics of the problem) which looks somewhat stochastic. See attached image. power_image
This is a typical session which is based on a set of target 'levels' which are straight line targets of the power output required (so would look like a series of blocks with linear lines between them). The actual realised/achieved power output is naturally messy around this.
What I am after is extracting the target session from the messy power data (as I don't have access to this). It will essentially look like binary waves (straight level lines), though as you can see from the attached image, sometimes the power target is upward sloping.
A further complication is that for some of the other sessions the target effort blocks may be of short duration.
I have looked at various things to achieve this (wavelets etc...) but can't seem to find anything obvious...I am using R.
Any thoughts and help is greatly appreciated.