Toggle button missing
Signature missing

Image missing16-band audio spectrum analyzer

Image missingReturn to projects list

This project started on February 13th, 2017, and was completed on May 18th, 2017. It involved five students:

  • Cody Smith
  • Andrew Eddins
  • Andrew Brinsko
  • Coleman Green
  • Jake Rubin

The goal is to build an electronic device that is capable of filtering the frequencies of an audio signal from 20 Hz to 20 kHz across 16 channels, and display the level of each channel on a corresponding 10-segment bargraph. Before we dive into this project, you may want to watch a demonstration of the finalized device:

The schematics, layout files, and Gerber files are available for download here.

The theory

From Fourier's theorem, any time-dependent signal f(t) can be written as a superposition of imaginary exponentials:

Image missing

Here, ω is the angular frequency of a given exponential, g(ω) is its (complex) amplitude and is called the “spectrum” of the signal. Thus, the goal of our project is to build a device that displays a discretized version of the spectrum. The figure below shows the global diagram:

Image missing
  • Filters: These are band-pass filters that measure the level of the frequencies that fall within a given bandwidth. Each filter also includes a peak detector that converts its AC response into a DC signal, and keeps a short memory of the peak value in order to ease the visualization of the signal.
  • Display: This circuit includes a 10-level voltmeter that measures the level of the DC signals and activates the corresponding number of segments of the bargraphs.
  • Main circuit: The main circuit is divided into three subcircuits:
    • Power supply: The device makes use of operational amplifiers (op-amps) that require a symmetric power supply. Here, we will build a power supply that delivers voltages of +5V, 0V, -5V with a maximum current of 1A.
    • Audio mixer: This part of the circuit takes the audio signal from either a stereo input via RCA connectors (Cinch connectors) which is mixed into a single signal, or from an internal microphone. It has a stereo output, which is just a copy of the stereo input signal, so that the sound can be sent to speakers via an amplifier. The audio mixer allows the adjustment of the input signal level so that it falls within values that can be displayed by the bargraphs.
    • Multiplexer/demultiplexer unit: This part of the circuit distributes a copy of the signal from the audio mixer to each of the 16 filters, and periodically sends the output signal from one of the filters to the display. At the same time, a decoding signal is sent to the display in order to inform it about which filter the output signal is from.

The filters

If you are not comfortabable with complex impedances, watch this tutorial.

If you are not comfortabable with operational amplifiers, watch this tutorial.

We use the following circuit:

Image missing

We want to determine the complex voltage gain G=Vout/Vin. To this end, we start by writing Kirchhoff's junction rule at points A and B:

Image missing
Image missing

The feedback between the output of the op-amp and its inverting input guarantees that it works in the linear regime. As a result, the op-amp automatically adjusts its output in order to keep a zero potential at point B:

Image missing

Substituting this value into the two Kirchhoff's equations above, and solving for Vout/Vin, we obtain the complex gain:

Image missing

It is clear from the expression above that G vanishes only for ω=0 and ω=+∞. As a result, the circuit is a band-pass filter, as required. The resonant frequency ωo is obtained by setting the derivative of the gain's modulous to zero, and keeping only the real and positive solution for the frequency:

Image missing

Substituting the resonant frequency into the expression for the gain, we obtain the maximum gain, which is real and negative, and implies that the output signal is in opposite phase with the input signal:

Image missing

Something that is crucial to consider is the bandwidth Δω=ω+- of the filter, where ω+ and ω- are the cutoff frequencies. These cutoff frequencies are defined as those for which the power gain is half of the maximum power gain. In terms of the voltage gain, this implies:

Image missing

Taking the square of the above equation and substituting the expression for G(ω), we obtain a 4th degree equation for ω±:

Image missing

This equation is easily solved for ω±2, and the solution for ω± is given by taking the positive root. The resulting expression for the bandwidth Δω seems to be complicated:

Image missing

However, it “miraculously” simplifies well. This can be easily seen by calculating first the square of the bandwidth, then taking the square root of it:

Image missing

The figure below summarizes the features of the filter:

Image missing

In order to characterize how selective the filter is, we define the Q-factor as the ratio of the resonant frequency to the bandwidth:

Image missing

