Audio level indicator comparator design help with hysteresis - Page 1
Forum section: electronics / beginners

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 05:39:31 pm
content: Hi all,I'm trying to design a comparator that accepts a rectified audio signal and a DC signal and compares them.If the comparator is high (meaning the signal is greater than the DC signal) a red led lights up else a green led is lit.The DC threshold is provided by a CD4053 which also switches the incoming audio. (this works perfectly so I will leave it out)My circuit is as basic as it gets and it roughly works but I get led flashing because my comparator has no hysteresis so it kind of oscillates between on and off when the audio has sharp transients or peaks (which is all the time!)I can't leave it like that because it's pretty must useless.I thought about compressing the incoming audio somehow but I guess this is overkill and there is a simpler solution like coming up with some sort of hysteresis scheme.The problem is that there are two levels of DC thresholds one for -10dBV and one for +4dBu which differ with a factor of 3.9 meaning that the same comparator will accept two levels of rectified audio and two levels of DC and must be able to handle both without oscillating.I was being lazy and placed a 1M wired as variable resistor between the + and output terminals of the comparator but didn't notice any difference so I came here for advice..Is it possible to make this comparator insensitive to rapid changes?

author: TimFox
author_rank: Super Contributor
timestamp: March 29, 2023, 05:46:25 pm
content: Assuming your concern is the peak amplitude level, you should trigger a monostable multivibrator (one-shot) from the output of your comparator to stretch the indication on the LEDs to a duration that you can see.Adding hysteresis to your comparator is a good idea, but not absolutely necessary.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 05:51:43 pm
content: My led circuit is shown below and it works fine. I have no problem using a 555 but this is pretty simple and it works so far.My concern is that the comparator goes high all the time and I need it to be quiter and trigger at higher levels without catching every single peak of the incoming signal.Should I compress or filter the audio before rectify it?I thought that if I rectify it first before it hits the comparator I wouldn't have to deal with the spikes but I was wrong.I want the comparator to hit + when the audio is a bit above 0db not in every single snare strike..

author: shapirus
author_rank: Super Contributor
timestamp: March 29, 2023, 06:06:24 pm
content: Try adding an RC low-pass filter at the signal input of your comparator. It should filter out the unwanted short spikes.

author: donlisms
author_rank: Frequent Contributor
timestamp: March 29, 2023, 06:14:50 pm
content: As you have become aware, there is usually no such thing as a single audio level. The normal approach for level meters is some form of averaging. Back in the day, a VU meter would have mechanical ballistics - the needle would respond fairly rapidly going up, with some sluggishness (low pass filtering - of the needle movement, not the audio), and the needle would fall back down more slowly, giving the user time to see what was going on. The user did the averaging and such with intuition.One very important question is whether you want to measure an average audio level, or peak levels. In the digital realm, peaks are very important, because they're going to determine whether you have, or will have, clipping. It is an objective measurement of a specific level. The time element here would to hold the indication long enough for it to be useful.Average level, on the other hand, is generally used for more subjective purposes, e.g. "Is it loud enough?" Here, the usual approach is to convert to RMS, and again there is a time element in how quickly the average is made. The levels reported such an averaging meter are usually divided into ranges, at least two, or better three, or more, that can be considered something like "signal present," "low," "normal," and "high," perhaps with a separate peak indicator that means "dangerous." This is what you'd normally find on a mixer, for example, in one form or another.Without knowing what you need to accomplish, I can't suggest a circuit. I would suggest you investigate peak detectors, though - that might be what you'd want.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 06:30:44 pm
content: That's why I took the route of converting the AC signal to DC; in order to have a real world relative indication of what is "loud enough".I just set my AC signal to a bit over 0.775Vrms and then set my DC threshold to trigger the comparator high at that audio level.That works great but it's too sensitive and it triggers my comparator all the time even at AC levels waay lower than 0dB.Isn't a peak detector sensitive as well? I'm afraid it will produce results in the ballpark of what I'm already doing.What I want to achieve is a more sluggish/dumped perfomance of what I already have.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 06:44:45 pm
content: Isn't R48 and C15 form a low pass RC filter?

