Go Down

Topic: Help using ArduinoFFT (Read 15640 times) previous topic - next topic


Thanks a lot, it seems to work!
Only thing is that I probably described it a bit wrong. There's one line with OK brightness but others are dimmer, but now at least all lines are the same brightness (but dimmer than before using FHT). But I guess it should work afterwards, I've calculated resistors for 12V supply for LEDs while currently I use only 5V.


it looks like the way you set how long an LED is on for, is by the amount of time it takes to run 8 clock() functions.

Aren't LEDs on while the latch pin is HIGH? From this I understand it like they would be on when latch is LOW (when i call clock() functions)

is because it also has to run the fht() function, so it takes much longer

I thought this would only add more delay after drawing the whole matrix - LEDs would only be off for longer...

Also, do I really need this:
Code: [Select]

TIMSK0 = 0; // turn off timer0 for lower jitter

and do I need while(1) loop in the loop() function? (I have commented it out right now)

And one last thing:
If I use #define FHT_N 64, I assume I'll get 32 amplitudes (I need only 20), what would be the resolution of each amplitude? (Like it was 150hz before, I guess it would be larger now)


you set the latch low, do 8 clock() functions, then set latch high, and the LEDs light.  now, that particular LED pattern stays lit until you run the next set of 8 clock functions, and toggle the latch line again.  so each LED pattern is on for the amount of time it takes to shift the next pattern out.  this is why the fht() function call makes the last line so much brighter, because it takes so much longer to get to the next latch line toggle.

if you reduce your LED resistor values, it should be fine.  the LEDs are on for such a small amount of time, you can go above the reccomended 20mA if you want, as the average current will be much less than 20mA.

the TIMSK0, while(1), cli() and sei() stuff is not necessary, it just makes things run faster.  if you plan on using delay() or millis(), you need to get rid of TIMSK0 anyways.


Yep, I noticed delays don't work with that thing.
Thanks again for explaining everything. :)


oh yeah, the new frequency bin size will be:

16MHz/32/13/64 = 600Hz

basically 4x what it was for 256 (256 = 4x 64)


Yeah, some simple maths, thanks  :smiley-mr-green:


Hi all..

I am using the similar code for finding the fft of an analog signal in the range 0-5v.But I need the sampling frequency of 100 hertz.How can I get this sampling frequency?I am posting the code I am using now.
Code: [Select]
#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h>
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
    for (byte i = 0 ; i < FFT_N/2 ; i++) {
      Serial.println(fft_log_out[i]); // send out the data

Go Up