With this definition, the higher the Q-factor, the more selective the filter. The Q-factor must be high enough so that only one bargraph displays a maximum level when a single frequency is injected, but not too high otherwise no signal will be displayed if the frequency falls between the resonant frequencies of two neighboring bargraphs. Our choice for a suitable Q-factor is explained below, as well as our choice for the 16 resonant frequencies. The maximum gain can be arbitrarily chosen to be unity. Assuming that a choice for ωo, Gmax, and Q has been made, and introducing the linear resonant frequency Foo/2π which is more human-friendly than the angular frequency ωo, we can determine the values of the resistors R1, R2, R3 by inverting the expressions above:

Image missing

The values for C1 and C2 can be freely chosen in order to obtain reasonable values for R1, R2, R3. We want these values to be large enough in order to avoid excessively large currents, but not too large in order to keep a good signal/noise ratio.

Choosing the gain, the resonant frequencies, and the Q-factor

As already mentioned, the gain can be arbitrarily set to unity, Gmax=1, since the audio mixer allows to adjust the level of the input signal (hence the level of the signal that comes out of the filters). For the resonant frequencies, we have to consider the fact that the perception of sounds by humans as “higher” or “lower”, the so-called “pitch”, is not directly proportional to the frequency. Instead, it is observed that the pitch increases by a constant step when the frequency is multiplied by a constant number. In order to determine the exact relationship between pitch and frequency, it is common to define the pitch associated to a frequency of 440Hz as a A4. Multiplying the frequency by two, 880Hz, is perceived as a A5, while dividing it by two, 220Hz, is perceived as a A3. The pitch change between Ai and Ai+1 is called an “octave” and is divided into 12 semitones. It follows that the frequency of a pitch that corresponds to s semitones above (s>0) or below (s<0) the A4 reference pitch is given by:

Image missing

Thus, the frequency increases exponentially with the pitch as perceived by humans. We want the resonant frequencies to be evenly distributed from 20Hz to 20kHz in terms of pitch. In other words, we want the number of semitones between the resonant frequencies to be a constant. In order to determine this constant, we start by inverting the above equation in order to obtain the number of semitones above or below A4 that correspond to a given frequency F:

Image missing

We want to divide the range of semitones between 20Hz and 20kHz into 15 constant intervals. Thus the number of semitones no between the resonant frequencies must be:

Image missing

It follows that the resonant frequency Fk of the kth filter is given by:

Image missing

As a result, the resonant frequencies are:

Filter #12345678910111213141516
Frequency (Hz)20.031.750.279.61262003175027961.26k2.00k3.17k5.02k7.96k12.6k20.0k

Finally, we need to determine a suitable Q-factor. We don't want the bandwidths of neighboring filters to overlap otherwise the filters would respond to the same frequencies, and we don't want to leave any gap between those bandwiths otherwise some frequencies would not be detected. Thus, it makes sense to choose the bandwidths so that they touch each other. So, the bandwidth ΔFk of filter k must be equal to Fk+1/2-Fk-1/2. As a result, the Q-factor is the same for all filters and given by:

Image missing

Having chosen the gain, the Q-factor, and the resonant frequencies, we can finally determine suitables values for C1, C2, R1, R2, R3:

CalculatedActual value
C1 (F)C2 (F)R1 (Ω)R2 (Ω)R3 (Ω)R1 (Ω)R2 (Ω)R3 (Ω)
Filter 1 100n 100n 171k 20.8k 342k 180k 20k 330k
Filter 2 100n 100n 108k 13.1k 216k 110k 13k 220k
Filter 3 100n 100n 68.2k 8.27k 136k 68k 8.2k 130k
Filter 4 100n 100n 43.0k 5.21k 86.0k 43k 5.1k 82k
Filter 5 100n 100n 27.2k 3.29k 54.3k 27k 3.3k 56k
Filter 6 100n 100n 17.1k 2.08k 34.2k 18k 2k 33k
Filter 7 100n 100n 10.8k 1.31k 21.6k 11k 1.3k 22k
Filter 8 10n 10n 68.2k 8.27k 136k 68k 8.2k 130k
Filter 9 10n 10n 43.0k 5.21k 86.0k 43k 5.1k 82k
Filter 10 10n 10n 27.2k 3.29k 54.3k 27k 3.3k 56k
Filter 11 10n 10n 17.1k 2.08k 34.2k 18k 2k 33k
Filter 12 10n 10n 10.8k 1.31k 21.6k 11k 1.3k 22k
Filter 13 1n 1n 68.2k 8.27k 136k 68k 8.2k 130k
Filter 14 1n 1n 43.0k 5.21k 86.0k 43k 5.1k 82k
Filter 15 1n 1n 27.2k 3.29k 54.3k 27k 3.3k 56k
Filter 16 1n 1n 17.1k 2.08k 34.2k 18k 2k 33k

