FFT for digital data


I am new user never used Arduino or c language before. I need to have a program that can read data in array form of an SD card and perform a FFT on it. From there we analyze the FFT too see if there’s a large magnitude at 2Hz.

we plan on using an Arduino Mega for this part and we have found an Arduino FFT example but are having trouble reading and understanding what’s happening in the file. Also I don’t know how to call that data from SD card to do fft and after doing the FFT I need to see the values which is not included in the following code that i found in examples of fft lib.

guest openmusiclabs.com 8.18.12
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.  there is a pure data patch for
visualizing the data.

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

void setup() {
  Serial.begin(115200); // use the serial port
  TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0

void loop() {
  while(1) { // reduces jitter
    cli();  // UDRE interrupt slows this way down on arduino1.0
    for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
      while(!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fft_input[i] = k; // put real data into even bins
      fft_input[i+1] = 0; // set odd bins to 0
    fft_window(); // window the data for better frequency response
    fft_reorder(); // reorder the data before doing the fft
    fft_run(); // process the data in the fft
    fft_mag_log(); // take the output of the fft
    Serial.write(255); // send a start byte
    Serial.write(fft_log_out, 128); // send out the data

I would appreciate your help.

Break the project into small pieces and get each one working before putting them together. I would start by learning how to read the data file on the SD card and display the data on the serial monitor.

Then you need to learn how the FFT works. The example you have chosen is not very helpful, because it reads (unknown) data from the ADC input and sends the transformed results back to the PC for display.

You will need to understand the limitations of sampling, available memory and the requirement for an excellent low pass input filter, in order to achieve 1 Hz frequency resolution that your requirements seem to imply.

There are other methods for determining frequency components that may be better suited for your task (like autocorrelation analysis).