Treble and Bass Detector

11
CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride Treble and Bass Detector The main idea of this project is to input an audio signal with a microphone and depending on the frequency of the input, two rows of LED’s will light up corresponding to the intensity of the bass and treble using the Arduino and a high and low pass filters for the treble and bass respectively. System Requirements Takes audio input and lights up LEDs sequentially based on the low and high frequencies of the input. Essentially acting as an audio level meter. System Specifications Use two bandpass filters to separate treble and bass from a given audio signal that is converted from a sound wave to an electromagnetic analog signal. This analog signal would then be ran into three separate amplifiers and then sent into the Arduino’s analog to digital converter to allow for interpretation. A modified digital signal is then sent to two sets of four LEDs corresponding to the intensity of the treble and bass of the audio input. System Architecture Figure 1 below shows the system diagram of the treble and bass detector. The microphone converts a sound wave into an electromagnetic analog signal. Since the output of the microphone is in the millivolts spectrum, the signal must be amplified. The signal is then run into an amplifier with a gain of eleven. This signal is then ran into two separate bandpass filters. The bandpass filter corresponding to the bass signal passes frequency between the ranges of 8 to 500 Hertz and the treble filter passes signals from 2,000 to 10,000 Hertz. The outputs of the two filters are then ran through two separate operational amplifiers with a gain of two to help with any loss of gain from the filters. The Arduino’s analog to digital converter interprets both of these signals and outputs on the digital pins zero through seven to determine which LED will turn on depending on the input to the ADC on pins A0 and A1.

Transcript of Treble and Bass Detector

Page 1: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

Treble and Bass Detector  The main idea of this project is to input an audio signal with a microphone and depending on the frequency of the input, two rows of LED’s will light up corresponding to the intensity of the bass and treble using the Arduino and a high and low pass filters for the treble and bass respectively.  

System Requirements Takes audio input and lights up LEDs sequentially based on the low and high frequencies of the input. Essentially acting as an audio level meter. 

System Specifications Use two bandpass filters to separate treble and bass from a given audio signal that is converted from a sound wave to an electromagnetic analog signal. This analog signal would then be ran into three separate amplifiers and then sent into the Arduino’s analog to digital converter to allow for interpretation. A modified digital signal is then sent to two sets of four LEDs corresponding to the intensity of the treble and bass of the audio input.  

System Architecture Figure 1 below shows the system diagram of the treble and bass detector. The microphone converts a sound wave into an electromagnetic analog signal. Since the output of the microphone is in the millivolts spectrum, the signal must be amplified. The signal is then run into an amplifier with a gain of eleven. This signal is then ran into two separate bandpass filters. The bandpass filter corresponding to the bass signal passes frequency between the ranges of 8 to 500 Hertz and the treble filter passes signals from 2,000 to 10,000 Hertz. The outputs of the two filters are then ran through two separate operational amplifiers with a gain of two to help with any loss of gain from the filters. The Arduino’s analog to digital converter interprets both of these signals and outputs on the digital pins zero through seven to determine which LED will turn on depending on the input to the ADC on pins A0 and A1.  

Page 2: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

 Figure 1: System Schematic of the Treble and Bass Detector 

System Design The microphone used the configuration in Figure 2 below. The 2.2 kΩ resistor acts as a pull­up on the output, and its value can vary between 1 kΩ and 5 kΩ. After testing the microphone it was revealed to have a limited output, with amplitudes around 100 mV. Because of this the output of the microphone was AC­coupled to an non­inverting amplifier with a gain of 11, allowing the microphone voltage to vary from 1 V to 2 V.  

Page 3: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

 

Figure 2: Microphone with Amplifier 

 

