# How many opamps does it take to find the peak amplitude of a signal?

I'm a beginner with EE and trying to find the peak amplitude of an electric guitar signal (0-300mV) using an Arduino's 0-5v ADC. I'm going to use the data to pulse lights in accordance with each strum of the guitar.

I've figured out so far that I need to use op-amps to:

1. Rectify the 0-300mv AC signal (full or half wave)
2. Amplify the signal to 0-5v
3. Use a voltage peak finder to locate the peak
4. Use a buffer to protect against impedance (not sure if I need this?)

I've found circuits that use op-amps to do all of these, and they work fine, however they are all independent of each other.

My Question: is how do I combine all of these together into one circuit and how many op-amps should I really need. My approach initially was just to daisy chain everything, but I'm not sure that's the correct approach. Also, most of these use a buffer op-amp as the last step, do I really need one if I'm sending the signal into an ADC?

-
If you always amplify the signal to 0-5 V, then find the peak, won't the peak amplitude always be 5 V? –  The Photon Apr 24 '12 at 19:26
It will vary based on how hard you strum the guitar. After rectification some quiet guitar picking could be 0-50mv, but if you strum hard the peaks can get up to 300mv. So I'm saying the possible max would change from 300mv to 5v after amplification. –  uberdanzik Apr 24 '12 at 19:55
one... tu-whooo... (crunch) three... the world may never know. –  Jason S Apr 24 '12 at 20:35

I think you can do all of this with just two op-amps (although someone will probably correct me).

The first stage is the peak detector and decay. The op-amp is wired to emulate a perfect diode. We take the feedback signal from after the diode so that the op-amp drives hard enough to overcome the voltage drop of the diode. Being a peak detector, it doesn't really eed a rectified signal. The capacitor holds the peak value, while the resistor decays it. You can make the decay slower by choosing a larger capacitor and resistor. And vice versa.

The second stage is simply 15x gain. It has low output impedance.

-
That scheme is wrong if I'm right, because when the signal is inverted the first opamp will saturate...do you agree? –  clabacchio Apr 24 '12 at 20:23
This is wrong. You are not amplifying the peak detected signal. –  Olin Lathrop Apr 24 '12 at 21:29
@Rocket: Better now. Downvote removed. –  Olin Lathrop Apr 24 '12 at 21:42
@Telaclavo: You're right, I apologize for that. I've changed the title now to reflect I was looking for the peak. –  uberdanzik Apr 24 '12 at 23:19
the nitpicker adds: this circuit finds the peak positive amplitude of the signal; signals with 2nd harmonics will have their negative halves ignored. –  Jason S Apr 25 '12 at 16:05

Take a look at this: it's a rectifier, that you can use both to find the envelop of the curve, and to amplify it.

You have to set the resistors such as the gain is the desired one (you can use a pot to set it), and the capacitor to minimize the ripple. Note that the RC constant will determine the responsivity of the circuit, so you'll have to find the optimal value for you.

-
Damn, you did it in one. Shoulda been obvious. –  Rocketmagnet Apr 24 '12 at 20:23
@Rocketmagnet I didn't :) I shamelessly took the schematic from another question :) –  clabacchio Apr 24 '12 at 20:24
Your output RC constant will largely depend on something external to the circuit (as is the input resistance of the ADC input). Also, the maximum gain for that is 11, and the OP needs 16.8. –  Telaclavo Apr 24 '12 at 21:08
@Telaclavo but I've specified that he can change the components to fit his needs, this schematic is taken from another question. And the RC constant will be quite fine if he feeds the signal to the ADC –  clabacchio Apr 24 '12 at 21:51
Everything there that the OP asked for, except a buffer. And if his ADC needs little enough input current that the error caused by its draining the capacitor is okay, then he doesn't really need the buffer. –  The Photon Apr 25 '12 at 5:09
show 1 more comment

Since you just want to turn on and off LEDs, and don't need hi-fidelity, this should work for you. The opamp amplifies only the positive range of your input signal, and therefore it does the rectification without needing any diode and, at the same time, it provides a voltage gain. The opamp will go into and out of saturation constantly, with the corresponding penalty in its frequency response but, I repeat, since you don't need hi-fi, this shouldn't be any problem.

R1 = 4.7 kohm (to limit input current when Vin is negative)

R2 = 9310 ohm

R3 = 590 ohm (gain will be the 5/0.3=16.8 that you need)

R4 = 1 kohm

C1 = 47 uF (R4 and C1 will low pass filter at fc=3.4 Hz, good for a vu-meter)

C2 = 1 uF 0805

U1 = AD8615AUJZ (with rail-to-rail input and output)

Notice that this circuit does not perform peak detection. Vout is the average of the positive cycles of Vin. That is proportional to the average amplitude of the input signal, which is what the OP wanted. So, in fact, Vout will be at most 2.5 V for full-scale, 50% duty ratio square wave input, but linearity will be better than with a peak detector, because that is nonlinear. The reduced Vout range can be easily compensated:

a) In software.

b) In hardware, applying 2.5 V to the VREF input of the Arduino.

-
With that circuit the range goes also to 5 V. And eventually he can use the LED itself as rectifying element –  clabacchio Apr 24 '12 at 20:47
@clabacchio No, Vout goes to an analog input of an Arduino, he said. –  Telaclavo Apr 24 '12 at 20:47
I do need high fidelity. These LEDs will be pulsing/fading to the guitar's dynamic activity like a light show. Hard strum / light strum should equal Bright pulse / Dim pulse. –  uberdanzik Apr 24 '12 at 21:36
@uberdanzik 1) Clearly, you don't know what hi-fidelity means. Hi-fidelity means something like <= 0.01% THD which, I repeat, makes no sense to drive vu-meter LEDs. 2) This circuit is the most linear of the 3 answers that I see here. 3) You wrote "trying to find the average amplitude", but then selected a circuit that gives you the peak amplitude, so you don't know the difference between them, either. 4) You shouldn't write "How many opamps does it take...", if you later select a solution that does not use the minimum possible number of opamps. Anyway, good to know, for the future. –  Telaclavo Apr 24 '12 at 22:56
@Telaclavo you're right about high-fidelity, but I'm quite sure that for "average amplitude" he means the envelope of the curve, which basically can be obtained with a fast peak detector –  clabacchio Apr 25 '12 at 6:08

Here's another precision full wave rectifier. Full wave amp

Personally you can do alot of signal conditioning with HEX CMOS inverters with each buffer having an open loop gain of 1000. A log amp is useful if you want to regulate Light intensity with log of input amplitude similar to hearing response. You can use a State Variable Filter to create bandpass, low pass and high pass for 3 channel or use a chain of gyrator BP filters with quad OA's and make one light per note or one per octave. Again it all depends what you want to do.

-
+1 -- this circuit detects both positive and negative peaks of waveforms. –  Jason S Apr 25 '12 at 16:08