getting a larger spectrum window?

Status
Not open for further replies.
Hey guys, still trying to get my audio project working. I do have the audio shield and fht working with that, but I need to just get basic spectrum from it. I really just need lows, mids, and highs. I am doing something wrong however. How do I just get those 3 groups?

I hacked out the code from my much larger project and this is the JIST of what I tried..
The results of this seems to be any sounds are read by the low band.
Am I just using the wrong values in the read?

Code:
AudioInputI2S            i2s1;           //xy=136,96
  AudioMixer4              mixer1;         //xy=459,109
  AudioAnalyzePeak         peak1;          //xy=677,84
  AudioOutputAnalog        dac1;           //xy=690,269
  AudioAnalyzeFFT256       myFFT;          //xy=694,182
  AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
  AudioConnection          patchCord2(i2s1, 1, mixer1, 1);
  AudioConnection          patchCord3(mixer1, myFFT);
  AudioConnection          patchCord4(mixer1, peak1);
  AudioConnection          patchCord5(mixer1, dac1);

  const int myInput = AUDIO_INPUT_MIC;

  AudioControlSGTL5000 audioShield;


float lowBand = 0.0;
float midBand = 0.0;
float highBand = 0.0;

void setup() {
  Serial.begin(57600);
  delay(3000); // 3 second delay for recovery

  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(0.5);

}

void vuMeter()
{
  //float n;
  //int i;

  if (myFFT.available()) {

    lowBand = myFFT.read(0,42);
    midBand = myFFT.read(43,85);
    highBand = myFFT.read(85,127);
        Serial.print(lowBand);
        Serial.print(" ");
        Serial.print(midBand);
        Serial.print(" ");
        Serial.print(highBand);
        Serial.println();
    }
    
}
 
Am I just using the wrong values in the read?

Yeah, pretty much. You've got a linear style scale, with 3rd of the bands in the low range. But humans perceive sound in octaves, not linearly. The bass sounds are only the bottom few bins. The top half is the very last octave of extremely high pitch sounds hardly anyone can hear well. Your high region is only 66% of that octave.

Play with the numbers on those 3 reads. Think in octaves. You're on the right track, just needing different ranges.
 
Last edited:
Yeah, pretty much. You've got a linear style scale, with 3rd of the bands in the low range. But humans perceive sound in octaves, not linearly. The bass sounds are only the bottom few bins. The top half is the very last octave of extremely high pitch sounds hardly anyone can hear well. Your high region is only 66% of that octave.

Play with the numbers on those 3 reads. Think in octaves. You're on the right track, just needing different ranges.
Awesome, thanks for the quick response. Was I right in the thinking that it goes to 128, or should it go to 256 since it is a fht256?
 
Yes, there are 128 bins. Each bin has a width of 172.25Hz so your three ranges will be:
Code:
 0 -  42 =     0 -  7235Hz
43 -  85 =  7407 - 14643Hz
86 - 127 = 14800 - 22100Hz
If you look at the first table in this Wikipedia article you'll see that your range of bins 0-42 covers everything from low bass notes up to the upper reaches of the human voice. This demonstrates what Paul was saying.

Using that table, I'd suggest these ranges as a starting point:
0-3 frequencies up to 517Hz, but maybe try 1-3 to get rid of whatever DC component is in the audio input.
4-12 frequencies up to about 2048Hz
13-93 up to 16kHz - which is well above my hearing range :)

Another website I saw suggested that "lows" are frequencies up to 320Hz. Midrange is 320-3200 and "highs" are all above 3200. In this case the bin ranges would be:
0 - 2 (or 1-2)
3 - 19
20 - 93

Try them both and if they don't work as you like, play with the ranges until you get a satisfactory result.

Pete
 
Yes, there are 128 bins. Each bin has a width of 172.25Hz so your three ranges will be:
Code:
 0 -  42 =     0 -  7235Hz
43 -  85 =  7407 - 14643Hz
86 - 127 = 14800 - 22100Hz
If you look at the first table in this Wikipedia article you'll see that your range of bins 0-42 covers everything from low bass notes up to the upper reaches of the human voice. This demonstrates what Paul was saying.

Using that table, I'd suggest these ranges as a starting point:
0-3 frequencies up to 517Hz, but maybe try 1-3 to get rid of whatever DC component is in the audio input.
4-12 frequencies up to about 2048Hz
13-93 up to 16kHz - which is well above my hearing range :)

Another website I saw suggested that "lows" are frequencies up to 320Hz. Midrange is 320-3200 and "highs" are all above 3200. In this case the bin ranges would be:
0 - 2 (or 1-2)
3 - 19
20 - 93

Try them both and if they don't work as you like, play with the ranges until you get a satisfactory result.

Pete

Thanks for the detailed response! I will when I get home :D
 
Thanks for the detailed response! I will when I get home :D

So, I got it kinda worked out, I was getting some weird results tho. But I think its good enough for now.
The weird results were I would get values in the high container when I was using a tone generator with a tone that should only be in the mid container, thru a cord from my phone, not a speaker to a mic. Id assume there would be no frequency crossover in that situation, but was getting some.
This has also allowed me to have a test case for my other thread here

https://forum.pjrc.com/threads/36126-audio-quot-sticking-quot

if I use the 0 container it stores values in it, so I cant use it, which sucks cause then I loose the lowest base tones
 
Status
Not open for further replies.
Back
Top