The bass frequencies were originally designed to range from 0­500 Hz, and the treble frequencies were designed for frequencies above 2 kHz, based on the sound spectrum. Thus the filters used to isolate the treble and bass from the microphone were originally a high pass and low pass filter respectively. However when testing the high­pass filter, high frequency noise was found to pass through in the MHz range. To counteract this, the high­pass filter was replaced by a band­pass filter for the treble frequencies, from 2 kHz ­ 10 kHz since the microphone used only detected up to 10 kHz. This eliminated the noise and allowed the treble frequencies to come through. This lead to a 10 kΩ resistor and 2.2 nF capacitor for the low pass 10 kHz filter, and a 10 kΩ resistor and 8 nF capacitor for the high pass 2 kHz filter. From here another non­inverting voltage amplifier with a gain of 2 was used to keep the voltage levels steady enough for the arduino ADC to read.  

The bass low­pass filter had the issue of its time constant holding the voltage output of the filter for too long. To counteract this, the low pass filter was also changed to a band­pass filter to reduce its time constant. However in order to keeps its frequency range, the low frequency of the band­pass was designed to be as low as possible, resulting in a 8 Hz ­ 500 Hz bandpass filter for the bass frequencies. This filter also had a non­inverting amplifier to make the filter active and keep the voltage levels steady. This filter used a 10 kΩ resistor and a 0.33 μF capacitor (three 0.1 μF in series) for the low­pass 500 Hz filter and a 0.1 μF capacitor and 200 kΩ resistor for the high­pass 8 Hz filter. 

From here the outputs of each filter were fed into a port on the on­board ADC of the arduino. The arduino interprets these voltages to sequentially light­up LED’s depending on the amount of treble and bass voltage. An elaboration on this process can be seen in the software section.   

The original idea to light up the LED’s was to use the arduino to drive a DAC, and use a specific analog voltage value for each ‘step’ of the treble or bass. This value would be sent to a comparator for each LED, and the voltage value sent from the DAC would be greater than the 

Page 4: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

voltages compared for certain number of LED’s. The IC’s used for the comparators, however, did not work, possibly a fault with the IC’s or breadboard used. As a result the LED’s had to be lit up individually with the pins on the arduino. This sacrificed the number of LED’s that could be lit, since the arduino had a limited number of pins. This also limited the resolution of the system overall. Since only a certain number of LED’s could be lit, the voltage ranges sensed would have to be larger to compensate. With four LED’s for the treble and bass set, the voltage ranges for each needed to be tuned. The voltage values for the bass component usually varied up to 1 V, while the treble usually varied from 1 V ­ 2 V.   

Hardware  Table 1 below shows the bill of materials to create the treble and bass detector system. The majority of the cost came from the purchasing of the Arduino with the ATmega328p microcontroller. The total cost of the system was calculated to be $32.54 with the Arduino making up $24.95 of that cost. The cost of this system could be greatly reduced if the system was manufactured in bulk so the ATmega328p microcontroller and microphone condenser would cost significantly less reducing the overall cost of the system.   

Table 1: Bill of Materials  

  Treble and Bass Detector       

qty  part type  designator / id  description  Cost/unit (U.S. $) 

2   Amplifier    LM741   Operational Amplifier    .50 

1  Amplifier  LM201AN   Operational Amplifier    .50 

8  Capacitor  C104  Capacitor 0.1 uF 100 Volt X7R 10% Radial 

.10 

1  Capacitor  FC 8828  Capacitor 2.2 nF   0.4 

1  Capacitor  IIC 103  Capacitor 8 nF  0.2 

13  Resistor  ­­­­­­­­­­­­­­­­  Resistor, Axial Lead, 1k, 5%  .10 

4  Resistor  ­­­­­­­­­­­­­­­­  Resistor, Axial Lead, 10k, 5%  .10 

1    Resistor   ­­­­­­­­­­­­­­­­  Resistor, Axial Lead, 2.2k, 5%   .10 

1  Resistor  ­­­­­­­­­­­­­­­­  Resistor, Axial Lead, 200k, 5%  0.10 

8  LED  UT0341R­41­R  Red Diffused, T1, 635nm   .012 

1  Microphone    270­090  Condenser Microphone Element   2.99 

Page 5: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

