Beep detection circuit - Page 1
Forum section: electronics / projects

author: TopGunPk
author_rank: Contributor
timestamp: April 06, 2018, 10:10:07 pm
content: Hi.I am trying to build a circuit that will, eventually, detect the Beep of a buzzer and give a simple logic "1" or "0" output to a controller.There are numerous "similar" circuits on the internet, like a very common "Clap detector" and "Whistle detector" etc... But these are very basic and have false triggering. What I am trying to do is to implement a sure shot circuit.I have done a few tests with simple electret mic capsules (scavenged from an old POTS phone, a generic cell phone mic module, normally available elctret capsules, etc.). Used opamp (LM2904, LM358) to make a pre-amp, and measure frequencies on a o'scope etc. I have had some level of success with an LM567 (PLL / Tone detector) to recognize the Beep sound of a buzzer (3.95 kHz), But I am facing few problems, and initially, looking for a guide.So the main problem I am facing is the range of the detection. keep the buzzer close (within 1 foot of the mic) and it detects the beep sound and gives a clean "1" or "0". When I move it away further, it just does not do that. So I figured the gain of the mic amplifier is low. I increased the gain from 100 to 1000 and even 10000, but then the nearby sounds get amplified a lot and saturate the outputs.So I have two basic schemes in mind, hoping if someone can first point me in the right direction.1) Mic -> Pre-amp -> Bandpass filter (High + Low pass centered around 3.95 kHz) -> AGC (to keep output levels same regardless of inputs level) -> tone detection chip (LM567) -> Logic output.2) Mic -> Pre-amp -> AGC (to keep output levels same regardless of inputs level) -> Bandpass filter (High + Low pass centered around 3.95 kHz) -> tone detection chip (LM567) -> Logic output.I am wanting to use an AGC circuit hoping that whether the "Beep" sound comes from half-way across the room or from very very near to the mic, the output level will not saturate or clip or not come at all..... Is this the right block to use in my scheme ?Thanks for all the help.Regards,Shan

author: Zero999
author_rank: Super Contributor
timestamp: April 06, 2018, 11:14:07 pm
content: It looks like you're on the right track.I'd put the bandpass filter before the AGC and integrate it with the pre-amplifier. Steer clear of the old LM358. What's the power supply voltage? If it's above 6V, use the tried and tested NE5532.Have you tried using the CD4046 as a tone detector?All that's needed is a lock detector can be made with a couple of OR gates and a diode.http://www.ti.com/lit/an/scha002a/scha002a.pdf

author: MasterT
author_rank: Frequent Contributor
timestamp: April 06, 2018, 11:50:06 pm
content: What kind a controller? Can you re-program it, to do sound detection in software?

author: Rerouter
author_rank: Super Contributor
timestamp: April 07, 2018, 12:01:12 am
content: You will want 2 filter chains, 1 band pass for your signal, and 1 band stop for your reference,If the bandpass signal is present, and the bandstop is not, its valid and output as such,If pass and stop are present, its likely speach or noise, not valid

author: TopGunPk
author_rank: Contributor
timestamp: April 07, 2018, 08:02:11 am
content: Thanks Hero999My intended supply in the final circuit will be 3.3V (Single supply). So considering the Mic circuit, its biased at half that supply voltage, or at around 1.6V, with the audio signal riding on that 1.6V center-line.The opamp I am using is an LM2904 and LM358, and my test circuit is at 5V power.... for now. I know that LM358 is not a good choice here, considering the common mode range and min/max output with respect to supply rails... I am going to try with a Rail-to-rail opamp now.for the scheme of putting a Bandpass filter BEFORE the AGC, I am a bit confused. what I understand is, the Bandpass filter will give max gain at the frequencies around the center pass-band region, while attenuate other frequencies base on its roll-off. Since it is at max a 2nd order filter, the response will obviously not be a brick-wall cutoff. So, its output will be many frequencies, with the center frequency at highest gain, and all others at lower gain... BUT these lower frequencies will be there in the output.Feeding this composite signal to the AGC, the AGC will try its best to keep its output level constant... irrespective of which component of the signal is lower in amplitude or higher on its input.. so wouldn't it kind of negate the use of the Bandpass filter ? since the AGC will output all the frequencies on its input at a constant level on its output ?

