FFT LED Spectrum analyzer on PIC32

MrChips

Joined Oct 2, 2009
30,714
This is not entirely true. If you were to sample a 1Hz signal for 1 Second at 1024 SPS, and do an FFT on the result, you should have a rather nice approximation of a delta function at 1Hz. Interpretation should be trivial.:D
There is no convention as to how the results appear in the array. Here are things to watch for:


  1. The location of data points may be scrambled.
  2. There will be positive and negative frequencies.
  3. The data points will be complex numbers, real and imaginary.

The proper thing to do is to input a known time series to the FFT and compare the results with your expected results.

For example enter:


  1. 0, 0, 0, 0, 0, 0, 0, 0,...
  2. 1, 1, 1, 1, 1, 1, 1, 1,...
  3. 1, 0, 0, 0, 0, 0, 0, 0,...
  4. 0, 1, 0, 0, 0, 0, 0, 0,...

Find out the expected results using Matlab or similar program.
 

Thread Starter

stefan646

Joined Dec 16, 2011
28
RRITESH KAKKAR : cand you spell the full word of DIT and DIF so i can have i idee what it is about?

Can somebody answer post #18 and #20, so i can carry out with another things? :D
 

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I read somewhere that it converts time domain in to frequency domain...hope i am not wrong
That's what FFT also do both DIF and DIT do the same job but due to advantages of using sequence RAM AND ROM addr one of them is prefer.
 

thatoneguy

Joined Feb 19, 2009
6,359
If your other question is "do I need to amplify the signal", yes. You'll want it to be about 4-5V, with center at 2 or 2.5V

That way the signal covers the full ADC range. Sample as fast as you can. Shorter sample lengths will give "snappier" response, but too small and it won't look right at all (aliasing), grab 60mS worth of signal at a time to ensure low frequencies are represented, or whatever RAM you have. Decide frequency buckets, do FFT, display, repeat.

Did you look at the source code that was in the link I posted above? You are doing the same thing, except to double the frequency (40kHz Sample Rate), and a different output device (LED Matrix).
 

Thread Starter

stefan646

Joined Dec 16, 2011
28
1) If your other question is "do I need to amplify the signal", yes. You'll want it to be about 4-5V, with center at 2 or 2.5V


2) or whatever RAM you have.
3) Decide frequency buckets
4) Did you look at the source code that was in the link I posted above? You are doing the same thing, except to double the frequency (40kHz Sample Rate), and a different output device (LED Matrix).
1)On my chip Reference Manuall saise "Analog input voltage range: 0V to 3.3V". So i must amplified to max 3.3V ?
2) 128k
3)64
4)That source code is write in HiTech C18 i think, so i cant view it.
My uc is programable with an Arduino like IDE. Its the same software modify to suport PIC32.

I finaly decided abouth the LED matrix and the programabile board: it will be 26X64 led matrix powerd by an chipKIT MAX 32 http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,894&Prod=CHIPKIT-MAX32
 
Last edited:

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
May i know the difference in DIT and DIF FFT as per lecture of MIT, professor say DIT require bit reverse at input and in DIF bit reverse at output ..
so, what will be better for ROM and RAM??
 

thatoneguy

Joined Feb 19, 2009
6,359
1)On my chip Reference Manuall saise "Analog input voltage range: 0V to 3.3V". So i must amplified to max 3.3V ?
2) 128k
3)64
4)That source code is write in HiTech C18 i think, so i cant view it.
My uc is programable with an Arduino like IDE. Its the same software modify to suport PIC32.

I finaly decided abouth the LED matrix and the programabile board: it will be 26X64 led matrix powerd by an chipKIT MAX 32 http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,894&Prod=CHIPKIT-MAX32
Ok, then you have a 3.3v controller, so the input needs to be amplified to 0-3.3V, it cannot go below 0, or over 3.3V. If you power the input amp from 3.3V with a Rail to Rail Op amp, then you'll be fine. Too much gain will just cause the signal to clip rather than hurt the ADC/uC. Though a clipped signal will show false high frequencies after the FFT, so set it close to clipping with max input volume if you have a scope and signal generator.

PIC18 have a useful ADC of about 20kHz if you plan on doing tasks in addition to ADC. This is not a problem with the one you are looking at.

The PIC32 Mx samples at 1Ms/s, or 1Mhz Sampling rate (500kHz max signal sampling), with sample outputs going into a 1k FIFO Queue to be processed, which makes the FFT a lot easier to perform, as you don't need to grab and deal with each sample as you do on the PIC18, you simply take the stack, process it, display, repeat.
 
Last edited:

Thread Starter

stefan646

Joined Dec 16, 2011
28
Before i get to the sampling rate and other aspect about programing my board i have to finish all the hardware parts. :cool:
So tomorow i am starting to make the schematic of the all project and hopefuly after the hollydays i will have the PCB and start soldering LEDs :D

Another questions:
1)what is the equivalent for the MAX293 ?
I like this filtre but unfortunately I can't found on sale in my country :(

2)if I put a 3.3V zener after the amplifier to make a extra-protection for my microcontroller, it is a good idea?
 

thatoneguy

Joined Feb 19, 2009
6,359
You won't need the Zener if you power your amp from the 3.3V source.

For the new version of the IC, go to maxim.com and type in the function. They have a lot of very cool new parts out.
 

Thread Starter

stefan646

Joined Dec 16, 2011
28
You won't need the Zener if you power your amp from the 3.3V source.
If I found a good amp to work properly at 3,3 v :D

Another very important thing: My final matrix will be 26X64 LEDs.
My board has 83 I/O ports. 1 port i will use for the analog to digital input, 1-3 for the push-button, 2 ports for an eventualy TV Out(i see that Arduino has a library of that), so i will ramain only with aprox. 75 I/O ports for controlling the matrix. So my question is: what tip of IC i should use for expanding (and how many) : multiplexing, shift register , etc. The best chose will be the one with the simplest code to implement no the one with the most simplicity
to build or the chipest.
 

Thread Starter

stefan646

Joined Dec 16, 2011
28
Questions:
1) I don't understand "ADC buffer" term and how that op amp cand do that?
2) You said "allowing 20kHz low pass filter at the front end, saving on code"
-in the datasheet says Wide Bandwidth: 10 MHz...i cand make a 20kHz low pass filter using one op amp?; and why you said saving code? How i cand save code using this IC?
 

thatoneguy

Joined Feb 19, 2009
6,359
The ADC runs in the bakcground, filling up a FIFO buffer with samples from the analog input. Your program will pop values off of this stack for your FFT then display. I said it was convenient since you didn't have to wait for each ADC to complete in order to continue.

As for the op amps, you'll want one at the input to give gain to a small signal, or unity to negative gain to larger signals, so they do not clip at the output of the opamp, which will never give an output higher than it's supply voltage (3.3V)

To sample 0-20kHz accurately, you need to filter out any frequencies above 20kHz. Op Amps make excellent active filters to cut off the input signal to only frequencies less than 20kHz. I'd suggest this low pass filter to be after the gain/input adjusts filter, and the output of the low pass filter into a unity gain buffer to input to the uC ADC pin. That way the uC input impedance doesn't interfere with the filter.

Please read these links until you understand them completely, the road ahead isn't "plug and play" simple.

http://en.wikipedia.org/wiki/Short-time_Fourier_transform
http://www.qsl.net/dl4yhf/spectra1.html
http://www.picotech.com/applications/spectrum.html
 
Top