1  Arduino  Arduino Uno R3  ATmega328P Microcontroller w/ Arduino Interfacing 

24.95 

  

Table 2 below shows the Arduino’s wiring configuration to the rest of the system. This table is best followed if referenced with the system schematic shown in Figure 1 above. The overall schematic of the system can be interpreted by referencing Figures 1 and 2 above as well as the bandpass filter schematic shown in Figure 3 below. The combination of these three schematics allows for the system to be recreated.  

 

 

Figure 3: Bandpass Filter Schematic 

 

 

 

 

 

 

 

 

 

 

 

 

 

Page 6: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

Table 2: Arduino Wiring Configuration  

Arduino Pin  Port Name  System Connection  Function 

GND  GND  GND   Create a common ground between all 

blocks  

Power: 5V  VCC  AREF  Generate the reference voltage for the analog to 

digital converter  

AREF  AREF  5V  Generate the reference voltage for the analog to 

digital converter  

Analog: 0  PA0  Output of LM741 Op­Amp for Bass Filter 

Input into the Arduino’s analog to digital 

converter 

Analog: 1  PA1  Output of LM741 Op­Amp for Treble Filter 

Input into the Arduino’s analog to digital 

converter 

Digital: 0  PD0  Bass LED1  Determines the state of Bass LED1 

Digital: 1  PD1  Bass LED2  Determines the state of Bass LED2 

Digital: 2  PD2  Bass LED3  Determines the state of Bass LED3 

Digital: 3  PD3  Bass LED4  Determines the state of Bass LED4 

Digital: 4  PD4  Treble LED1  Determines the state of Treble LED1 

Digital: 5  PD5  Treble LED2  Determines the state of Treble LED2 

Digital: 6  PD6  Treble LED3  Determines the state of Treble LED3 

Digital: 7  PD7  Treble LED4  Determines the state of Treble LED4 

 

 

 

Page 7: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

Figure 4 shows the physical representation of the system shown in Figure 1. The Arduino is powered through the use of a USB cable connected to a computer. The system was wired in such a way that can be followed by using the Arduino wiring diagram in Table 2 above.  

 

 

Figure 4: Physical Representation of the Treble and Bass Detector 

Software  Atmel Studio version 6.2 development software was used to program the Atmel 328 with C++. An instructor provided the arvdude.exe, arvdude.conf, and prog.bat files to help program the arduino with .hex files created by Atmel Studio by placing them in the C:\Windows directory.  

The program the arduino used began by defining the libraries used as well the functions used to initialize the components on the microprocessor. The on­board ADC had its initial registers and states initialized with the Initialize_ADC0() function, and the on­board timer used to generate interrupts was constructed with the init_Timer0() function. Both of these functions can be seen below. 

Insert ADC and Timer init functs  

Page 8: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

 

These functions are called in the beginning of the main function. The beginning of the main function also sets up the PORTD pins on the arduino as the outputs that drive the LED’s, enables interrupts that will be generated by the timer, and initializes the outputH and outputL variables. These variables act as the upper and lower 4 bits of the PORTD register that determines the logic of each output to the 4 LED’s for the bass and treble. This initial steps of the main loop can be seen below. 

Insert Main Loop Start  

The ADC was used to interpret the bass and treble inputs with the 5 V from the arduino as reference. Each while loop first reads the bass input, and then the treble. For each reading, an if­statement determines the appropriate voltage level the bass or treble is at, and how many LED’s to light up. The higher the voltage, the more LED’s light up. This output is reflected in the outputL and outputH variables. This process can be seen in the code below. 

Insert for loops code  

The timer was used to generate interrupts, and during each ISR the arduino would update the output to the LED’s. Without this the LEDs would blink too fast to be noticeable if they were driven in the while loop. So having the timer with a clock running at 1/1024th of the arduino clock helps the visual feedback remain smooth. However, this means that the arduino reads data faster than it outputs it. This can be changed by the prescaler on the timer, however the visual feedback on the LED’s might suffer as a result. The ISR can be seen in the code below. 