author: TopGunPk
author_rank: Contributor
timestamp: April 07, 2018, 08:31:59 am
content: Thanks MasterT.One of the goals for me is to specifically keep the audio signal out of the controller, ad process it in the analog domain with a clean logic output.This is also a learning curve for me and a challenge. I understand opamps fairly well, but, for example, I am very new to AGC and its building blocks. That is why my question is geared to ask if the AGC will be required or not.One of the challenges is to detect or "recognize" the beep sound from a signal that has other sounds in it as well at the same time (Speech and some noise). I recorded an audio on my cell phone with people in the same room talking, and I could still distinctively hear the beep sound on my Aircon unit in another room.The other major challenge is to be able to get that beep sound from a distance (from one end of a room to the other, OR, from one room to the other) and amplify it in the circuit so it can be detected.On a controller, this could be accomplished with FFT or Goertzel algorithm. I am not ruling out the use of a controller here, but I want to understand and be able to do this in the analog domain as far as practically possible.

author: MasterT
author_rank: Frequent Contributor
timestamp: April 07, 2018, 12:26:10 pm
content: To solve it in analog world, look at the super-regenerative receiver architecture. In both your options:Quoteyou doing "band selection" after pre-amp. This is wrong way if you need to get the wide dynamic range. To avoid saturation you need to do filtering as close to mic as possible, OR use mic that sensitive to specific tone (piezo), OR put filter before the mic (wind pipe).Discriminator could be as simple as envelope detector. Or you could do RF receiver analogy, and mix-up mic output (may be after low noise amp x10 ) to 3.9 kHz, and get DC (Zero IF receiver), than do amplification.

author: Marco
author_rank: Super Contributor
timestamp: April 07, 2018, 12:40:19 pm
content: Is the beep generated by a crystal based circuit?If so, you could go ultra-narrow-band ... which is to say, use a lock-in amplifier. Low pass->gate with two square waves at the desired frequency shifted 90 degrees->low pass and sum the results->threshold detector. No AGC needed.

author: Peabody
author_rank: Super Contributor
timestamp: April 07, 2018, 12:41:13 pm
content: The IR remote receivers such as the Vishay TSOP1738 deal with similar problems. They are looking for the 38 KHz carrier. There's no real detail, but the datasheet shows the AGC first, then bandpass, then demodulator. I suspect all but the front end is done digitally.

author: Zero999
author_rank: Super Contributor
timestamp: April 07, 2018, 08:17:35 pm
content: Quote from: TopGunPk on April 07, 2018, 08:02:11 amIf you're using the LM358, rather than a rail-to-rail op-amp, to get the maximum output swing, the output shouldn't be biased to half the supply voltage but (Vsupply-1.5)/2 as the output stage typically drops 1.5V, off the positive rail when sourcing current.Yes, filtering should be implemented as early as possible, preferably acoustically, before the sound even reaches the microphone. An electrect microphone probably isn't optimum. A piezoelectric transducer could be used instead, preferably one with a resonant chamber, tuned to the right frequency. Fortunately there are plenty of piezo transducers available, with a resonant frequency close to 4kHz.http://www.farnell.com/datasheets/1851881.pdf?_ga=2.216633558.1797950326.1523104475-47418993.1417808164&_gac=1.204279460.1521927514.EAIaIQobChMI7eL33vWF2gIVTrftCh3lBAcPEAQYAyABEgKzePD_BwEhttp://www.farnell.com/datasheets/2370673.pdf?_ga=2.216633558.1797950326.1523104475-47418993.1417808164&_gac=1.204279460.1521927514.EAIaIQobChMI7eL33vWF2gIVTrftCh3lBAcPEAQYAyABEgKzePD_BwEIf you must use an electrect mic' then a Helmholtz resonator could be added, to give a peak response at 4kHz. See the link below, which deals with designing a resonant chamber for a piezo transducer, but the principle is the same.http://www.puiaudio.com/resources-white-papers-helmholtz.aspxAn AGC is fairly straightforward to design. I made a discrete one fairly recently for an intercom project. It had the advantage of only requiring two wires between iit and the power amplifier: one for both power and the output signal and another for 0V. The microphone was on the same board. It performed fairly well but wasn't developed further as the AGC requirement was dropped from the project. There are also ICs available such as the NJM2783 and MAX9814, the latter is available in a pre-built module, with a microphone. It's also possible to add some filtering to the AGC/pre-amplifier stage. I noticed my design can be made to have a resonant peak, if certain resistor and capacitor values were used, but I deliberately avoided it.https://www.eevblog.com/forum/projects/mic-pre-amp-circuit-discrete-or-ic/msg1410745/#msg1410745