The figure below shows the gain of the 16 filters.

Image missing

Peak detector

The output of each filter is sent through a peak detector that converts the AC signal into a DC signal, and generates a time-delayed decay in order to ease the visualization of the signal. This is realized with the circuit below:

Image missing

If the input voltage is higher than the output voltage, then the op-amp adjusts its output in order to forward-polarize the diode and keep the circuit's output at the same potential as the input, which results in the capacitor being instantly charged with the same value as the input voltage. If the input voltage is lower than the output voltage, then the op-amp saturates to -Vsat and the diode is reverse-polarized, blocking any current from flowing. Thus the capacitor and resistor are decoupled from the rest of the circuit and the capacitor discharges across the resistor. As a result, the output voltage decreases exponentially with a time constant RoCo. Therefore, the op-amp and the diode act as an ideal diode with no threshold and a vertical I(V) characteristics. As a result, the circuit keeps a short-time memory of the input signal's peak voltage.

In our case, we want the memory of the peak voltage to drop down to half its initial value in about one second, which implies to choose the resistor and the capacitor such that RoColn(2)=1. For example, we can choose Ro=1.2MΩ and Co=1μF. The figure below shows an example of response to an arbitrary input signal:

Image missing

For the realization, it is interesting to keep the filters with their peak detectors on separate circuit boards, so that they can be easily replaced by others with different characteristics if needed. Here, a good solution is to make use of the TL084 integrated circuit that includes four op-amps, allowing us to incorporate two filters with their peak detectors. The figure below shows the final schematic of the circuit, the corresponding PCB image, and a 3D preview of the assembled circuit board. The final device will include 8 circuit boards like this.

Image missing

The display

The output level of each peak detector needs to be converted into a number of bargraph segments to be turned on. We want the first LED segment to be on when the signal level is greater than a given reference potential V1, the two first LED segments to be on when the signal level is greater than a given reference potential V2, ..., and all ten segments to be on when the signal level is greater than a given reference potential V10. This can be done by using a so-called “LED driver” composed of op-amps used as “comparators”. The figure below shows the circuit:

Image missing

The reference potentials V1, V2, ..., V10 are determined by choosing suitable values for the resistors R0, R1, R2, ..., R10, which constitute a voltage divider. The reference potential Vi is easily determined as:

Image missing

Each reference potential Vi is connected to the non-inverting input of the corresponding op-amp. Because of the absence of feedback between the output and the inverting input of the op-amps, they work in the non-linear regime. As a result, the ith op-amp saturates to a high potential as long as the input signal Vsig remains lower than Vi. This prevents any current from flowing across the ith LED segment, which remains off. When the input signal Vsig becomes greater than Vi, the op-amp saturates to a low potential. This forward polarizes the LED which comes on. The 220Ω resistors are there to avoid excessive currents in the LED segments.

One problem with the above circuit is that, in addition to the LED segments, it includes 10 op-amps and 21 resistors. We need one LED driver for each of the 16 bargraphs, which would require a total of 160 op-amps and 336 resistors. In order to solve this problem, we use the LM3914 integrated circuit which implements the above circuit (without the LEDs) in a small 18-pin dual in-line package (DIP). Still, we need in principle 16 LM3914 integrated circuits, one for each bargraph. In order to reduce further the number of components, we use a multiplexing/demultiplexing technique. This technique consists in controlling only one bargraph at a time while the others are turned off, and switching sufficiently fast to the next bargraph so that we have the impression that they are all on at the same time. As a result, only one LM3914 is needed, which is connected to the cathodes of the 16 bargraphs. The anodes are controlled separately by the main board that takes care of turning on only one bargraph at a time, while sending the output signal of the corresponding filter and peak detector to the LM3914. The details on how the multiplexer/demultiplexer unit achieves this are given below. The figure below shows the final schematic of the display, the corresponding PCB image, and a 3D preview of the assembled circuit board.

Image missing

The main circuit

The main circuit is composed of three subcircuits: The power supply, the audio mixer, and the multiplexer/demultiplexer unit.

The power supply

