Level Detectors, Absolute Value, Peak and RMS

Where we discuss new analog design ideas for Pro Audio and modern spins on vintage ones.
User avatar
JR.
Posts: 3715
Joined: Sat May 24, 2008 7:21 pm
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by JR. »

mediatechnology wrote:OK, I get the part about how conveniently the micro can scan and scale the display, provide ballistics etc.
It's a nice functional meter with a fairly low BOM and in it's application killer. Need to find the link to the vid you posted.
I suspect the LEDs are the greatest cost.
PICs eventually seem to enter most threads here.
Microchip PIC families are just the platform I am familiar with, there are several brands with similar capability, and it looks like the bigger (32 bit, etc) platforms these days are being licensed from Arm Holdings, I tend to write about what I have used.

But with a theoretical DR of 72 dB (for a 12 bit conversion) and with sub 40 kHz sampling I don't see how you can claim greater accuracy than a continuous time (analog) absolute value circuit costing pennies (5532 + 2X inexpensive dual transistors) that has at least 60 dB of usable range at 20 kHz. I may be wrong but I think that's what I heard.
I don't know that I said that exactly but comparing analog to digital is not apples to apples. There is a difference between accuracy and resolution for A/D conversion. You need X bit linearity (accuracy) so the conversion SAR will converge, but you can accumulate and average samples over time and gain more bits of display resolution. The example I cited where I collected 4 samples in row, gives me 2 more bits just by adding them. Note: in the interest of full disclosure, full wave rectification costs one bit of dynamic range, so 12b a/d rectified is only 11b, but it still doesn't make economic sense to perform even that outside the digital domain. Easier and more effective to do it in code.

The digital equivalent of a low pass filter to average this meter output over time, first computes the instantaneous difference between the last sample, and the accumulated average. Then a factor to simulate the R part of a RxC, adds a fraction of that difference per unit time, to the accumulated result. The accumulated result I used was 16 bits, but it could have been longer if there was some utility in doing that. While the accuracy will never exceed the raw linearity of the conversion, the resolution over multiple samples certainly can. (of course this has practical limits and other error sources are present)
Sampling 20 kHz only 1-1/2 times per waveform period the odds of actually hitting the peak value seem rather slim to me.
Engineering is always about using the right tool for the task. If you need to absolutely, positively, capture the peak voltage of a one time transient, a sampling A/D is not the right approach, as we notice digital scopes use silly high sample rates to provide that capture visobility.

However to bering this back into perspective to read the peak value of a sine wave even at 20kHz, under sampling with a dithered sample rate ( like I mentioned I did) such that it doesn't hit the sine wave at the same place every cycle will work... trust me if it didn't work I wouldn't have used it in a relatively high end console. The APB boys were pretty picky about performance, And I hit the meter with up to 30 kHz sine waves (from an old TS-1) .

In practice even the peak meter result is LPF at something like a 4 mSec RxC (for at least the common PPM standard) so single transient events do not over-report.
I get the averaging across samples part and understand how an 18 bit higher-speed converter would make it better.
But I'm not buying how a 10-12 bit aliased sampled input that's "blind" to the waveform more often that it isn't can be more accurate than a dual op amp and handful of diode-connected transistors. (Or for that matter just diodes.)
It all depends on how you frame the question. How are you using that analog data? In my TS-1 I performed an analog log conversion and then did my own A/D voltage to period or frequency conversion to count up or down x dBu. The analog processing and log conversion had errors at both end, and probably some in the middle too. :lol:
It seems that the HF accuracy limitations of the sampled approach exist at any level whereas the analog approach suffers it's greatest errors only at low levels.
What it looks like to me is that using a PIC allows you to do all this housekeeping and add a lot of functionality at low cost with reduced accuracy due to low sample rate.
I never made any claim that the almost free A/D that come inside cheap PICs are bench test equipment replacements. But I suspect a cheap PIC and DPOT to double the 12 bit dynamic range (by compressing the input 2:1) could give the old TS-1 a run for it's money. Not to mention I could probably make a more accurate and lower distortion sine wave using the PIC. With one of the cheap audio codecs and a pic it would absolutely kick the ass of my best effort for analog technology 30+ years ago. Today I could do better than I did 30 years ago using modern analog technology, but would be foolish to ignore modern digital technology.

One point not really explored in the console digital vs analog meters comparison, the price was not even close to similar but the digital was way way cheaper. Both analog and digital LED meters need the same LEDs so that cost is a wash... all the analog crunching and glue circuitry just to do a simple average only (VU) meter used a ton of PC board real estate, lots of insertions and lots of separate parts. I did the digital meter in a smaller package, added more features and functions, and even performed some of the related analog circuitry (like steering meter input for solo, alarm notification, etc) all for less cost.

