NOTE ABOUT GRAPHS: on my computer the colours rendered as green and blue, this forum is showing green as pale grey and the blue as a dark blue though.
I have a circuit which measures an output waveform from a system. That waveform ought to be an envelope shaped like the green curves in the images, but due to other signals nearby I instead get a distorted copy like the blue waveforms. The different images show different severities of distortion.
I want to perform a calculation on a microcontroller to get the green waveform data back from the measured blue waveform.
I can't think how it should be performed though. Especially as I need a method which can work for different severities of error, as seen in the different images.
The underlying cause of the error is an extra sine wave signal of the same frequency being added to the true signal, but I'm only measuring he envelope of the peaks of those sine signals, which is what the graphs show here.
A difference between the envelopes gives the orange signal (only shown in the graph with the underlying sines also shown), it is almost a square wave, but there are linearly sloping sections in the regions between the green envelope has its minima and where the blue envelope has them. As the gradient of this slope, and height of this "square" wave, and length along the x axis for which the slope exists can all vary depending on the severity of the distortion, I can't se a way to process the measured numbers to subtract this away and give the green signal back.
To be quite clear, the only data I can have access to is the blue signal at one particular instant. That makes it impossible (I think?) to properly know whether to be adding or subtracting the error amount when in the regions between the two minima.
What mathematical operation should I be perforing on the microcontrolelr so I can get the idealised green signal (not measurable) back from the measured blue one.
Thank You
P.S. to give some further explanation, this is part of a resolver angle measurement circuit running with a high frequency underlying sine wave (much higher than depicted here, and higher than easily available analogue circuitry could do subtractions with). I only measure the envelope of those high frequency signals, this envelope varies with the shaft angle. I have 3 phases to work with, but I think this correction has to be done on each phase independently before I can start using the phases' values together. Any given shaft angle would correspond to a point on the envelope somewhere on the x axis, shown for two whole revolutions here. From that point on the x axis I can get the blue y value, but need to transform that blue to get the green value. I do have "sign" information too, not shown, so know which 180 degree half I am in, but this is affected by the distortion too, so until I can work out the right equation to convert from blue to green the exact points where this switching of sign occurs are shifted from true in the way that the positions of the blue minima are. Simply making an addition or subtraction depending on which value the sign reading has gives some huge spikes in the areas between the blue and green minima. I can't see way to calculate the linear parts of that orange curve from blue readings alone, so can't see how to apply those, although having the linear regions in the conversion equation would eliminate those spikes and give the correct green reading for any blue value.
The green signal is following a function like
y=sin(theta)*sin(high_frequency*t)
the blue follows
y=sin(theta)*sin(high_frequency*t)+error_proportion*sin(high_frequency*t)
The blue measurement I can make, and the green values I need, are envelopes of these signals as if passed through a diode and RC peak detector