Thursday, July 20, 2017

fft - 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: enter image description here



Answer



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.


Pink approximation

Figure 1. Pink magnitude spectrum (red diamonds) compared to the original fft_max (blue dots).


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...