A Sound (Frequency) Detection Circuit

From Makerpedia
Jump to navigation Jump to search

by Yuelin Kuang

Project Overview

This circuit functions as an audio signal processing system designed to detect whether a sound wave's frequency falls within a specified range. When the microphone identifies a sound with a frequency above 424 Hz and below 1120 Hz, the circuit outputs a digital high signal. This page provides instructions for constructing this frequency detector and explains how it can be tailored to suit your needs. For example, you can adjust the detection frequency range or incorporate additional filters to enable the detection of multiple frequency ranges.

The key components of this circuit include some high-pass filters, low-pass filters, an inverting amplifier, two single-supply full-wave rectifiers, two averagers, and a comparator. The microphone serves as the detector, converting sound waves into electrical signals. Subsequently, a band-pass filter is employed to extract signals within a specified frequency range. At the end, the circuit determines whether the frequency falls within the specified range by comparing the average amplitude of the filtered signal to a threshold set at 1/Sqrt[2] times the average amplitude of the unfiltered signal.

It's worth noting that the threshold is not a fixed voltage value. In fact, I started with this idea and worked on it for a whole week. However, this approach encountered problems because most microphones are significantly more sensitive to high-frequency sound, making it challenging to effectively attenuate the high-frequency signals due to their inherently large amplitudes. The adaptive thresholding method solved this issue.

Tools and Materials

  • Resistors: 1 kΩ (1), 5 kΩ (1), 5.3 kΩ (1), 10 kΩ (12), 20 kΩ (4), 22.5 kΩ (1) , 45 kΩ (1) , 50 kΩ (2), 100 kΩ (2), 309 kΩ (1), 715 kΩ (1), 10 MΩ (2).
  • Capacitors: 1 μF (2), 10 nF (3), 22 nF (1), 15 pF (2), 100 μF (2).
  • Op amps: LF411 (7), LM311 (1).
  • Diodes: 1N4007 (2).
  • An electret condenser microphone.
  • A PB-505 prototyping board or a bread board with +5V, +15V, and -15V power supplies.
  • An oscilloscope with several probes for signal monitoring.

Step-by-Step Instructions

Build the sound detection circuit as shown. The input comes from a 5V DC power supply, and a resistor of 5 kΩ is connected in series with the microphone to avoid current overflow. The power supply for a microphone can range from 3V to 9V, but the current-controlling resistor must be adjusted proportional to the power supply. A 1 μF capacitor is added to eliminate the DC offset. We don’t need the DC offset because there is no sound with zero frequency. Note that the electret condenser microphone is not a power source by itself. We can think of it as a resistor with resistance that varies with sound waves (though not precisely). To check the functionality of the microphone, you can play a test tone and measure the voltage directly after the capacitor. At this stage, the output should be around 30 mV. For all subsequent steps, all voltages should be measured relative to the ground.

Build an inverting amplifier as shown and connect it to the output from the sound detector. This amplifier has a gain factor of R3/R2 = 5 MΩ/1 kΩ, which is around 5000. However, taking the impedance of the sound detection circuit into account, the gain factor is actually much smaller than 5000. In fact, it only amplifies the audio signal to the order of some volts. Note that R3 = 5 MΩ (achieved by two 10 MΩ resistors in parallel) is intentionally chosen to be large such that the impedance from the sound detector matters less. I chose to build an inverting amplifier because the gain factor calculation is simpler and the phase shift in sound wave is not a concern, but you could also build a non-inverting amplifier alternatively.

Build a single-supply full-wave rectifier as shown and connect it to the output of the amplifier. This single-supply full-wave rectifier is adapted from this online source: https://www.analog.com/en/technical-articles/build-a-fullwave-rectifier-circuit-with-a-singlesupply-op-amp.html. The op amps we used here are LF411 with rail voltages at +/-15V. The diode at the output of the first op amp ensures that when the input signal is negative, the first op amp is cut off, but based on the voltage division of R4+R5 to R6, the voltage at the junction between R5 and R6 should still be half the input. Then, the second op amp amplifies this signal by a factor of 2 and inverts it as well, resulting in an overall positive output from a negative input. When the input swings positive, the first op amp amplifies it by a factor of -1/2, while the second op amp amplifies it by a factor of -2. Together, they keep the input unchanged when it is positive. It’s crucial to note that the ratios of the resistance values ensure the correct amplitude of the output signal, so they cannot be changed.

