Hey guys,

I've got a new project:

I recently received another 8x8 matrix LED display, powered by the Maxim MAX7219 chip, it works fine with the LED control library.

What i'm having a go at is a really simple graphic equalizer. Now I don't actually do any formal studying of electronics or mathematics so please bare with my lack of ability!

I know of the fourier transform so i'm merely going off my knowledge of that and i've written this code:

#include <math.h>

```
```volatile int16 Sample[256], SampleRead, SampCount;

int16 Wa1[256], Wa2[256], Wa3[256], Wa4[256], Wa5[256], Wa6[256], Wa7[256], Wa8[256];

int16 MidP, NextSamples = 1;

double SineD = 0;

byte Fv = 127;

int16 Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8;

HardwareTimer SampleTimer(2);

void setup(){

SerialUSB.begin();

SampleTimer.pause();

//Create Sine wave arrays

for(int WaveWrite; WaveWrite<256; WaveWrite++){

Wa1[WaveWrite] = 127*sin(SineD); //~70Hz

Wa2[WaveWrite] = 127*sin(SineD*2); //~141Hz

Wa3[WaveWrite] = 127*sin(SineD*4); //~281Hz

Wa4[WaveWrite] = 127*sin(SineD*8); //~563Hz

Wa5[WaveWrite] = 127*sin(SineD*16); //1125Hz

Wa6[WaveWrite] = 127*sin(SineD*32); //2250Hz

Wa7[WaveWrite] = 127*sin(SineD*64); //4500Hz

Wa8[WaveWrite] = Fv; //9000Hz

SineD+=0.024544;

Fv*=-1;

}

pinMode(0, INPUT_ANALOG); //Analog Input (mid biased 2x 1k resistors)

adc_set_sample_rate(ADC1, ADC_SMPR_1_5); //Fastest sampling rate

//Sample rate of 18KHz

SampleTimer.setPrescaleFactor(1);

SampleTimer.setOverflow(3999);

SampleTimer.setChannel1Mode(TIMER_OUTPUT_COMPARE);

SampleTimer.setCompare(TIMER_CH1, 1);

SampleTimer.attachCompare1Interrupt(Sampling);

SampleTimer.refresh();

SampleTimer.resume();

delay(1000);

MidP = analogRead(0); //Find mid point of circuit, no audio applied

}

void loop(){

if(SampCount>=255){

NextSamples = 0; //Stop more samples being processor

//Compute FT, multiply all sine tables by samples and sum to store in bin(s)

for(int FT = 0; FT<256; FT++){

Bin1 += (Sample[FT]*Wa1[FT]);

Bin2 += (Sample[FT]*Wa2[FT]);

Bin3 += (Sample[FT]*Wa3[FT]);

Bin4 += (Sample[FT]*Wa4[FT]);

Bin5 += (Sample[FT]*Wa5[FT]);

Bin6 += (Sample[FT]*Wa6[FT]);

Bin7 += (Sample[FT]*Wa7[FT]);

Bin8 += (Sample[FT]*Wa8[FT]);

}

//Magnitude of bins, shift to 8bit range

Bin1 = (abs(Bin1))>>7;

Bin2 = (abs(Bin2))>>7;

Bin3 = (abs(Bin3))>>7;

Bin4 = (abs(Bin4))>>7;

Bin5 = (abs(Bin5))>>7;

Bin6 = (abs(Bin6))>>7;

Bin7 = (abs(Bin7))>>7;

Bin8 = (abs(Bin8))>>7;

SampCount = 0; //Reset sample counter

NextSamples = 1; //Start next set of samples

}

else{

//While the FT isn't being calculated, print bins, debug only

SerialUSB.print(Bin1);

SerialUSB.print(" ");

SerialUSB.print(Bin2);

SerialUSB.print(" ");

SerialUSB.print(Bin3);

SerialUSB.print(" ");

SerialUSB.print(Bin4);

SerialUSB.print(" ");

SerialUSB.print(Bin5);

SerialUSB.print(" ");

SerialUSB.print(Bin6);

SerialUSB.print(" ");

SerialUSB.print(Bin7);

SerialUSB.print(" ");

SerialUSB.println(Bin8);

}

}

`void Sampling(){`

//Samples done here

if(NextSamples==1){

SampleRead = (analogRead(0) - MidP)>>4; //Sample and subtract midpoint(constant), shift to 8 bit range

Sample[SampCount] = SampleRead; //Store samples in array

SampCount++; //Increment sample counter

}

}

```
```As you can see, its creating 8 sine wave arrays of different frequencies in the setup and once a full 256 array of samples has been done, carrying out a real only fourier transform on the sample array (no phase).

What I then want to do with the 8 bins is convert them into 3 bit values to then be used to drive my graphic LED.

The only problem i'm having is when I upload this code, the LED on my maple just throbs at me and it doesn't want to do anything. What seems to be wrong with my code and how can I fix it? I've tried replacing the "next samples" section for timer pause and refresh/resume but this still caused the throbbing LED problem. My maple still works as I can upload the blink program successfully.

`Thanks,`

Harris