Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include "arduinoFFT.

h"

#define SAMPLES 512


#define SAMPLING_FREQUENCY 1000

arduinoFFT FFT = arduinoFFT();


int maior=1000000;
int pos_maior;
unsigned int sampling_period_us;
unsigned long microseconds;

int j=0;
int aux=0;
float freq[20];
double vReal[SAMPLES];
double vImag[SAMPLES];

void setup() {
Serial.begin(115200);
sampling_period_us = round(1000000*(1.0/SAMPLING_FREQUENCY));
}

void loop() {
for (int i = 0; i < SAMPLES; i++) {
microseconds = micros();
vReal[i] = analogRead(A0)*5/1024;
vImag[i] = 0;
while(micros() < (microseconds + sampling_period_us)){};
}
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_FLT_TOP, FFT_FORWARD);
FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);

for (int i = 0; i < SAMPLES/2; i++) {


if(vReal[i]>4500){
//maior=vReal[i];
freq[j]=i;
j++;
aux++;
}
//Serial.print((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1);
//Serial.print(" ");
Serial.println(vReal[i], 1);

}
//Serial.println("--------------");
for(int j=0;j<aux;j++){
//Serial.println(freq[j]);
}
Serial.print("pico: ");
Serial.println(maior);
Serial.print("freq: ");
Serial.print(peak);
//Serial.println("hz");
while(1);

You might also like