javiernicola
Member
Hi , im trying to implement a FFT of the ADC readings with a teensy 3.5.
My intentions are getting the highest resolution possible but just around the low frecuencies from 0Hz to 500Hz.
I want to modify the Sampling frecuency so i get the bandwidth i need but i dont really know how to make those changes.
Should i change the ADC sampling frecuency?
Should i change something in the FFT code?
So far I have succesfully built a regular 23khz bandwidth tft display that listens to A2 analog input and labels the maximum peak frecuency.
My intentions are getting the highest resolution possible but just around the low frecuencies from 0Hz to 500Hz.
I want to modify the Sampling frecuency so i get the bandwidth i need but i dont really know how to make those changes.
Should i change the ADC sampling frecuency?
Should i change something in the FFT code?
So far I have succesfully built a regular 23khz bandwidth tft display that listens to A2 analog input and labels the maximum peak frecuency.
Code:
#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
///////////////////////////////tft screen
#define CS_PIN 8
#define TFT_DC 9
#define TFT_CS 10
// MOSI=11, MISO=12, SCK=13
AudioInputAnalog myadc;
AudioAnalyzeFFT1024 myfft;
AudioConnection patchCord1(myadc, myfft);
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
int SCREEN_WIDTH,SCREEN_HEIGH;
float dataforscreen [320];
float mainPeak[2]={0,0};//frecuecny, value
void setup(){
Serial.begin(115200);
Serial.println("FFT example : ");
AudioMemory(12);
myfft.windowFunction(AudioWindowHanning1024);
//null
//extern const int16_t AudioWindowHanning1024[];
//extern const int16_t AudioWindowBartlett1024[];
//extern const int16_t AudioWindowBlackman1024[];
//extern const int16_t AudioWindowFlattop1024[];
//extern const int16_t AudioWindowBlackmanHarris1024[];
//extern const int16_t AudioWindowNuttall1024[];
//extern const int16_t AudioWindowBlackmanNuttall1024[];
//extern const int16_t AudioWindowWelch1024[];
//extern const int16_t AudioWindowHamming1024[];
//extern const int16_t AudioWindowCosine1024[];
//extern const int16_t AudioWindowTukey1024[];
//////////////////////////////////////////screen
SCREEN_HEIGH= tft.height();
SCREEN_WIDTH= tft.width();
Serial.print("SCREEN_HEIGH");Serial.print(SCREEN_HEIGH);Serial.print(" SCREEN_WIDTH");Serial.println(SCREEN_WIDTH);
Serial.print("AUDIO_SAMPLE_RATE ");Serial.print(AUDIO_SAMPLE_RATE);Serial.print(" AUDIO_BLOCK_SAMPLES ");Serial.println(AUDIO_BLOCK_SAMPLES);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setFont(Arial_20);
//??ts.setRotation(1);
while (!Serial && (millis() <= 1000));
}
void loop() {
getfftdata();
PrintScreenFFT();
PrintSerialFFT();
//delay(100);
}
void PrintSerialFFT(){
float n;
int i;
if (myfft.available()) {
// each time new FFT data is available
// print it all to the Arduino Serial Monitor
Serial.print("FFT: ");
for (i=0; i<50; i++) {
n = myfft.read(i);
if (n >= 0.01) {
Serial.print(n);
Serial.print(" ");
} else {
Serial.print(" - "); // don't print "0.00"
}
}
Serial.println();
Serial.println(mainPeak[0]);
}
}
void PrintScreenFFT(){
int i;
if (myfft.available()) {
tft.fillScreen(ILI9341_BLACK);
for(i=0;i<SCREEN_HEIGH;i++){
//int n=myfft.output[i]/40;
int n =dataforscreen[i]*500;
tft.drawFastVLine(i,SCREEN_WIDTH-n,n,ILI9341_YELLOW);
}
tft.setCursor(mainPeak[0],60);
tft.print((23000/512)*mainPeak[0]);
//tft.drawPixel(x, y,ILI9341_RED);
//tft.fillScreen(ILI9341_BLACK);
//tft.setTextColor(ILI9341_YELLOW);
//tft.setFont(Arial_10);
//tft.setCursor(10,10);
//tft.print("RAW");
}
}
void getfftdata(){
int i;
mainPeak[0]=0;
mainPeak[1]=0;
for(i=0;i<SCREEN_HEIGH;i++){
dataforscreen[i] = myfft.read(i);
if(mainPeak[1]<dataforscreen[i])
{
mainPeak[0]=i;
mainPeak[1]=dataforscreen[i];
}
}
}