Difference between revisions of "S14: Spectrum Analyzer for Audio Frequency Signals"
Proj user13 (talk | contribs) (→Introduction) |
Proj user13 (talk | contribs) (→Software Design) |
||
Line 224: | Line 224: | ||
** Then we set the required pins to output. After that, the timer frequency was allocated, the reset mode was configured. | ** Then we set the required pins to output. After that, the timer frequency was allocated, the reset mode was configured. | ||
** Along with that, the enabling of timer interrupt to occur according to our requirements.The snippet of the code(especially the initial configurations) is given below. | ** Along with that, the enabling of timer interrupt to occur according to our requirements.The snippet of the code(especially the initial configurations) is given below. | ||
+ | |||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> |
Revision as of 21:06, 22 May 2014
Contents
Grading Criteria
- How well is Software & Hardware Design described?
- How well can this report be used to reproduce this project?
- Code Quality
- Overall Report Quality:
- Software Block Diagrams
- Hardware Block Diagrams
- Schematic Quality
- Quality of technical challenges and solutions adopted.
Spectrum Analyzer for Audio Frequency Signals
Abstract
We plan to build a Spectrum Analyzer for Audio Frequency signals. Our device is able to display frequencies in audio of up to 4 kHz, which covers the most of the of the frequency range of typical music. The main inspiration for our project was applications of music visualizers which are seen in much software like Windows Media Player. Our spectrum analyzer will try to mimic such visualizers using an audio amplifier and a LED display. The display will light up a range of LEDs from low to high according to audio frequency using FFT as the algorithm for analyzing audio input. This gives a fully dynamic LED display for audio frequency.
Introduction
A Spectrum analyzer is used in measuring the magnitude of an input signal versus a frequency for a certain frequency range of an instrument. The primary use of a Spectrum analyzer is to measure power of spectrum of unknown or known signals. An input signal that a spectrum analyzer measure is electrical, however, signals like acoustic pressure or optical waves can also be measured by use of an appropriate transducer.
By analyzing the spectra of electrical signals, dominant frequency, power, distortion, harmonics, bandwidth, and other spectral components of a signal can be observed that are not easily detectable in time domain waveforms. These parameters are useful in the characterization of electronic devices, such as wireless transmitters.
The display of a Spectrum analyzer has frequency on the horizontal axis and the amplitude displayed on the vertical axis. In general observation, a Spectrum analyzer looks like an oscilloscope and, in fact, some lab instruments can function either as an oscilloscope or a spectrum analyzer.
Fast Fourier Transform
A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.[1] As a result, fast Fourier transforms are widely used for many applications in engineering, science, and mathematics. The best-known FFT algorithms depend upon the factorization of N, but there are FFTs with O(N log N) complexity for all N, even for prime N. Many FFT algorithms only depend on the fact that e^{-2*pi/ N}} is an N-th primitive root of unity, and thus can be applied to analogous transforms over any finite field, such as number-theoretic transforms.
Objectives
The main objective of our project was to display the audio input given to the mic through an LED display. The range of frequency was kept to 4K Hz as it covers most of the frequency range for a typical musical instrument. The LED matrix will be able to display change in the audio signal correspondingly.
The scope of the project was divided into 3 main parts :
- ADC interfacing with the audio input through mic
- Performing FFT calculations on the LPC1758 board and communication of the same to LED matrix.
- Interfacing of the 16 X 32 LED matrix with LPC1758 board
Team Members & Responsibilities
- Anand Dumbre
- ADC interfacing + LED Interfacing
- Chinmay Vaidya
- Fast Fourier Transforms + Hardware.
- Kevin Beadle
- LED interfacing
Schedule
Week# | Date | Planned Task | Actual Task |
---|---|---|---|
1 | 03/13/14 | Order & receive parts. | Ordered the parts.late by 1 week as parts were not available |
2 | 03/20/14 | Interface microphone/LED strip to SJ One board. | Obtained the parts. Started work on Microphone and LED. |
3 | 03/27/14 | Design band pass filter to reduce noise. | Done |
4 | 04/03/14 | Analyze audio signals with Matlab using FFT. | The waveforms were not coming out properly. FFT code was working alright |
5 | 04/10/14 | Write code to process audio signal on SJ One board. | FFT code working fine. |
6 | 04/17/14 | Write algorithm to output audio signal to LED strip. | ADC and FFT output coming out properly |
7 | 04/24/14 | Test algorithm using different audio sources. | Tested using various Youtube audio. Still working on porting of LED strip. |
8 | 05/01/14 | Finalize project firmware. | ADC working fine. FFT output coming out properly. The communication through UART is working. LED porting still going on. LED strip flashes light but not lighting individual pixels. Working on getting correct color output. We suspect the LED display is defective. In process of trying with different LED display. |
9 | 05/08/14 | Finalize project demonstration. | Working on the LED Matrix with a different board. Color output is correct. The row selection is working, however, column selection still not working. |
10 | 05/13/14 | Finalize project report. | Project report completion started. Still working on the LED Matrix column selection. |
Parts List & Cost
Component Name | Quantity | Cost per Item | Total Cost |
---|---|---|---|
Audio Amplifier Board | 1 | 25$ | 25$ |
LPC1758 Board | 2 | 70$ | 140$ |
LED Matrix (16 X 32) | 1 | 35$ | 35$ |
Wires | 50 | 0.5$ | 25$ |
Resistors | 2 | None | None |
Capacitors | 5 | None | None |
Total | 225$ |
Design & Implementation
Hardware Design
The flow of our Hardware datapath is very linear. The audio board with Mic was interfaced with the LPC1758 board by connecting the audio, envelope, gate,Vcc and Ground ports to the board. The input from mic is fed to the ADC on the board. The ADC is internally connected to the processor. The FFT calculations are done on the board and the output of the FFT is given to other LPC1758 board by UART communication. The LPC1758 board is interfaced with the LED matrix. The block diagram of our Spectrum analyzer hardware is shown below.
Each block diagram hardware design will be explained as follows:
- Audio Input : The audio input can be provided by playing a song or even just by talking into the mic
- Audio Amp & Filter design: The audio amp board had an in-built mic which provided the input. Filter design was implemented and the filter was direct connected to the audio board. The filter design was implemented as shown in the image.
- LPC1758 Board (ADC + FFT): The LPC1758 board has an in-built ADC. The output from audio board is connected to ADC of the board. The audio, envelope, gate, Vcc and ground ports from audio board will be connected to ADC ports. All the FFT calculations are software based and computed directly on the processor.
- LPC1758 Board (for LED matrix interfacing) : The communication between the two LPC1758 boards is done by UART. The UART communication uses Tx and Rx ports of both the boards.
- 16 x 32 LED Matrix : The LED matrix is connected to LPC1758 board by connecting the A,B,C,R1,B1,R2,B2,G1,G2,Clk,OE and Latency of the Matrix to the port pins of LPC1758 board. The connections is as shown in the image below.
Hardware Interface
In this section, you can describe how your hardware communicates, such as which BUSes used. You can discuss your driver implementation here, such that the Software Design section is isolated to talk about high level workings rather than inner working of your project.
The Hardware Interface mostly consisted of pin connections to LPC1758 board from Audio Amp board, LPC1758 to LPC1758 UART connections and LPC1758 to LED Matrix. The schematic of the connections is given below.
Pin Connections
Sl. No | Port and Pin Number | Pin Type | Function |
---|---|---|---|
1 | P1.31 | ADC | Audio Amp |
2 | P2.8, P2.9 | UART2 | Serial transmission between SJOne Boards |
3 | P0.0, P0.1, P0.29, P0.30, P1.19, P1.20,P2.0 - P2.5 | GPIO Output | LED Matrix |
Software Design
Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
The Software design implementation was done in 4 parts.
- ADC configuration:
- FFT calculations:
The main method of the FFT program was to wait for the ADC buffer to get full. According to the FFT algorithm, we considered a real and imaginary numbers as the input to the FFT matrix. A function for FFT was created which calculates the FFT matrix depending upon the inputs provided. In the main program, depending upon the size of array we use, it prints out the real and imaginary values of the Fast Fourier Transform. These values are to be sent to other board via Tx pin of UART. The steps in calculating FFT were as follows
- Create a structure which includes the real and imaginary parts. It also includes declaration of matrix parameters
- As the matrix is 3 dimensional, consider i,j,k parameters and calculate the FFT for every i,j and k value using nested 'for' loops.
- Output the real and imaginary values of the FFT calculations. However as we need only the real values for spectrum analyzer,we can neglect the imaginary value while UART communication.
- UART communication :
The UART communication between the two boards is solely for the purpose of providing the FFT values to LED matrix. There is only one way communications in this arrangement. The FFT values are sent through Tx pin and received by the other baord at Rx pin. We decided to use the UART as it is easy to implement in our case as we just had to send an 8 bit data over the bus.The UART was set to transmit with 8-bit character sizes, which takes a byte and transmit 8 bits serially. UART offers different frame formats including different character sizes, parity bits, and multiple stop bits, but we opted to use a 10-bit frame for simplicity and speed of transmission with 1 start bit, 8 character bits, and 1 stop bit.
- Interfacing the LED Matrix:
The main problem in configuration of the LED Matrix was that its library was in Arduino. Also, the data sheet for the matrix was not available. Hence, we had to port it to the LPC1758. The pseudo code which we implemented in C is given as follows The various ports for A,B,C,OE,Clk,R1,R2,G1,G2,B1 and B2 were set depending upon the port on which they were connected to LPC board.
- We used #define to make each pin correspond to the required port.Initially we have to clear the display, then set the pins for A,B and C depending upon the row or column we need to select.
- For that, the bit masking for Apin, Bpin and Cpin was used. We used a 'for' loop to access all 32 columns of the LED matrix.
- Also, we need to clear the interrupt flag after every operation of the display.
- Then we set the required pins to output. After that, the timer frequency was allocated, the reset mode was configured.
- Along with that, the enabling of timer interrupt to occur according to our requirements.The snippet of the code(especially the initial configurations) is given below.
if (LPC_TIM2->IR & MR0MASK) { // Check if the interrupt occured
LPC_GPIO0->FIOPIN |= (1 << OEPIN); // Disable LED output
/* Select row */
LPC_GPIO1->FIOPIN = ((row & 0x1)==1) ? LPC_GPIO1->FIOPIN |= (1 << APIN) : LPC_GPIO1->FIOPIN &= ~(1 << APIN);
LPC_GPIO1->FIOPIN = ((row & 0x2)==0x2) ? LPC_GPIO1->FIOPIN |= (1 << BPIN) : LPC_GPIO1->FIOPIN &= ~(1 << BPIN);
LPC_GPIO0->FIOPIN = ((row & 0x4)==0x4) ? LPC_GPIO0->FIOPIN |= (1 << CPIN) : LPC_GPIO0->FIOPIN &= ~(1 << CPIN);
/* Output color */
LPC_GPIO2->FIOPIN |= (1 << R1PIN) | (1<<B2PIN) | (1<<G1PIN);
LPC_GPIO0->FIOPIN |= ( 1 << CLOCKPIN);
LPC_GPIO0->FIOPIN &= ~(1 << CLOCKPIN);
LPC_GPIO0->FIOPIN |= (1 << LATCHPIN); // Enable latch and set data for led matrix
LPC_GPIO0->FIOPIN &= ~(1 << LATCHPIN); // Disable latch for next interrupt
LPC_GPIO0->FIOPIN &= ~(1 << OEPIN); // Output LED display
/* Increment row value */
if (row<8)
row++;
else
row=0;
/* Clear interrupt flag */
LPC_TIM2->IR |= (1 << 0);
}
Implementation
This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
Testing & Technical Challenges
Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again? Make a smooth transition to testing section and described what it took to test your project.
Include sub-sections that list out a problem and solution, such as:
My Issue #1
The main issue was obtaining correct parts for the audio amplifier board and LED strip. The gain of amplifier needed to correct for required frequency. Also, the parts were not available on Websites. Resolution: checked the forums on the websites to obtain more information about the boards. Placed an order for deliver when available on the Adafruit and Sparkfun.
My Issue #2
We required the timer1 for ADC. However, the timer1 was configured for the I2C bus. Hence, we changed the I2C bus ports to timer2 and used the timer1 for ADC
My Issue #3
Adafruit Led strip had a library for Arduino. We need to port it to LPC in order to get our LED strip working.However, there are timing issues as the clock frequencies are not same for both. Issue is not resolved yet.
My Issue #4
The LED matrix did not have any datasheet available from which we could have learned which pins to access for Column selection. We got the row selection working however, the column selection was not working properly. We posted this topic on the AdaFruit forum and got some inputs from the support staff. We got the column working eventually.
My Issue #5
The range of FFT calculations values was more than 10K. However, we cannot send more than 8 bit data through UART. So, only the partial data was getting transferred over the line. To resolve this issue, we separated all FFT values into blocks and assigned a number to each block so that all the block numbers can be sent over the line in single transaction.
Conclusion
Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?
The critical part of the project was to get the timings of all blocks right. Also, configuring the ADC and Testing of the FFT code was a challenging process. There was no documentation for LED matrix which made work hard to understand the Arduino code and port it our board. The key points which we learnt from the project were
- We had to study working of ADC very properly in order to understand and implement the timer for it. Also, we had to find out if we needed to use the Filter. We learned the filter designing in order to decrease the gain.
- Having learned about how to calculate an FFT in undergraduate years, its actual implementation on the processor was a good learning experience.
Project Video
Upload a video of your project and post the link here.
Project Source Code
Send me your zipped source code and I will upload this to SourceForge and link it for you.
References
Acknowledgement
Any acknowledgement that you may wish to provide can be included here.
We obtained the components from ADAFruit and Sparkfun. We would like to thank Preet for teaching us this course and his guidance in the project as well as the coursework.
References Used
List any references used in project.
1. Preetpal Kang, Lecture notes of CMPE 244, Computer Engineering, Charles W. Davidson College of Engineering, San Jose State University, Feb-May 2014.
2. http://www.socialledge.com/sjsu/index.php?title=SJ_One_Board
3. Digital Signal Processing by A.V OppenHeim & R.W Schafer
4. http://en.wikipedia.org/wiki/Fast_Fourier_transform
6. https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/
Appendix
You can list the references you used.