# What is the purpose of the following code?

So I'm attempting to setup a LED visualizer using a python library called Impulse. I've already repaired some of the initial issues with the code in my own custom fork, and now I'm attempting to change the chunk size to something a bit more high-resolution. I got the idea from this question, but the issue is I'm a bit lost as to what a certain part of the code does.

I've kinda hit a wall. The bit of code is here. I don't understand what it refers to by fft_max, but I need to figure out what it is so I can determine how to calculate and expand the array to match the higher sample chunk. I apologize if this is in the wrong section, as it is highly related to programming, but I figured someone here might know what fft_max might be referring to.

Here is a plot of fft_max:

• Can you please edit your question for clarity? It would be good to have a high level description of what Impulse does and what fft_max refers to. In the meantime, please note the way that the magnitude spectrum is calculated on line 189. For more information please see this link, section "Computations using the FFT". – A_A Oct 15 '16 at 11:12
• @A_A what is noteworthy of that calculation? To me it looks like a generic vector magnitude formula, which also helps eliminate the imaginary component of the returns from FFT. – duper51 Oct 15 '16 at 22:53
• Exactly, that is what it is and fft_max is used to normalise it as indicated by Olli Niemitalo's response. Do you need it? I don't know, maybe within the context of that code you do, I haven't gone through it in detail. The main point is that the output of the DFT is complex and to obtain the magnitude of its value you need to calculate that "vector magnitude" you refer to. You could try with and without division by fft_max to see how the results differ. – A_A Oct 16 '16 at 0:08

I think fft_max is a kind of equalization table so that the visualization would be "flat" over all frequencies for a typical input. It does not look carefully crafted as it is so spiky. Probably the author just used some example audio input and kept book of the largest encountered values of the magnitudes of the bins, hence the name of the table. If you need a different length fft_max, it would be fine to interpolate the original fft_max say by linear interpolation, or to roll your own (not a cigarette).
You could use the synthetic pink power spectral density $a^2/f$, where $a$ is a normalization constant and $f$ is frequency. In terms of magnitude which you need to put into code, that would be $a/\sqrt{f}$, the square root of power. Put some reasonable value to $f = 0$, for example copy the value at the first non-zero frequency.
Figure 1. Pink magnitude spectrum (red diamonds) compared to the original fft_max (blue dots).