0% found this document useful (0 votes)
117 views

Arduinofft 2

This document contains code to perform a Fast Fourier Transform (FFT) on an analog input signal sampled at 1000 Hz with 512 samples. It calculates the magnitude of the FFT, finds the major peak frequency, and prints the peak value and frequency to the serial monitor. It also finds and prints any frequencies above 4500 in magnitude. The code initializes the FFT library, sets up sampling parameters, performs the FFT calculations in a loop, and continuously prints the results.

Uploaded by

Caio Molinari
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Arduinofft 2

This document contains code to perform a Fast Fourier Transform (FFT) on an analog input signal sampled at 1000 Hz with 512 samples. It calculates the magnitude of the FFT, finds the major peak frequency, and prints the peak value and frequency to the serial monitor. It also finds and prints any frequencies above 4500 in magnitude. The code initializes the FFT library, sets up sampling parameters, performs the FFT calculations in a loop, and continuously prints the results.

Uploaded by

Caio Molinari
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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