Spectrumanaliser Software

The software for my spectrumanaliser project is not finished, and it may never be finished because there is always some feature or improvement to make.

However, I do have a working piece of example code which basically functions. Here it is:

fft.ino
#include <fix_fft.h>
#include <ht1632c.h>
 
 
char im[128], data[128], raw[128], maxval[64];
char x=64, ylim=16;
int i=0, val;
static long tt=0;
 
ht1632c ledMatrix = ht1632c(&PORTB, 10, 9, 11, 8, GEOM_32x16, 2);
 
void setup()
{                         
 
  ledMatrix.clear();
  ledMatrix.pwm(15);
  ledMatrix.plot(0, 0, 2); 
 
  analogReference(DEFAULT);                          //  Use default (5v) aref voltage.
  for (int z=0; z<64; z++) {
    maxval[z]=15;
  };       //  fill the lastpass[] array with dummy data
 
  // defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
 
  // set prescale to 16
  sbi(ADCSRA,ADPS2) ;
  cbi(ADCSRA,ADPS1) ;
  cbi(ADCSRA,ADPS0) ;
 
};
 
void loop()
{
 
  //if (millis() > tt )
  {
 
    //noInterrupts();
    if (i < 128) {
      val = analogRead(1);
      //val = ((log(analogRead(1))*1024)/log(1024));
      data[i] = val - 512;
      im[i] = 0;
      i++;
    } 
    else {
      //interrupts();
      //this could be done with the fix_fftr function without the im array.
      //fft_windowing(data,7);
      fix_fft(data,im,7,0);
      // I am only interessted in the absolute value of the transformation
 
      bool degrade = (millis() - tt > 100);
      if ( degrade ) {
        tt = millis();
      }
      for (i=0; i< 64;i++){
        data[i] = sqrt(data[i] * data[i] + im[i] * im[i]);
        int y = constrain( map(data[i], 0, 15, 15, 0) , 0, 15)  ;
//        int y = constrain( map( (log( data[i]+1) * 15/log(15)), 0, 15, 15 , 0 ) , 0, 15)  ;
 
        ledMatrix.line(i, 0 , i, 15, 0); 
        ledMatrix.line(i, y , i, 15, 1);              
        ledMatrix.plot(i, y, 3); 
        maxval[i] = min(maxval[i], y);
        ledMatrix.plot(i, maxval[i], 2); 
        if ( degrade ) {
          //maxval[i] = constrain(maxval[i] +1, 0, 15) ;  
          maxval[i] = maxval[i] + 1 ;        
        }        
      }
      i = 0;
 
 
      ledMatrix.sendframe();
    }
 
  }
 
 
};