Author Topic: Beep detection circuit  (Read 5544 times)

0 Members and 1 Guest are viewing this topic.

Offline TopGunPkTopic starter

  • Contributor
  • Posts: 21
  • Country: pk
Beep detection circuit
« on: April 06, 2018, 10:10:07 pm »
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

 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19802
  • Country: gb
  • 0999
Re: Beep detection circuit
« Reply #1 on: April 06, 2018, 11:14:07 pm »
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
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 808
  • Country: ca
Re: Beep detection circuit
« Reply #2 on: April 06, 2018, 11:50:06 pm »
What kind a controller? Can you re-program it, to do sound detection in software?
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4700
  • Country: au
  • Question Everything... Except This Statement
Re: Beep detection circuit
« Reply #3 on: April 07, 2018, 12:01:12 am »
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
 

Offline TopGunPkTopic starter

  • Contributor
  • Posts: 21
  • Country: pk
Re: Beep detection circuit
« Reply #4 on: April 07, 2018, 08:02:11 am »
Thanks Hero999

My 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 ?
 

Offline TopGunPkTopic starter

  • Contributor
  • Posts: 21
  • Country: pk
Re: Beep detection circuit
« Reply #5 on: April 07, 2018, 08:31:59 am »
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.
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 808
  • Country: ca
Re: Beep detection circuit
« Reply #6 on: April 07, 2018, 12:26:10 pm »
To solve it in analog world, look at the super-regenerative receiver architecture.  In both your options:
Quote
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.
you 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. 
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6894
  • Country: nl
Re: Beep detection circuit
« Reply #7 on: April 07, 2018, 12:40:19 pm »
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.
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: us
Re: Beep detection circuit
« Reply #8 on: April 07, 2018, 12:41:13 pm »
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.

 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19802
  • Country: gb
  • 0999
Re: Beep detection circuit
« Reply #9 on: April 07, 2018, 08:17:35 pm »
Thanks Hero999

My 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 ?

If 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_BwE
http://www.farnell.com/datasheets/2370673.pdf?_ga=2.216633558.1797950326.1523104475-47418993.1417808164&_gac=1.204279460.1521927514.EAIaIQobChMI7eL33vWF2gIVTrftCh3lBAcPEAQYAyABEgKzePD_BwE

If 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.aspx

An 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
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3306
  • Country: gb
Re: Beep detection circuit
« Reply #10 on: April 08, 2018, 02:37:18 pm »
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.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15103
  • Country: fr
Re: Beep detection circuit
« Reply #11 on: April 08, 2018, 03:34:54 pm »
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.

Quite 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.

 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19802
  • Country: gb
  • 0999
Re: Beep detection circuit
« Reply #12 on: April 08, 2018, 08:25:32 pm »
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.

Quite 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.
I 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.
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7990
  • Country: ca
Re: Beep detection circuit
« Reply #13 on: April 08, 2018, 08:36:52 pm »
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.

Quite 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.
I 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.
Use 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.

 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6134
  • Country: de
Re: Beep detection circuit
« Reply #14 on: April 08, 2018, 09:00:07 pm »
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

Please do not refer to that TI application note. It's one of the dodgiest around and will not lead to success.

 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15103
  • Country: fr
Re: Beep detection circuit
« Reply #15 on: April 08, 2018, 09:27:22 pm »
I 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.

Depending 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.
 

Offline TopGunPkTopic starter

  • Contributor
  • Posts: 21
  • Country: pk
Re: Beep detection circuit
« Reply #16 on: April 08, 2018, 10:18:03 pm »
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) ].


« Last Edit: April 08, 2018, 10:22:08 pm by TopGunPk »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19802
  • Country: gb
  • 0999
Re: Beep detection circuit
« Reply #17 on: April 08, 2018, 10:33:35 pm »
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

Please do not refer to that TI application note. It's one of the dodgiest around and will not lead to success.
Why? 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.

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) ].
The 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.
« Last Edit: April 09, 2018, 11:04:31 am by Hero999 »
 

Offline TopGunPkTopic starter

  • Contributor
  • Posts: 21
  • Country: pk
Re: Beep detection circuit
« Reply #18 on: April 09, 2018, 09:26:26 am »
Hi Hero999

By 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 ?
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6134
  • Country: de
Re: Beep detection circuit
« Reply #19 on: April 09, 2018, 10:15:21 am »
Why? 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.

It'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/

 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Beep detection circuit
« Reply #20 on: April 09, 2018, 10:16:48 am »
By referencing the non-inverting input to Ground (0V), I get ground referenced ac signal from mic, which is easy to amplify

If 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.

Quote
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.

For 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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19802
  • Country: gb
  • 0999
Re: Beep detection circuit
« Reply #21 on: April 09, 2018, 11:27:24 am »
Hi Hero999

By 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 ?
The input signal should be biased around half the op-amp's output voltage swing, which is typically 1/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
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Beep detection circuit
« Reply #22 on: April 09, 2018, 11:32:27 am »
Filter design often involves relatively complex maths. Here's a basic guide to designing filters.
http://www.vyssotski.ch/BasicsOfInstrumentation/FilterDesignIn30Seconds.pdf

This one is good as well: http://www.analog.com/designtools/en/filterwizard/
 
The following users thanked this post: Zero999, BrianHG

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19802
  • Country: gb
  • 0999
Re: Beep detection circuit
« Reply #23 on: April 09, 2018, 12:36:38 pm »
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.htm
http://www.circuitstoday.com/band-pass-filters
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: us
Re: Beep detection circuit
« Reply #24 on: April 09, 2018, 02:26:55 pm »
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.


I 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf