Help with using analogRead() instead of ADMUX in FHT program

So recently I decided to create a spectrum analyzer using FHT to transform an audio input through a 3.5mm jack to a digital signal with the onboard ADC. I tried using the sample code provided from the ArduinoFHT Wiki, but I can't seem to adjust the range of frequencies. I'm new to this stuff with a little programming experience. I read online that it is easier to use analogRead() instead of ADMUX to change the range of frequencies, but I don't know how. My question is: how do I use analogRead() instead of ADMUX = 0x40?

My Current Code:

#define LIN_OUT8 1 // use the log output function
#define FHT_N 16 // 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
   int analogPin = 0;
   int val = 0;
 }
 
 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 16 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_lin8(); // take the output of the fht
     sei();
     for(int i = 0; i < 16; i++){
       Serial.println(fht_lin_out8[i]);
       delay(15000);
     }
     //Serial.println(fht_lin_out8[7]);
   }
}

I am using the serial monitor to print the magnitude of the frequency bins at a slow and readable rate. However, most of the magnitudes of my frequency bins are returning as 0. I assume this is because of a frequency range that is too large. In the serial monitor, I get the following:

28
16
0
0
0
0
0
0
0
0
0
0
0
0
0
0
119
65
3
0
0
0
0
0
0
0
0
0
0
0
0
0
119
65
3
0
0
0
0
0
0
0
0
0
0
0
0
0
119
65
3
0
0
0
0
0
0
0
0
0
0
0
0
0
119
65
3
0
0
0
0
0
0
0
0
0
0
0
0
0
119
65
3
0
0
0
0
0
0
0
0
0
0
0
0
0

And it keeps updating. When I place my thumb on a wire plugged into the A0 port on the Arduino Uno, I get the following:

119
65
3
0
0
0
0
0
0
0
0
0
0
0
0
0
84
46
3
0
0
0
0
0
0
0
0
0
0
0
0
0
38
21
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
6
1
0
0
0
0
0
0
0
0
0
0
0
0
0
50
28
0
0
0
0
0
0
0
0
0
0
0
0
0
0
82
44
1
0
0
0
0
0
0
0
0
0
0
0
0
0
98
54
3
0
0
0
0
0
0
0
0
0
0
0
0
0
110
60
1
1
0
0
0
0
0
0
0
0
0
0
0
0

Can someone please explain what I am doing wrong and how I can fix it?

Basically you do not use analogue read because your range of frequencies depends on the number of samples you take and the sample rate.
Using an analogue read will only reduce the top frequency you can discriminate.

What range of frequencies do you want to cover?
What sort of Arduino are you using?
What do you want to do with the results?
Have you an AC coupled input and bias resistors?

Grumpy_Mike:
Basically you do not use analogue read because your range of frequencies depends on the number of samples you take and the sample rate.
Using an analogue read will only reduce the top frequency you can discriminate.

What range of frequencies do you want to cover?
What sort of Arduino are you using?
What do you want to do with the results?
Have you an AC coupled input and bias resistors?

What I am trying to do is to take an audio input through the A0 port of my Arduino and convert the input into a digital signal. I then wish to find the amplitude of each frequency, and light up a certain amount of LEDs for each frequency. I don't really know how to determine what range I want to cover, but I plan on playing .AAC files through the input if that helps. I am using an Arduino UNO, and I'm not using an AC coupled input or using bias resistors. What does an AC coupled input and bias resistors do exactly in this scenario? By eliminating the DC signal from the input, does it really change anything? Does the signal coming from a 3.5mm audio plug send both AC and DC signals?

What does an AC coupled input and bias resistors do exactly in this scenario?

Many things:-

  1. It adds a DC bias to the signal.
  2. It stops negative signals getting into the Arduino analogue input and possible damaging it.
  3. It means that a zero audio input will produce an analogue reading of 512 which is the center point, then any signal will produce numbers above and below this datum point. Otherwise half the signal is going to be chopped off and screw up any measurements you want to make on the waveform.

but I plan on playing .AAC files through the input if that helps.

If it is an audio signal then it is totally irrelevant from what file format it was derived.

Does the signal coming from a 3.5mm audio plug send both AC and DC signals?

It is normally just an AC signal, which is no good for direct connection to an Arduino analogue input as it will only measure positive voltages.

You need a 2.5V peak to peak audio signal to fully drive the Arduino, anything less will not be as good.

The frequencies are derived from your sample rate. The top bin contains the frequencies with a period of twice the sample period. The next down will contain the second harmonic of this, and so on increasing the number of the harmonic in each successively lower bin. Note this is not how the ear will perceive those frequencies so you will have to do a bit of juggling averaging several bins to get what you perceive to be a linear frequency distribution.

For more information about the FFT see my book:-