Finding the maths to transform between two "envelope" curves - Page 1
Forum section: electronics / beginners

author: Infraviolet
author_rank: Super Contributor
timestamp: August 23, 2023, 06:31:37 pm
content: 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 YouP.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 likey=sin(theta)*sin(high_frequency*t)the blue followsy=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

author: Nominal Animal
author_rank: Super Contributor
timestamp: August 23, 2023, 07:07:21 pm
content: It seems to me that if you were to invert every other half wave of the envelope, you'd find your error is mostly just a DC bias.In other words, if you locate every envelope peak in both time and amplitude, their average amplitude is the true envelope amplitude, and the inverse frequency is twice the average interval between those peaks.If you were to draw the full signed envelope curves, you'd see that the correction you need is just a constant (or very, very slowly changing value), equal to half the difference in magnitude between the odd and even peak amplitudes.Thus, one option to implement this on a microcontroller would have two stages. One stage locates the odd and even (or "positive" and "negative") peaks, and updates the relevant "constants" using a long time constant filter (so jitter won't affect the actual values much). The other stage simply shifts the incoming data by adding half the difference between the odd and even peak amplitudes to the ADC data. To avoid step changes, you might keep track of the difference at each peak, and linearly interpolate between the two; but this may not be necessary, depending on the precision and accuracy of your data, and the peak detector filter (or the maximum step change it may cause).

author: Infraviolet
author_rank: Super Contributor
timestamp: August 23, 2023, 08:33:18 pm
content: Ok, I've found that applying a DC offset with a sign which is controlled by the "sign"* of the blue signal gives something close to a solution.Because the cause of the error is a sine wave, not actually a DC offset at the underlying level, the offset's direction changes in different parts of the signal.The DC offset is the black square wave, the corrected waveform is in red, it is pretty close except for the small negative spikes now shown. Much better than switching the direction of the offset according to the "sign" of the green waveform (which was what I initially tried when graphing this even though the green one's sign isn't a measurement available in the real system), which gave far taller spikes over a far larger x axis region around each minima.It seems to mostly save me from needing to worry about the sloping sections on the difference graph.*in the full system this is a sign measured as high or low on a separate GPIO pin, in the graph plotter I'm using to test my ideas it is a hacky piece of code checking whether the theta angle is in the region before the first envelope minima, between the first and second minima and so on.