I have code example that divides audio frequency into 6 channels. It uses Fast Fourier Transform (FFT). Algorithm process the frequency range using 6 capture[x] samples based on the range of n between 0 and 63. The separation looks logarithmic. I want modify code to split frequency band into 4 channels, so I need to change the boundaries here. What should be the new values for 4 channels? Problem is that I don't know what is corresponding frequency range to each value. The existing divisions use:
# of samples
1) 0 1
2) 1..3 3
3) 4..11 8
4) 12..21 10
5) 22..34 13
6) 35..63 29
code
for (uint8_t n = 0; n < FFT_N / 2; n++) {
s = spektrum[n];
if(n == 0) { // lowest frequency band
if(s <= SCORE_MAX) capture[0] = s;
else capture[0] = SCORE_MAX;
}
if((n >= 1) && (n <= 3)) {
if((capture[1] + s) <= SCORE_MAX) capture[1] += s;
else capture[1] = SCORE_MAX;
}
if((n >= 4) && (n <= 11)) {
if((capture[2] + s) <= SCORE_MAX) capture[2] += s;
else capture[2] = SCORE_MAX;
}
if((n >= 12) && (n <= 21)) {
if((capture[3] + s) <= SCORE_MAX) capture[3] += s;
else capture[3] = SCORE_MAX;
}
if((n >= 22) && (n <= 34)) {
if((capture[4] + s) <= SCORE_MAX) capture[4] += s;
else capture[4] = SCORE_MAX;
}
if((n >= 35) && (n <= 63)) { // highest frequency band
if((capture[5] + s) <= SCORE_MAX) capture[5] += s;
else capture[5] = SCORE_MAX;
}
}
Full code here.
If $N$ is the FFT length, which I assume is $128$ in your example, then the frequency corresponding to the FFT bin with index $i$ is given by
$$f_i=\frac{if_s}{N},\quad i=0,1,\ldots, N/2\tag{1}$$
where $f_s$ is the sampling frequency.
EDIT: From (1) you can find the index corresponding (approximately) to a given frequency $f$ by
$$i=\left\lfloor\frac{Nf}{f_s}\right\rfloor$$
Note that for a sampling frequency $f_s=19\,\text{kHz}$ your maximum frequency is $19/2=9.5\,\text{kHz}$, so you can't implement the frequency ranges you desire. For the highest band between $6$ and $20\,\text{kHz}$ you need a sampling frequency $f_s>40\,\text{kHz}$.