We hear nothing but raves from customer, while customers these days willing to invest in analog consoles seem to be a declining market segment.
Kinda like an iPad or iPhone-based drum tuner...
Well you can buy one It's only something like $2. I even provide a link to it on my website because it isn't really competition. Like i said, I have an aversion to making products that can be covered by a cheap smart phone app. I spent months trying to make my tuning invention work with only one loud speaker to make it cheaper and smaller and it does not work right with less than two speakers. The lug matching "clear" measurement I make (from a standing wave I excite in the drumhead) does not converge with only one sound source. The lugs interact with each other. I need to use two speakers to bracket and isolate one lug at a time to make useful clear quality (different than note pitch) measurements that converge. Tuning drums is not just about the notes. In fact drums are technically not even considered "pitched" instruments with the exception of the tympani and kettle drum. The hard part is to get the lugs in agreement with each other independent of the note the drum is making.

If you have any interest in learning about drums, or buying that Iphone app here is an article I wrote about drums, called "about drums" (go figure). http://www.resotune.com/About_drums.htm The link to the IPHONE app is in my discussion about note sniffers.

Sorry for the veer... There will always be analog... in fact some of the issues I talked about with the cheap A/D are related to analog or hybrid analog circuits like sample and holds.

I tried to drag APB kicking and screaming into the digital age. I fear they may end up like the dinosaurs, which saddens me because they are friends.

JR
Cancel the "cancel culture", do not support mob hatred.
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

I wanted to post this very clever circuit for a dB meter using the RSSI output of an NXP SA604A FM IF stage.

Image
The NXP SA604 FM IF used as an audio dB meter.

Image
NXP SA604A Block Diagram

Image
The NXP SA604 audio dB meter linearity.

The linearity is quoted as being within 1.5 dB over an 80 dB dynamic range.
For 0.5 dB accuracy they recommend using a segment of about 40-50 dB.

NXP AN1991 "Audio decibel level detector with meter driver" http://www.proaudiodesignforum.com/imag ... AN1991.pdf

NXP SA604A Datasheet http://www.proaudiodesignforum.com/imag ... SA604A.pdf
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

From the Microcontrollers PIC Forum:
More than averagely fun & disparate collection of Level, Absolute Value, Peak and RMS Detectors
http://microcontrollers.2385.n7.nabble. ... 01073.html

I found this reference to our forum very amusing.
User avatar
JR.
Posts: 3715
Joined: Sat May 24, 2008 7:21 pm
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by JR. »

mediatechnology wrote:From the Microcontrollers PIC Forum:
More than averagely fun & disparate collection of Level, Absolute Value, Peak and RMS Detectors
http://microcontrollers.2385.n7.nabble. ... 01073.html

I found this reference to our forum very amusing.
So if you link to a forum that is linking to you, does that crash the WWW or create a singularity? :lol:

JR
Cancel the "cancel culture", do not support mob hatred.
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

So if you link to a forum that is linking to you, does that crash the WWW or create a singularity? :lol:
It's positive feedback. :lol:
I'm building up for an oscillator series.

BTW I really thought Cordell's level detector for oscillator stabilization was pretty slick due to its simplicity so I put it up in the first post along with a few other additions.
It's low-level performance doesn't need to be good.
What I like about it is that no op amps run open loop during zero cross so its likely to be very quiet in an oscillator.

Image
Cordell Rectifier From "A High Performance THD Analyzer."

See: "Bob Cordell: Build A High Performance THD Analyzer" https://www.proaudiodesignforum.com/for ... f=12&t=805
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

Found these comparator-based positive and negative peak detectors in the LM311 datasheet.
I didn't recall this particular example...


Image
Positive and Negative Comparator-based Peak Detectors Using the LM311.

The LM311 symbol is the odd logic format.
The inverting input has the ball.
Note the attempt to prevent TL081 voltage follower latch-up and capacitor discharge current into the input.
Also be aware that the capacitor polarity shown in the negative example is incorrect.

The negative peak detector version is easily implemented with the open collector LM339 and LM393.
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

I found this one op amp absolute value circuit on flyboy71's website several months ago and have been meaning to post it.