author: shapirus
author_rank: Super Contributor
timestamp: March 29, 2023, 06:56:32 pm
content: Quote from: belzrebuth on March 29, 2023, 06:44:45 pmIt's hard to tell from the two pieces you showed, I had to make assumptions. Can you attach a complete picture of the relevant part of the circuit so that we can see the full path of the signal from the point that the peak detector has to monitor to the output of the LED triggering signal?

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 07:18:47 pm
content: Here is the complete circuit:VU_IN is the incoming audio.LEDs are not shown they're wired as VCC->resistor->LED (not important but for completeness sake).

author: donlisms
author_rank: Frequent Contributor
timestamp: March 29, 2023, 07:39:06 pm
content: Yes, the rectification was a great place to start! Necessary.Compression will change the level. That seems to be the wrong direction if what you want is a measurement of the level! I don't know. Maybe it's the Heisenberg uncertainty principle. :-) Anyway, that's probably not the right answer for several reasons, including complexity, as well as the "what's needed" thing.A peak detector has a time constant; you can choose it. A first amplifier is going to charge a "holding" capacitor rapidly to the peak, and present that voltage through a buffer amplifier. Then back at the capacitor, a resistor will discharge it over some time interval of your choice. Seems to it would sort of take care of half-wave rectification, too, if that's good enough for you. Or you could feed it with the DC you already have.You mentioned snare hits. Each of those is going to, almost by definition, a "peak." Their total time of existence is not so many milliseconds, making them incompatible with a long-term average -- which would have to so extreme it would make the thing useless for all other kinds of sounds. I would never want those hidden, anyway; they're kind of a big deal! If I'm mixing, I might make a decision about where to put the snare in the mix based on how strong those peaks were. If I'm recording... clipping danger!

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 08:49:07 pm
content: I have a vu meter on that circuit as well so monitoring the levels via the LEDs is not my primary concern.The LEDs act as a decorative blinkenlight of some sort not as a meter.Red means you're overdoing it but it's like an average thing not a peak thing.I know I'm not making it any easier and I'm being vague.Isn't there any way to make the comparator slower to rapid level changes?! Can't I introduce some time of delay? I thought hysteresis was the answer to that..!

author: shapirus
author_rank: Super Contributor
timestamp: March 29, 2023, 09:21:55 pm
content: Quote from: belzrebuth on March 29, 2023, 07:18:47 pmOkay, so as it is, your circuit is averaging the output of the rectifier over a very long time span. C15 is basically doing what the capacitor in a typical bridge+cap linear DC power supply is doing. The comparator is seeing a nearly DC waveform at its non-inverting input.Have you tried to look what happens at the comparator's input with a scope?It looks like the way to go here is be to:1) either remove C15 altogether and use the comparator to detect any short peak; or replace it with something like 10-100nF and add a 1k resistor between the non-inverting input of the comparator and the cathode of D1 -- this will work as an actual low-pass filter to stretch the peaks and make them lower; or maybe simply reduce the cap (to a few nF maybe) and not add the resistor at all -- try various combinations and use a scope to see what happens;2) see if it works as is; if it doesn't, then use the comparator's output to trigger a one-shot multivibrator that will turn on the LEDs -- tune the pulse duration to your liking. Use two channels of the scope connected at both inputs of the comparator to make sure that the threshold voltage is correct and the rectified and filtered audio signal is going over it when you expect.Also, R47 is unnecessarily low. It is still required, if your input is AC-coupled, to provide a DC bias return path for the comparator (note that it is actually an op amp used as a comparator here), but it can be replaced with a higher value, I'd say 10k-50k.p.s. hysteresis may or may not solve it. It doesn't add an actual time delay, it deals with voltages. Try it.p.p.s. i don't think you can add hysteresis here, at least not with the dual supply-powered op amp used as a comparator, because it ouputs voltage close to the negative rail when it's not triggering, but you need it to be at ground if you use a rectified signal as input.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: March 29, 2023, 11:17:15 pm
content: I think that replacing the 22uF C15 with a 220uF one greatly absorbs the peaks and makes the overload indicator a lot smoother to look at..