FHT example code

Hello again everybody! I’m trying to use Open Music Labs free FHT library and example code. However I am already using pin A0 for my LCD display but the pin address in the code seems to be the hexadecimal address. I may be way off the mark but I just need the FHT program to run from another input. any help would be appreciated, here is the code:

/*
fht_adc.pde
guest openmusiclabs.com 9.5.12
example sketch for testing the fht library.
it takes in data on ADC0 (Analog0) and processes them
with the fht. 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 FHT_N 256 // set to 256 point fht

#include <FHT.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 < FHT_N ; i++) { // 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
      fht_input[i] = k; // put real data into bins
    }
    fht_window(); // window the data for better frequency response
    fht_reorder(); // reorder the data before doing the fht
    fht_run(); // process the data in the fht
    fht_mag_log(); // take the output of the fht
    sei();
    Serial.write(255); // send a start byte
    Serial.write(fht_log_out, FHT_N/2); // send out the data
  }
}

It's the ADMUX register that tells the A/D which input to digitize.

0x40: analogReference(DEFAULT), Select input A0

You can select other inputs with:]
0x41: analogReference(DEFAULT), Select input A1
0x42: analogReference(DEFAULT), Select input A2
.
.
0x45: analogReference(DEFAULT), Select input A5

John thank you for your help! I now have an FHT code that works to some degree and the rest of my code.

I now have the problem that when i compile them together, what I am assuming is to do with the FHT setup code, is messing around with my LCD display.

#include <LCD4Bit_mod.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);
#define LOG_OUT 1 // use the log output function
#define FHT_N 256 // set to 256 point fht
#include <FHT.h> // include the library
float StrI[] = {285.43, 329.63, 369.99};
float StrII[] = {220.00, 246.94, 285.42};
float StrIII[] = {169.81, 196.00, 219.99};
float StrIV[] = {127.47, 146.83, 169.61};
float StrV[] = {95.25, 110.00, 127.57};
float StrVI[] = {65.406, 82.407, 95.15};
float Strings[] = {73.416, 95.00, 128.00, 170.00, 220.00, 285.00, 392.00};
float a = Strings[0];
float b = Strings[1];
float c = Strings[2];
float d = Strings[3];
float e = Strings[4];
float f = Strings[5];
float g = Strings[6];
float x;
float h = 0;
float l = 0;
float jp = 0;

void setup(){
  Serial.begin(115200);
  TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe6; // set the adc to free running mode
  ADMUX = 0x41; // use adc1
  DIDR0 = 0x02; // turn off the digital input for adc0
   pinMode(13, OUTPUT);  
  lcd.init();
   lcd.clear();
  lcd.printIn("Guitar Tuner");
  delay(1000);
  lcd.clear();
  lcd.printIn("By Liam Simpson");
  delay(1000);
  lcd.clear();
  lcd.printIn("E,A,D,G,b,e?");
  delay(3000);
  lcd.clear();
  }
void loop(){
  while(1) { // reduces jitter
    cli();  // UDRE interrupt slows this way down on arduino1.0
    for (int i = 0 ; i < FHT_N ; i++) { // 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
      fht_input[i] = k; // put real data into bins
    }
    fht_window(); // window the data for better frequency response
    fht_reorder(); // reorder the data before doing the fht
    fht_run(); // process the data in the fht
    fht_mag_log(); // take the output of the fht
    sei();
    Serial.write(255); // send a start byte
    int j = 0;
int k;
for (int i = 0; i < FHT_N/2; i++) {
  if (fht_log_out[i] > j) {
    j = fht_log_out[i];
    k = i*150;
    x = k;
  }
}
Serial.println(x);
  }
  Serial.println(x);
  if(x > Strings[0] && x < Strings[1]) {
    float h = StrVI[1];
    float l = StrVI[2];
    float jp = StrVI[0];
    lcd.cursorTo(1,0);
    lcd.printIn("E");
    if(x > h+1 && x < l) {
    lcd.cursorTo(2,0);
    lcd.printIn("Sharp");  
  }
  else if(x < h-1 && x > jp) {
    lcd.cursorTo(2,0);
    lcd.printIn("Flat");  
  }
  else if(x >= jp-1 && x <= l+1){
    lcd.cursorTo(2,0);
    lcd.printIn("Bingo!");  
  }
  else{
    lcd.cursorTo(2,0);
    lcd.printIn("Undetectable");
  }
  delay(1000);
  lcd.clear();
  }
  if(x > Strings[1] && x < Strings[2]) {
    float h = StrV[1];
    float l = StrV[2];
    float jp = StrV[0];
    lcd.cursorTo(1,2);
    lcd.printIn("A");
    if(x > h+1 && x < l) {
    lcd.cursorTo(2,0);
    lcd.printIn("Sharp");  
  }
  else if(x < h-1 && x > jp) {
    lcd.cursorTo(2,0);
    lcd.printIn("Flat");  
  }
  else if(x >= jp-1 && x <= l+1){
    lcd.cursorTo(2,0);
    lcd.printIn("Bingo!");  
  }
  else{
    lcd.cursorTo(2,0);
    lcd.printIn("Undetectable");
  }
  delay(1000);
  lcd.clear();
}
  if(x > Strings[2] && x < Strings[3]) {
    float h = StrIV[1];
    float l = StrIV[2];
    float jp = StrIV[0];
    lcd.cursorTo(1,4);
    lcd.printIn("D");
    if(x > h+1 && x < l) {
    lcd.cursorTo(2,0);
    lcd.printIn("Sharp");  
  }
  else if(x < h-1 && x > jp) {
    lcd.cursorTo(2,0);
    lcd.printIn("Flat");  
  }
  else if(x >= jp-1 && x <= l+1){
    lcd.cursorTo(2,0);
    lcd.printIn("Bingo!");  
  }
  else{
    lcd.cursorTo(2,0);
    lcd.printIn("Undetectable");
  }
  delay(1000);
  lcd.clear();
  }
  if(x > Strings[3] && x < Strings[4]) {
    float h = StrIII[1];
    float l = StrIII[2];
    float jp = StrIII[0];
    lcd.cursorTo(1,6);
    lcd.printIn("G");
    if(x > h+1 && x < l) {
    lcd.cursorTo(2,0);
    lcd.printIn("Sharp");  
  }
  else if(x < h-1 && x > jp) {
    lcd.cursorTo(2,0);
    lcd.printIn("Flat");  
  }
  else if(x >= jp-1 && x <= l+1){
    lcd.cursorTo(2,0);
    lcd.printIn("Bingo!");  
  }
  else{
    lcd.cursorTo(2,0);
    lcd.printIn("Undetectable");
  }
  delay(1000);
  lcd.clear();
  }
  if(x > Strings[4] && x < Strings[5]) {
    float h = StrII[1];
    float l = StrII[2];
    float jp = StrII[0];
    lcd.cursorTo(1,8);
    lcd.printIn("b"); 
  if(x > h+1 && x < l) {
    lcd.cursorTo(2,0);
    lcd.printIn("Sharp");  
  }
  else if(x < h-1 && x > jp) {
    lcd.cursorTo(2,0);
    lcd.printIn("Flat");  
  }
  else if(x >= jp-1 && x <= l+1){
    lcd.cursorTo(2,0);
    lcd.printIn("Bingo!");  
  }
  else{
    lcd.cursorTo(2,0);
    lcd.printIn("Undetectable");
  }
delay(1000);
lcd.clear();  
  }
  if(x > Strings[5] && x < Strings[6]) {
    float h = StrI[1];
    float l = StrI[2];
    float jp = StrI[0];
    lcd.cursorTo(1,10);
    lcd.printIn("e");
    if(x > h+1 && x < l) {
    lcd.cursorTo(2,0);
    lcd.printIn("Sharp");  
  }
  else if(x < h-1 && x > jp) {
    lcd.cursorTo(2,0);
    lcd.printIn("Flat");  
  }
  else if(x >= jp-1 && x <= l+1){
    lcd.cursorTo(2,0);
    lcd.printIn("Bingo!");  
  }
  else{
    lcd.cursorTo(2,0);
    lcd.printIn("Undetectable");
  }
  delay(1000);
  lcd.clear();
 }
}

This is my code so far. I’m not sure which parts are conflicting so I had to just put it all in.

I’m also only using it with frequencies between 73-400Hz, is there anything I can change to give it a higher resolution within that bandwidth?

Thanks.