The integrated circuits used in the device need a DC power supply. In particular, the op-amps must be supplied with a symmetric voltage. Here, we can choose to work with the minimum voltage of +5V, 0V, -5V that will satisfy all integrated circuits. The power supply must be able to deliver a current of 1A or more in order to make sure that there is enough current to supply all circuits and LEDs. We can use a transformer that converts the 120V AC from a wall outlet into two 6V AC sources. This is done by using a primary coil that induces an electromotive force into a secondary coil that is tapped at its center in order to divide it into two equal electromotive forces. The electromotive force induced into the secondary coil is equal to the ratio of the number of turns of the secondary to the primary. By using a ratio of 1/10, the electromotive force induced into the secondary is 12V AC, hence two times 6V AC. Then this symmetric AC voltage is converted into a symmetric DC voltage as described below. For this, we use the following circuit:

Image missing

First, consider only the transformer and the bridge rectifier (the four diodes) in the above picture, and assume that no other components are connected. It is easy to see that, whether the potential difference between the secondary's terminals 1 and 2 is positive or negative, the potential at the bridge's + terminal is always positive and the potential at the potential at the - terminal is always negative (with respect to the ground). These potentials, in absolute value, are slightly less than those at the secondary terminals because of the nearly constant voltage drop across the diodes. If we add now the rest of the circuit, the large 470μF capacitors at the terminals of the bridge will charge instantly across the diodes when they are forward-polarized, and will discharge exponentially across the two regulators when the diodes are reverse-polarized. Therefore, the potential at the secondary's terminals 1 and 2, the bridge's terminals + and - without the rest of the circuit, and with the rest of the circuit take the form as shown on the figure below:

Image missing

The signals present at the inputs of the two regulators (bridge + and - with load) are now sufficiently rectified so that the regulators can work properly and output constant potentials of +5V and -5V. The two 100nF capacitors are there in order to remove any remaining noise. They block the flow of DC currents, and their impedance is small for the typical high frequencies associated with noise, creating a short to kill it. Note that it would be a mistake to think that large electrolytic capacitors would be able to remove the noise better than the small 100nF capacitors, since they have (in principle) a even lower impedance. However, electrolytic capacitors have a non negligible inductance that actually makes their impedance increase at high frequencies. It is therefore necessary to use small capacitors with negligible inductance in order to filter out the noise.

The audio mixer

The audio mixer allows us to select the audio input from RCA connectors or from an internal microphone. For the microphone, we use an electret condenser microphone (ECM) which has the advantage of being very small. The ECM contains a piezoelectric crystal that generates an AC voltage proportional to the sound's level. The AC voltage generated is way too small for practical applications. This is why the ECM includes a field-effect transistor (FET) in order to amplify it. Consider the figure below:

Image missing

The FET requires a supply voltage Vdd via a resistor Ro connected to the drain (D). The ground is connected to the source (S). The FET works in such a way that the current i that enters into the drain depends linearly on the potential VG present at the gate (G), which is the voltage generated by the piezoelectric crystal:

Image missing

In the above equation, io is a constant current that depends on Ro and Vdd, and k is a constant coefficient. Applying Ohm's law to the resistor, we deduce the value of the potential at point A:

Image missing

As a result, VA oscilates around the constant value Vdd - Roio, and the voltage VG generated by the piezoelectric crystal is amplified by a factor -Rok. For the ECM to work properly, the constructor recommends using Ro=2.2kΩ with a supply voltage Vdd between 3V and 10V. Here we will use Vdd=5V. Still, the oscillations of the voltage VA are too small and need to be amplified. Also, we need to have a signal that oscillates around zero instead of the constant value Vdd - Roio (typically between 2V and 4V), otherwise the signal will saturates when it will be amplified. This is done by connecting the above circuit to an amplifer via a decoupling capacitor, as shown below:

Image missing

The decoupling capacitor Co blocks DC currents, and has a capacitance that is sufficiently large so that its impedance for frequencies above 20Hz is small compared to R1. For these frequencies, the capacitor behaves as a wire. Also, R1 is chosen sufficiently large compared to Ro so that the potential VA is unaffected by the current drawn across the capacitor, thus the above expression remains valid. As a result, only the AC part of VA goes through the capacitor, and the potential VB oscillates proportionally to VG around zero:

Image missing

The feedback resistor R2 between the output of the op-amp and the inverting input guarantees that the op-amp works in the linear regime. This implies that the potential at the inverting input is the same as that at the non-inverting input, hence zero. Noting that the current i1 across R1 must be the same as the current i2 across R2, and applying Ohm's law, it follows that:

Image missing

