# Printing the band with the highest amplitude (fft)

**URL:** <https://discourse.processing.org/t/printing-the-band-with-the-highest-amplitude-fft/27086>\
**Category:** Libraries\
**Created:** [January 15, 2021, 12:00pm UTC](https://discourse.processing.org/t/printing-the-band-with-the-highest-amplitude-fft/27086 "2021-01-15T12:00:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hangmansraven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hangmansraven/32/7285_2.png) [@Hangmansraven](https://discourse.processing.org/u/Hangmansraven)\
**Post date:** [January 15, 2021, 12:00pm UTC](https://discourse.processing.org/t/printing-the-band-with-the-highest-amplitude-fft/27086/1 "2021-01-15T12:00:17Z")

</div>

Hello,

I am currently trying to get into the sound library and especially fft analysis. I want to print the number of the band with the highest amplitude in the console for each draw loop. I used the following code but it is only returning 0.0 and 1.0:

```auto
import processing.sound.*;

FFT fft;
SoundFile sound;

int bands = 512;
float[] spectrum = new float[bands];
float max = 0;

void setup(){
  sound = new SoundFile(this, "demo_II.mp3");
  sound.loop();
  
  fft = new FFT(this, bands);
  fft.input(sound);
}

void draw(){
  fft.analyze(spectrum);
  max = 0;
  
  for(int i = 0; i < bands; i++){
    //println(i); // <- returning the correct value of i
    if(spectrum[i] > max){
      max = float(i);
    }
  }
  
  println(max);
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 15, 2021, 1:17pm UTC](https://discourse.processing.org/t/printing-the-band-with-the-highest-amplitude-fft/27086/2 "2021-01-15T13:17:23Z")

</div>

I think I know what’s happening.

You want to println the number of the highest band (not how high the amp of this band is)

Now, max stores just i, the number of the band

You need an addtional var maxValue to compare to

```auto
    if(spectrum[i] > maxValue ){
       maxValue = spectrum[i]; 
       max = i; 

```

**Remark**

I think maybe spectrum[i] is only between 0 and 1 because in the example they use `spectrum[i]*height*5` :

see [FFT \ Language (API) \ Processing 3+](https://www.processing.org/reference/libraries/sound/FFT.html)

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 16, 2021, 11:00pm UTC](https://discourse.processing.org/t/printing-the-band-with-the-highest-amplitude-fft/27086/3 "2021-01-16T23:00:31Z")

</div>

Hello,

> [@Hangmansraven](#):
>
> I used the following code but it is only returning 0.0 and 1.0

The description will explain this:  
[https://www.processing.org/reference/libraries/sound/FFT.html](https://www.processing.org/reference/libraries/sound/FFT.html)

[Normalization](https://www.statisticshowto.com/probability-and-statistics/normal-distributions/normalized-data-normalization/) usually means to scale a variable to have a values between 0 and 1.

This is what you were doing:  
[https://processing.org/reference/float.html](https://processing.org/reference/float.html)

Try this:

```auto
    if(spectrum[i] > max)
      {
      //max = float(i);
      max = spectrum[i];
      index = i;
      }
  }
  println(index, max);

```

`:)`