Insert ISR code  

Test Results The microphone used was fairly cheap, and could not pick up much sound. The easiest way to test for sound was the tap the mic directly. This was quick and allowed for small pulses that contained high enough frequencies to be seen on the filters. Blowing or whistling in the microphone worked as well, however these frequencies could be filtered out by the filters used. 

The acquisition of the treble and bass frequencies was fairly successful. The act of filtering and amplifying the sound took some time in order to consistently get values that the arduino could read. This testing resulted in the need for band­pass filters rather than low­pass and high­pass, as well as the need for active filters. 

The resolution determined by the arduino was limited by the amount of LED’s that could be driven. Originally ten LED’s per treble and bass was planned, however this had to be reduced to four LED’s due to hardware limitations.  

Personnel 

Page 9: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

Bret Omsberg handled most of the hardware setup and schematic creation. He also contributed to the design of the filters, starting with a simple RC low­pass and high­pass that would later become two active bandpass filters that provided a much sharper signal with the removal of high and low frequency noise. The troubleshooting aspect of the project as well as the powerpoint creation was done in conjunction with Evan.  

Evan Kirkbride handled most of the software design, and adapting the software with the outputs from the hardware. Troubleshooting with the hardware and software as well as the presentation preparation was done along with Bret.  

Conclusion 

Bret Omsberg This project offered many learning experiences along the way. The original design of this system included the use of digital to analog converters, converters, and transmission gates. As the implementation process continued, it was realized that the DAC was no longer necessary which saved money from a design perspective. The original design also included ten LEDs for each Bass and Treble output, but this was reduced to four per line due to the comparators not operating properly. A large portion of the problems occurred in setting up the filters. The filters were first implemented using simple RC low­pass and high­pass circuits but this presented a new issue, noise. This was corrected using a bandpass filter for the high­pass filter and was made even sharper with the introduction of an op amp that made the filter an active bandpass filter. The low­pass was eventually redesigned into an active bandpass filter to provide a signal that had very little noise. This project could be improved with the inclusion of twenty comparators that would allow ten LEDs per bass and treble line that would increase the resolution of the measurement. A higher quality microphone would also allow for a broader spectrum of frequencies to be analyzed due to the microphone used in this project cutting off at 10 kHz which is only half of the hearable frequency for humans. The project could also be adapted so that LEDs were arranged in a geometrical shape to make it more aesthetically pleasing to the user.  

Evan Kirkbride This project allowed for us to not only use the arduino in they ways we have learned about throughout the quarter, but also allowed us to use circuits we learned about in previous classes. Namely filters and amplifiers, and this project allowed for a synthesis of those elements. Since these components had to work with an audio signal, a signal that is more noisy and sporadic than typical signals used to test these circuits, the components needed to be high­quality and consistent. This lead to the testing of this hardware to be the most intensive part of the project. Figuring out the appropriate frequency ranges, using amplifiers to keep the gain of the signal consistent, and eventually changing each filter to band­pass allowed for some theory practice and familiarity with these systems. By the time we got to the arduino and LED light­up process, there was not much time within our deadline to ensure their function, and once it was clear that 

Page 10: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

the hardware needed was not working, the arduino had to be used directly to drive the LED’s. This was the biggest let­down of the project, and if more time was allotted to improve, getting more LED’s driven for the treble and bass would be the first step, allowing for more resolution. The quality of the microphone would probably be the next step, allowing for better quality sound over a larger frequency range. A container for this system could also be useful to make this system more marketable.   

References ATmega328 Datasheet 

ElectronicsTutorial Active Band­pass Filter Design Webpage 

Texas Instruments LM741 Operational Amplifier Datasheet 

Texas Instruments LM201AN Operational Amplifier Datasheet 

Appendix A – Marketing Document 

 

Page 11: Treble and Bass Detector

CPE 329‐03 Bret Omsberg Spring 2015 Evan Kirkbride 

 

 

Appendix B – Source Code