Jeff writes:
There are numerous circuits available that can perform an absolute value function using an op-amp. Many textbook examples start with a single opamp half wave circuit and simply add another opamp to make a full wave absolute value version. Among the various books I have, only one in my collection has the circuit shown here. This was originally published in Electronics magazine 1 in 1969 and I have not come across it in other books on opamp theory. The basic operation is fairly simple, during the positive half cycle D1 conducts and presents a voltage on the non-inverting input of the input voltage minus the voltage drop from D1 divided by two. Since D2 is cut off, the opamp is a standard non-inverting configuration with a gain of two. During the negative half cycle, D1 is cut off, which effectively puts the non-inverting input at zero volts via R2. Since the inverting input is also at zero volts, the opamp is now an inverting configuration with the input one diode voltage drop lower. Notice R4 has zero volts and therefore zero current, which effectively makes it transparent in this configuration. In both half cycles, since D3 is in the feedback loop, it compensates for the drops across D1 and D2. In my measurement of this circuit, the output can be loaded without affecting the operation. The measurement shown used a 4V pkpk sine at 1kHz input and the IC was a general purpose LM2904 operating from +/-15V.
I'll add that R4 provides a bias current path for the inverting input.
The one thing I might change is to make R1 and R2 (Jeff's drawing, R3 and R4 in 1969) 10KΩ each so that the diode forward currents are matched.
Rin for the inverting path is 20KΩ; for the non-inverting path it's 40KΩ. With R1 and R2 10KΩ Rin becomes 20KΩ.

https://ornerscorner.neocities.org/absvalue

Image

I pulled the original from the 1969 EDN article:

Image

I've been wanting to build this simple circuit and will post when I do.
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

mediatechnology wrote: Sat Sep 09, 2023 3:18 pm I found this one op amp absolute value circuit on flyboy71's website several months ago and have been meaning to post it.

Jeff writes:
There are numerous circuits available that can perform an absolute value function using an op-amp. Many textbook examples start with a single opamp half wave circuit and simply add another opamp to make a full wave absolute value version. Among the various books I have, only one in my collection has the circuit shown here. This was originally published in Electronics magazine 1 in 1969 and I have not come across it in other books on opamp theory. The basic operation is fairly simple, during the positive half cycle D1 conducts and presents a voltage on the non-inverting input of the input voltage minus the voltage drop from D1 divided by two. Since D2 is cut off, the opamp is a standard non-inverting configuration with a gain of two. During the negative half cycle, D1 is cut off, which effectively puts the non-inverting input at zero volts via R2. Since the inverting input is also at zero volts, the opamp is now an inverting configuration with the input one diode voltage drop lower. Notice R4 has zero volts and therefore zero current, which effectively makes it transparent in this configuration. In both half cycles, since D3 is in the feedback loop, it compensates for the drops across D1 and D2. In my measurement of this circuit, the output can be loaded without affecting the operation. The measurement shown used a 4V pkpk sine at 1kHz input and the IC was a general purpose LM2904 operating from +/-15V.
I'll add that R4 provides a bias current path for the inverting input.
The one thing I might change is to make R1 and R2 (Jeff's drawing, R3 and R4 in 1969) 10KΩ each so that the diode forward currents are matched.
Rin for the inverting path is 20KΩ; for the non-inverting path it's 40KΩ. With R1 and R2 10KΩ Rin becomes 20KΩ.

https://ornerscorner.neocities.org/absvalue

Image

I pulled the original from the 1969 EDN article:

Image

I've been wanting to build this simple circuit and will post when I do.
Looking at this circuit I see a potential problem which can be easily corrected.

If the op amp has bias current or input offset sufficiently high to send the output in the negative direction there is complete loss of DC feedback and it will peg to the negative rail in the absence of input signal.
The original works because the µA709 has an NPN input and the bias current causes a slight negative Vos to develop at the inverting input.
This sends the output positive and pre-biases the feedback diode.

A PNP input op amp such as the LM833 or LM324 etc. will likely peg to the negative rail.

The LM2904 also has a PNP input but from the Ib spec the sign is indeterminate suggesting that it is bias current compensated.
Whether the LM2904 pegs should be a toss-up.

The solution (I think) is two high value feedback resistors with an electrolytic in the middle to provide a DC feed back path around the op amp should the input bias current or Vos conspire to send it negative.
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

I'm beginning to think my bias current theory only partially holds water.
With equal value resistors the Thevenin equivalent is equal at the inverting and non-inverting inputs when the feedback diode isn't conducting. (Eout negative.)
So Ib doesn't drive the feedback diode into conduction. Ios, which has an indeterminate sign, may.

Scaling the input resistors in the non-inverting input lower to equalize diode current would help alleviate this by making the Ib of the inverting input dominate by a factor of 2.
That only works if it's a bipolar op amp without Ib correction and not something I think I would ever want to count on.

Also, the DC feedback loop proposal won't work: It will average the absolute value of Ein.

One could add a clamp diode around the op amp to limit negative swings, but the output could still peg at -Vf, 600mV.

I'm pondering a "plan C."
Stay tuned.
User avatar
mediatechnology
Posts: 5502
Joined: Sat Aug 11, 2007 2:34 pm
Location: Oak Cliff, Texas
Contact:

Re: Level Detectors, Absolute Value, Peak and RMS

Post by mediatechnology »

Plan C.

I confirmed that a BIFET (TL072) will peg to the negative rail in Spani's 1969 circuit when there is no input.
A 5532 has enough Ib that it works.

Here is a 2023 "improved version" of Spani's 1969 "Absolute Value Circuit Needs Only One Op Amp."

Image
Improved Absolute Value Circuit Needs Only One Op Amp

Scaling R1 and R2 improves symmetry by equalizing D1/D2 forward current.
D3, as before, compensates for the Vf of D1 and D2.
D4, not in the original, clamps bias and offset induced negative going outputs. With a TL072 and that particular diode clamped Vout is about -100 mV.
D5, also not in the original, prevents any negative output.
R6 provides a load.
The output impedance for sourcing current is the op amp output current with D5's dynamic impedance in series.
The impedance for sinking output current is R6 in parallel with D3's dynamic impedance plus R5.

For a simple single op amp circuit it works OK at peak inputs >250 mV and frequencies below 20 kHz.
In an instrumentation application with higher level inputs it makes a good go-to circuit.
Post Reply