Teensy LC FFT Question - Spectrum Analyzer

Status
Not open for further replies.

vitormhenrique

Well-known member
Hello Guys,

I Home you don't mid helping me on this basic question, I'm a chemical engineer, had my calculus and vaguely remember Fourier transform....

I dowloaded the Teensy-LC FFT Library and wanted to build a small Spectrum Analyzer on my RGB Shades.

But I don't understand what the output of the fft means, how can I translate that to the frequencies, and amplitudes.

The example code is this:
Code:
#include "LCAnalyzeFFT.h"

LCAnalyzeFFT LCFFT;

void setup() {
	Serial.begin(9600);
	delay(2000);
	Serial.println("hello");

	// Initialize the library with the appropriate input pin
	LCFFT.init(A9);
	// enable sampling
	LCFFT.enable();
} 

int counter = 0;
void loop() {
	static unsigned long start = millis();
	// wait until data is available
	if(LCFFT.available()) {
		counter++;
		if((millis() - start) > 1000) {
			Serial.println(counter);
			counter = 0;
			start = millis();
		}
		for(int i = 0 ;i < 32; i++) {
			int32_t sum = 0;
			for(int j = 0; j < 4; j++) {
				sum += LCFFT.output[i*4+j];
			}
			Serial.print(sum);
			Serial.print(" | ");
		}
		Serial.println();
	}
}

And the output that it print is this:

Code:
1067 | 8 | 8 | 8 | 4 | 6 | 7 | 6 | 2 | 5 | 3 | 5 | 3 | 4 | 6 | 7 | 2 | 2 | 3 | 2 | 3 | 1 | 1 | 4 | 2 | 2 | 1 | 3 | 3 | 2 | 3 | 4 | 
1070 | 9 | 8 | 8 | 2 | 3 | 5 | 6 | 5 | 6 | 6 | 6 | 4 | 5 | 4 | 6 | 1 | 1 | 1 | 2 | 1 | 3 | 2 | 3 | 3 | 2 | 3 | 1 | 2 | 3 | 2 | 3 | 
1067 | 8 | 8 | 8 | 3 | 6 | 6 | 8 | 4 | 3 | 7 | 3 | 3 | 6 | 4 | 7 | 1 | 3 | 1 | 1 | 1 | 3 | 1 | 3 | 2 | 1 | 2 | 3 | 1 | 3 | 2 | 3 | 
1069 | 8 | 8 | 8 | 6 | 4 | 7 | 8 | 2 | 3 | 7 | 4 | 5 | 5 | 4 | 7 | 1 | 2 | 2 | 1 | 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1 | 2 | 0 | 3 | 0 | 3 | 1 | 3 | 0 | 1 | 3 | 2 | 0 | 3 | 2 | 4 | 
1067 | 8 | 8 | 9 | 3 | 6 | 6 | 7 | 1 | 4 | 5 | 6 | 4 | 4 | 8 | 8 | 0 | 2 | 1 | 1 | 1 | 3 | 3 | 1 | 0 | 1 | 3 | 2 | 2 | 2 | 3 | 3 | 
1064 | 9 | 8 | 8 | 3 | 5 | 5 | 7 | 3 | 3 | 5 | 4 | 4 | 5 | 5 | 7 | 3 | 2 | 2 | 3 | 1 | 3 | 2 | 2 | 4 | 3 | 2 | 0 | 2 | 3 | 2 | 4 | 
1068 | 8 | 8 | 8 | 5 | 5 | 5 | 8 | 3 | 5 | 5 | 5 | 5 | 6 | 4 | 7 | 4 | 1 | 1 | 2 | 1 | 1 | 4 | 3 | 2 | 2 | 2 | 4 | 4 | 1 | 4 | 3 | 
1066 | 9 | 8 | 9 | 5 | 5 | 7 | 8 | 2 | 5 | 6 | 5 | 5 | 5 | 5 | 7 | 0 | 3 | 3 | 1 | 2 | 3 | 4 | 2 | 1 | 1 | 2 | 2 | 2 | 4 | 5 | 3 |

I have a cheap oscilloscope, I can see that the mic is outputting beautiful data... so, basically could you help me translate the fft output to something that I can work on?
 
Don't have the library handy at the moment but the horizontal rows should be the FFT frequency bins with levels in each bin. If you have something that can display a graph of the current levels it may be easier to visulise and find if you've actually got things working. So a graphical LCD or a processing script reading in those strings rather than watching them on a Serial terminal.

The first number is just how long it took to process the most recent sample, the rest should be the levels. If it's working right a sweep high/low or vice versa should be visible in the returned levels. This is why some sort of visulisation may help here.
 
That data looks like you've got a too-small audio signal with a DC voltage offset.

Any chance you could post details (ideally photos) of how you're getting the audio input? Getting the audio levels right is critical.

To sort-of answer your original question, maybe the OctoWS2811 SpectumAnalyzer example might help? It grabs the 512 bins from the audio library's 1024 point FFT and does some simple math to combine groups of them, for a 60 pixel wide display. The levels are converted using either linear or log scales, and then mapped to the Y axis with simple drawing to the pixels. The whole example is only 144 lines, so there's not too much code to pick apart to try to figure out what it does. Maybe some of that could be useful?

I also have the RGB Shades here... as the bare PCB. Maybe I ought to assemble it and give this a try?
 
Thanks Paul!

I'll definitely look into that example!

I'm using a adafruit Electret Microphone Amplifier MAX9814 set to 40dB gain. I connected the output to the A9 pin on Teensy-LC, VCC to +3.3V and ground to ground. Will post some pictures after I get home. Is that the correct setup? of do i need to use the circuit that you show here ?
 
Paul,

Follow the pictures of my setup. I'm using teens-lc connected to a BLE and the microphone. Just finishing up the app to control the shades! I would assembly and play with it, it is so cool!

IMG_1021.jpg
IMG_1015.jpg
IMG_1014.jpg
 
Status
Not open for further replies.
Back
Top