author: mikerj
author_rank: Super Contributor
timestamp: April 08, 2018, 02:37:18 pm
content: Does this have to be a purely analog solution? You can perform single tone detection on a small microcontroller pretty easily, using e.g. the Goertzel algorithm.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 08, 2018, 03:34:54 pm
content: Quote from: mikerj on April 08, 2018, 02:37:18 pmQuite right. And you could do this with just a few components: an electret microphone, a very small microcontroller with one ADC and a couple passive components... and it would be very flexible, allowing you to software-define your tone detection, and even perfom multi-tone detection if needed.So even as a stand-alone solution, a micro-controller-based solution would be much simpler and flexible IMO.

author: Zero999
author_rank: Super Contributor
timestamp: April 08, 2018, 08:25:32 pm
content: Quote from: SiliconWizard on April 08, 2018, 03:34:54 pmI agree that the tone detection would be better done in software, rather than a PLL, but there still needs to be some form of analogue front end, for this to perform well. The ADC on a microcontroller won't have enough precision, when driven directly by a microphone and an AGC will still help.Whare's Mr Cypress PSoC when we need him? That's just the sort of thing project which could benefit from a Cypress PSoC.

author: BrianHG
author_rank: Super Contributor
timestamp: April 08, 2018, 08:36:52 pm
content: Quote from: Hero999 on April 08, 2018, 08:25:32 pmUse a microchip PIC with a built in opamp, or, ADC with the VRef set to 1.024v reference with x2 or x4 gain on the 10/12bit ADC input channel. Use the DAC channel to set your mid DC bias point for the ADC.

author: Benta
author_rank: Super Contributor
timestamp: April 08, 2018, 09:00:07 pm
content: Quote from: Hero999 on April 06, 2018, 11:14:07 pmPlease do not refer to that TI application note. It's one of the dodgiest around and will not lead to success.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 08, 2018, 09:27:22 pm
content: Quote from: Hero999 on April 08, 2018, 08:25:32 pmDepending on the application, you may not necessarily need an AGC. Some microcontrollers have internal opamps.But to get a flexible yet low-cost solution, you can add a MAX9814 as a front-end a be done with it.

author: TopGunPk
author_rank: Contributor
timestamp: April 08, 2018, 10:18:03 pm
content: Thanks guys.Yes, I hate to admit, I am tilting towards a standalone micro-controller to do the tone detection.For the front-end, I have designed this little circuit, and would appreciate your feedbacks.So, the MIC (C2 in the diagram) is biased by a 2.2K resistor to the supply.C5 AC-couples the output to the opamp's non-inverting input.R4 will keep the signal based above 0V.R2, C5 and R4 form a High-Pass filter (HPF1) with a cutoff frequency of 3.6 kHz [ Fc = 1 / (2 * pi * (R2 + R4) * C5) ].The opamp DC gain is set to be about 100x by R8 and R7.Another High-Pass filter (HPF2) is formed by R7 & C7 with a cutoff frequency of 1.94 kHz [ Fc = 1 / (2 * pi * R7 * C7) ].A Low-Pass filter (LPF1) is formed by R8 & C8 with a cutoff frequency of 1.94 kHz [ Fc = 1 / (2 * pi * R8 * C8) ].

author: Zero999
author_rank: Super Contributor
timestamp: April 08, 2018, 10:33:35 pm
content: Quote from: Benta on April 08, 2018, 09:00:07 pmWhy? I remember you said something about it in another thread but didn't follow up with a proper explanation, so didn't take it on board and won't do, unless you provide one.Quote from: TopGunPk on April 08, 2018, 10:18:03 pmThe DC gain is not 100 but 1, which is correct. I think you made a typographical error when you said the DC gain is set to 100. I think you were talking about the AC gain being set to 100, which is correct.The op-amp is biased incorrectly. The non-inverting input is connected to 0V, when it should be biased at half the supply voltage. See the schematic below for how to bias the non-inverting input correctly.

author: TopGunPk
author_rank: Contributor
timestamp: April 09, 2018, 09:26:26 am
content: Hi Hero999By referencing the non-inverting input to Ground (0V), I get ground referenced ac signal from mic, which is easy to amplify, while with mid-supply referenced input, I get a DC offset (virtual ground at 1/2 supply) with the ac signal riding on top of it.Is this the right way to do it ? or should I use the mid-supply reference with the mic ac signal riding on it ?

author: Benta
author_rank: Super Contributor
timestamp: April 09, 2018, 10:15:21 am
content: Quote from: Hero999 on April 08, 2018, 10:33:35 pmIt's extremely simple:you can not build a 4046 type II PLL without an active loop filter. (this is directly from Gardner)The dodgy TI app note claims that you can, and it'll never work.Here's the original thread. Please read the document:https://www.eevblog.com/forum/projects/using-4046-type-plls-successfully/

