[sdiy] Simple circuit challenge: |a-b|

brianw brianw at audiobanshee.com
Fri Mar 22 22:39:12 CET 2024

I might be missing something, but it seems like you'd need two op-amps in parallel, with diodes to combine them.

|a-b| is either (a-b) or (b-a) depending upon which input is greater.

I assume this means you'll need two op-amps. One op-amp has a into the + input and b into the - input, while the other op-amp has a into the - input and b into the + input. These two op-amp outputs will represent (a-b) and (b-a), respectively. From those, a couple of diodes can combine them, and the larger will drive the next stage. You'll probably want a third op-amp to buffer after the diodes.

i.e. When a is greater than b, a-b will be positive, and it will pass through a diode to the final stage where it represents |a-b| correctly. However, when a is less than b, b-a will be positive, and the other op-amp will pass through the other diode to the final stage, where b-a is the same as |a-b|

Full wave rectifiers work on center-tapped transformer outputs, because you start with two waves, both the normal and inverted polarity, feeding the rectifier bridge such that there is always a positive cycle. Without the center tap, you end up with only the positive half cycle of the sine wave, and near-zero volts for the other half of the cycle. A bridge rectifier does not generate the opposite polarity via diodes alone - you need a transformer that feeds both polarities to the two bridge inputs.

By the way, what does the 2N3904 do in the suggested circuit provided? Is it merely an emitter-follower buffer?

Running the simulation, I see that with A=5V and B=-5V, the output is the full +10V (correct absolute value of the difference). However, when A=-5V and B=5V, the output is capped at +5V (incorrect, because it's only half the absolute difference).

After the simulation, I realized that I assumed only positive inputs before the difference, and only the difference would be positive or negative. My suggested circuit will still work for bipolar inputs, with the caveat that the output can be twice as large due to the difference.


On 22/3/24 05:50, Rutger Vlek via Synth-diy wrote:
> Dear list,
> while hobbying on an experimental design, I'm looking for a simple analog circuit to give me the absolute value of the difference between two signals (mathematically written as |a-b|).
> I already have a working circuit, but it's rather big for my needs. It uses an inverting opamp to invert signal A, followed by a bog-standard full wave precision rectifier circuit where -A and B are summed together and being rectified. The total is 3 opamps, 2 diodes and 9 resistors. As I need to repeat the circuit many times in the final application, I'm wondering: is there anything simpler that can do this?
> Requirements:
> - working across full audio range
> - distortion as consequence of diode drops is no problem (might even be beneficial!)
> Many thanks for any suggestions!
> Regards,
> Rutger

More information about the Synth-diy mailing list