I'm trying to come up with a system which will reliably convert an arbitrary input to a PWM signal, and then back again. The comparison signal is a 50kHz sine wave, and the result is fed through a window comparator to reject any partial signals.
I've got the duty cycle conversion functioning perfectly, however I'm having difficulties demodulating the signal accurately.
In the picture below the green trace is the input, the blue and red traces are from successive RC low pass filters.
There's a fair amount of distortion. Looking at the FFT it looks like it's being caused by other harmonics. I'm wondering what I can do to produce a much more accurate output. I was hoping to have a fairly wide usable frequency range with this system. Adding more poles to the output just creates additional harmonics.