As a result, the voltage VG generated by the piezoelectric crystal is amplified again, for R2>R1, and the output voltage takes the form:

Image missing

Although the values VG and k are unknown, choosing R1=10kΩ, R2=1MΩ, Co=2.2μF satisfies the conditions of validity of the above equations, and the measured output signal Vout has a level comparable to the signal's level typically present on RCA inputs. We use a switch that allows us to select between the microphone or the RCA inputs. The RCA stereo signals are mixed into a single signal that is equal to their average. Then the selected input signal needs to be amplified again or attenuated in order to fall within a level that can be displayed by the bargraphs without saturating. This is done by using another op-amp with an ajustable resistor for the feedback. The final circuit for the audio mixer is:

Image missing

When the switch is up, the microphone's signal is selected and the previous value is multiplied by -R4/R3, leading to:

Image missing

When the switch is down, the RCA inputs are selected, and the output voltage takes the form:

Image missing

Finally, choosing R3=1kΩ and the adjustable resistor R4 from 0 to 100kΩ allows to bring the signal level to a suitable value that can be displayed by the bargraphs.

The multiplexer/demultiplexer unit

This part of the circuit sequentially selects the output of a given filter, and sends it to the display driver. At the same time, the circuit sends the supply voltage to the corresponding bargraph. This is done by using four integrated circuits: A 16-line multiplexer, a 16-line demultiplexer, a timer, and a 4-bit binary counter. The functional diagram is shown below:

Image missing

The timer generates a square signal that oscillates between nearly 0V to nearly 5V. This is done by using the NE555 integrated circuit, as shown below:

Image missing

The NE555 works as follows: When the trigger voltage falls below 33% of Vcc the output goes high, when the threshold voltage rises above 67% of Vcc the output goes low. By connecting a capacitor C and a resistor R as shown, the circuit generates a square wave. Initially, the capacitor C is discharged, the trigger voltage is low, and therefore the output is high. Then the capacitor charges across the resistor, until the threshold reaches a high enough potential and resets the output to a low value. The capacitor then discharges across the resistor, until the trigger detects a low voltage and flips the output back to a high level, and the cycle keeps going on. Knowing that the typical time needed for a capacitor to charge or discharge across a resistor is τ=RC, we can estimate, without the need of any precise calculations, that the frequency of the square wave generated is roughly:

Image missing

This frequency is the frequency at which the circuit switches between the different bargraphs. This frequency must be high enough so that our persistence of vision gives us the illusion that the bargraphs are continuously on. It is commonly accepted that 30 images per second is sufficient to give this illusion. Here we can arbitrarily choose to double this value, and have each bargraph turned on and off 60 times per second. Since there are 16 bargraphs, this means that the frequency must be 960Hz. Using R=47kΩ and C=10nF satisfies this requirement. The additional 10nF capacitor between pins 1 and 5 is recommended by the constructor for the stability of the circuit.

The clock signal generated by the timer is then used to control a 4-bit binary counter. For this, we can use the HC393 integrated circuit that includes two 4-bit binary counters (we use only one). Each time a new clock signal is received, the counter is incremented by one. the output of the counter is denoted by A,B,C,D, where A is the least significant bit (LSB) and D is the most significant bit (MSB). As a result, there are 24=16 possible values for the counter, from 0000 to 1111. When the value is 1111, a further clock signal brings it back to 0000.

The binary value is sent to a 16-line multiplexer and a 16-line demultiplexer, for which we use the HEF4067 and HC154 integrated circuits, respectively. The multiplexer selects one of its 16 inputs (In1, ..., In16), depending on the binary value (the address of the input), and outputs it so it is available for the display driver. The demultiplexer has 16 outputs (O1, ..., O16) that are in a high level state, except the one whose address corresponds to the binary value which is in a low level state. The values of these outputs are inverted by using PNP transistors and used to supply the bargraphs. As a result, only the bargraph that corresponds to the filter selected by the multiplexer is supplied with current and displays the corresponding level.

Final main circuit

The power supply, the audio mixer, and the multiplexer/demultiplexer unit can be built on the same board. The filters and the display are then plugged to it. The final schematic, PCB image, and 3D preview of the main board are shown below:

Image missing Image missing Image missing

Image missingReturn to projects list

Subscribe to my YouTube channel Image

Not sure you want to subscribe? Take a peek at the description of the Blue Moonshine channel to get an idea of its contents.

Last update of this page: 29 February 2024 at 8:48am