author: ogden
author_rank: Super Contributor
timestamp: April 09, 2018, 10:16:48 am
content: Quote from: TopGunPk on April 09, 2018, 09:26:26 amIf you ground-reference AC signal in single supply op-amp application, it (signal) goes outside opamp supply range. It simply won't work. Even if you somehow bring AC signal above 0V rail, most opamps are nonlinear close to voltage rails. You better put signal in the middle of opamp supply range, disregarding it's powered by dual supplies or single one.QuoteFor signal itself it does not make much difference - ground is made by proper dual supply having own regulator for each rail or just by splitting voltage of single supply in half.

author: Zero999
author_rank: Super Contributor
timestamp: April 09, 2018, 11:27:24 am
content: Quote from: TopGunPk on April 09, 2018, 09:26:26 amThe input signal should be biased around half the op-amp's output voltage swing, which is typically1/2VSUPPLY.In the circuit you posted, the +input is directly connected to 0V, which will mean the output will sit at 0V, rather than at the mid supply. What do you think will happen when the signal from the microphone, goes below zero? Even if the op-amp's inputs work, slightly below the negative rail, the output certainly doesn't. At best it will clip the negative part of the signal off, worst case it will behave unpredictably.The top right circuit, in my previous post, shows how to correctly bias a single supply non-inverting amplifier. You need the output to be biased at half the supply voltage, so the AC coupling capacitor on the output should be omitted.The filter in your previous circuit will work, but probably has too lower Q for your application. Consider a more narrow band filter with a higher Q, giving a sharper peak at 3.95kHz.Filter design often involves relatively complex maths. Here's a basic guide to designing filters.http://www.vyssotski.ch/BasicsOfInstrumentation/FilterDesignIn30Seconds.pdf

author: ogden
author_rank: Super Contributor
timestamp: April 09, 2018, 11:32:27 am
content: Quote from: Hero999 on April 09, 2018, 11:27:24 amThis one is good as well:http://www.analog.com/designtools/en/filterwizard/

author: Zero999
author_rank: Super Contributor
timestamp: April 09, 2018, 12:36:38 pm
content: That's cheating.To use a calculator, one needs to be familiar with terms, such as the Q. Here's are some sites which discuss that.http://sound.whsites.net/project63.htmhttp://www.circuitstoday.com/band-pass-filters

author: Peabody
author_rank: Super Contributor
timestamp: April 09, 2018, 02:26:55 pm
content: Quote from: Hero999 on April 09, 2018, 11:27:24 amI wonder if in this case a ground-referenced input would work ok. After all, he isn't trying to amplify an audio signal. He just needs to *detect* the presence of a 4K audio carrier that could be sine, square, or whatever. I recently used an LM358 with ground-referenced input for a similar purpose, and its behavior was completely predictable. It tolerates input excursions below the negative rail, and in effect they are clipped. But he will still have 4K positive pulses per second which can be counted. I should say, though, that my circuit didn't have any filtering, and was DC coupled after the LM358. The filtering he will need may make mid-supply referencing necessary.

author: ogden
author_rank: Super Contributor
timestamp: April 09, 2018, 02:52:42 pm
content: Quote from: Peabody on April 09, 2018, 02:26:55 pmIt makes no sense to design inferior circuit, especially if proper design does not require any additional engineering or expensive components. If you want to save on two resistors then maybe simply reconsider whole project? Clipped signal contains lots of harmonics. It could be so that such "clipped circuit" will detect not only 4KHz but also 2nd harmonic of clipped 2KHz.

author: Zero999
author_rank: Super Contributor
timestamp: April 09, 2018, 05:32:28 pm
content: Quote from: ogden on April 09, 2018, 02:52:42 pmI agree biasing input at 0V is not optimal, but asking "why not?" is a valid question.The design could be simplified greatly, especially if the dynamic range doesn't need to be great and the background noise levels are low. If no electronic filtering or AGC is required, it may work with the input referenced to 0V. A Helmholtz resonator could be placed in front of the microphone, to act as a basic filter, then a comparator could convert the signal directly from the mic (no amplifier required) to a nice square wave, which could be counted by the micro-controller.Unfortunately, I don't think such as minimalist set-up would suit the original poster's requirements.

author: djnz
author_rank: Regular Contributor
timestamp: April 10, 2018, 04:04:37 am
content: Also, if the buzzer is a piezo buzzer, using a similar buzzer as the mic can give good results as their resonant frequencies will match...