Build an averager as shown and connect it to the output of the rectifier. This averaging circuit yields the average of our rectified signal. It is adapted from the precision average reading detector in this online source: https://sound-au.com/appnotes/an012.htm. The average of an AC signal can only be taken for a rectified AC signal. Otherwise, the average will always be zero. The averaging functionality is achieved by the large time constant controlled by R9 and C3. The values of R9 and C3 I suggested here have a time constant of 1 s, which works well for our sound signals falling within the frequency range comfortable for human ears, spanning from hundreds to thousands of Hz. After the averager, we will have a DC signal that is approximately 0.637 times the peak voltage of the original rectified signal. This average value will be used together with a voltage divider to set the threshold for the comparator at the end. Later in this circuit, we will need to another full-wave rectifier and another averager. You can choose to build them now or wait until the band-pass filter (Step 5) is built. If you opt to build them now, you may use my circuit layout as a reference for organizing the functional blocks.

Build a band-pass filter as shown. Before we go on to set the threshold voltage for the comparator, let’s revisit the output from the inverting amplifier that we built in Step 2 and obtain a filtered signal first. In this step, our goal is to build a band-pass filter that filters away the signals whose frequencies are outside our designated detection range. My initial attempt with a simple passive RC band-pass filter encountered issues with unusual charging and discharging of capacitors. Upon consulting with Melissa, we were not able to figure out the source of this problem. In search of alternatives, I found this single-supply, second-order, Sallen-Key band-pass filter., which is similar to a normal passive second-order filter but uses an active component (op amp) as a buffer to stabilize the output. Just like any other band-pass filter, it is composed of a high-pass filter followed by a low-pass filter. Being a second-order filter, it provides a sharper cut-off on both sides of the band because its cutoff frequency is controlled by two pairs of resistor and capacitor. For comprehensive documentation, refer to this source: https://www.ti.com/lit/an/sboa229/sboa229.pdf?ts=1700371619521. The resistor and capacitor values specified here are designed for a cutoff frequency of 500 Hz for the high-pass filter and 1000 Hz for the low-pass filter. I will briefly walk through the calculation here in case you would like to change the range of detection frequency. Let m be some scaling factor. The cutoff frequency f_c of the high-pass filter is controlled by C4, C5, R10, and R11. If C4 = C5 = 1/(m*2πf_c), R11 is m/Sqrt[2], and R10 is 2R11. You can pick some convenient values for C4 and C5 and then calculate m based on the cutoff frequency desired. Similarly, f_c for the low-pass filter is controlled by R13, R14, C6, and C7. If R13 = R14 = m, C6 must be 1/(Sqrt[2]*m*2πf_c), and C7 is 2C6. You can pick some convenient values for R13 and R14 and then calculate the capacitors required based on the cutoff frequency you want. One thing to note about my design is that I incorporated a bias voltage of +2.5V at the positive input of the first op amp, which turned out to be redundant for our LF411 op amp operating between -15V and +15V, and this DC offset is soon removed by a straightforward high-pass RC filter connected at the output of this band-pass filter. I decided to leave it here for your reference because in some cases, if the op amp of your choice operates only in the positive range, you might need to bias the input AC signal such that the input stays within the permissible voltage range for the op amp to function properly.

Build another full-wave rectifier and averager as in Steps 3 and 4 if you haven’t already. Use them to rectify the signal coming out of the band-pass filter and get its average.

Build a voltage divider to set the comparison threshold. Now that we have two DC signals: one that is the average of the unfiltered signal (V_unfiltered) and the other that is the average of the filtered signal (V_filtered). These two voltages will be compared at a comparator. If V_filtered is higher than 1/Sqrt[2] times V_unfiltered, it means the sound signal is able to make it through the band-pass filter, so the frequency is within the range bounded by the cutoff frequencies, and the comparator should output high. Otherwise, the output will be low. Therefore, we want the threshold to be at 1/Sqrt[2] times V_unfiltered, and it can be achieved by a voltage divider. Due to constraints in the available resistance values at the Makerspace, I couldn't precisely attain 0.707*V_unfiltered. The values I used here set the threshold at 0.69*V_unfiltered instead, and as a result, the circuit responds high to a wider range of frequencies (424 Hz – 1120 Hz) than intended (500 Hz – 1000 Hz). For precise frequency control, you may need to adjust this voltage divider slightly.

Finally, we add the LM311 comparator in. The threshold voltage that we set at Step 7 will be connected to the negative input of the LM311, and the average of the filtered signal will be sent to the positive input. We choose an LM311 comparator here because it can operate between 0 and 5V, and its output can operate most CMOS and TTL loads. The comparator circuit is adapted from this source: https://www.electronics-tutorial.net/analog-integrated-circuits/op-amp-comparators/comparator-ic-lm-311/. The resistor at the end serves as a pull-up resistor. In addition to Pin 1 (the ground pin), Pin 4 (known as V_EE) is also grounded (though I didn’t draw it out here). The output from the comparator is the digital output desired.