If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding premade modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
Splitting FFT spectrum into octave bands? how? worth it?
15 posts
• Page 1 of 2 • 1, 2
Splitting FFT spectrum into octave bands? how? worth it?
Hello ALL !!!
I'm just building a simple vertical bar graph display that shows (with fantastic accuracy hopefully) the volume of 10 or 12 different octaves (1 octave per bar, 01/inf  unitydb) .
~~~
I'm currently utilizing bw bandsplitters, and envelope followers to get my signal (saw a few others implement this approach, made my own from scratch. cpu heavy but It works great... proud ) but >>>>
I thought hey maybe I could increase accuracy and reduce cpu usage by analyzing to get a fft spectrum, divide the bins/array sections(?) into groups of octaves (how? math?) getting the magnitude into a 01 scale, adding the bins in each octave group together and rescaling the mag to get average of the octave, and using this as my amplitude to drive my bar graph... I would love the ability to change/choose the (f*2^n) band /octave splitter points with ease... I'm just not super hip to manipulating these fft arrays... I'm smart, yet not smart !
~~~
I know it sounds like I'm making a request for a schematic (not opposed to getting one ) but I'm more so wondering on the math/logic of getting my magnitudes, and dividing these bins into octave groups...
(would the octave splitter cutoffs be too steep to illustrate average amplitude? If that assumption holds weight.. is there a work around to simulate cutoff slopes?? is that thought relevant whatsoever??)
AND more importantly fft wisdom in general,, ? (samples? mag accuracy? bin vs freq? speed, responsive enough for multiband modulation? HELL... phase? pitch correlation/detection??)
prolly easier than I think. I'm thinking about just sweeping with sin waves and figuring it out (please save me...)
PS: also could I further this to semitone accuracy ( 10 octaves * 12 semitones = 120 band bar graph ..genius? dumb? needed? UNWARRANTED?? )
~~~
~~~
TLDR:
Ultimately the question is, will this yield me a result that is less CPU intensive and more accurate (speed/sync, freq, volume) ?
FFT Spectrum OCTAVES AMP BAR GRAPH
To whatever brave soul that has read this, I hope I have inspired you and we can exchange more ideas.. AND HOPEFULLY you can EDUCATE your friend here....
~That Guy
I'm just building a simple vertical bar graph display that shows (with fantastic accuracy hopefully) the volume of 10 or 12 different octaves (1 octave per bar, 01/inf  unitydb) .
~~~
I'm currently utilizing bw bandsplitters, and envelope followers to get my signal (saw a few others implement this approach, made my own from scratch. cpu heavy but It works great... proud ) but >>>>
I thought hey maybe I could increase accuracy and reduce cpu usage by analyzing to get a fft spectrum, divide the bins/array sections(?) into groups of octaves (how? math?) getting the magnitude into a 01 scale, adding the bins in each octave group together and rescaling the mag to get average of the octave, and using this as my amplitude to drive my bar graph... I would love the ability to change/choose the (f*2^n) band /octave splitter points with ease... I'm just not super hip to manipulating these fft arrays... I'm smart, yet not smart !
~~~
I know it sounds like I'm making a request for a schematic (not opposed to getting one ) but I'm more so wondering on the math/logic of getting my magnitudes, and dividing these bins into octave groups...
(would the octave splitter cutoffs be too steep to illustrate average amplitude? If that assumption holds weight.. is there a work around to simulate cutoff slopes?? is that thought relevant whatsoever??)
AND more importantly fft wisdom in general,, ? (samples? mag accuracy? bin vs freq? speed, responsive enough for multiband modulation? HELL... phase? pitch correlation/detection??)
prolly easier than I think. I'm thinking about just sweeping with sin waves and figuring it out (please save me...)
PS: also could I further this to semitone accuracy ( 10 octaves * 12 semitones = 120 band bar graph ..genius? dumb? needed? UNWARRANTED?? )
~~~
~~~
TLDR:
Ultimately the question is, will this yield me a result that is less CPU intensive and more accurate (speed/sync, freq, volume) ?
FFT Spectrum OCTAVES AMP BAR GRAPH
To whatever brave soul that has read this, I hope I have inspired you and we can exchange more ideas.. AND HOPEFULLY you can EDUCATE your friend here....
~That Guy

guyman  Posts: 198
 Joined: Fri Mar 02, 2018 8:27 pm
Re: Splitting FFT spectrum into octave bands? how? worth it?
Coincidentally, there' s been some discussion of related problems on tulamide's thread HERE, which may be of interest.
In short, when you use the FFT, you have to make a trade, balancing two factors...
 Precise frequency measurement. This gets better for bigger blocks of samples passed to the FFT, but bigger blocks will add latency (time delay) while you collect the samples to fill the next block. The block size also determines the lowest frequency that you can measure (excepting bin zero, which is the DC offset plus everything below bin one)  so if you need an accurate display for the subbass octave, you'll need to use a very long block of samples!
 Precise timing/lowlatency. The output bins of the FFT only tell you what frequencies happened at some point within the block of samples  but not where in the block they are present. So to react to changes quickly, or to analyse transients, you have to use small block sizes, sacrificing frequency precision and the bass end.
For your display, there are also a couple of added complications...
 The frequency 'bins' output by the FFT are spread linearly across frequency  each bin spans the same number of Hz. So each octave of the signal will have to average a different number of bins  the top half of the bins will be the highest octave, the top half of the remainder, the next octave down, and so on, until you reach the lowest band, which will have only a single bin (repeated halving will always work because the block size has to be a power of two for the usual FFT implementation.)
 The boundaries for the bins depend only on the sample rate and the number of bins. So if you wanted to control where the boundaries between octaves are, you'd have to resample the signal to a different sampling rate.
 Each bin doesn't perfectly isolate a band of frequencies  they 'leak' into the bins on either side (a bit like the slope of a conventional filter.) Because the bands are spread linearly across frequency, the upshot is that the measurements will get less and less selective for lower octaves. Or you could say that the lower frequencies are trickier because the analysis has fewer cycles of the wave to work from  it amounts to the same thing in practice.
 It's not necessarily more efficient. An FFT with a sample block of N samples is effectively calculating N/2 bandpass filters. While it does calculate these very efficiently, if you use a block long enough to reach into the bass region, that still a lot more filters that your current method is using!
As I said in the other thread that I linked to, whatever method you use to split the frequencies, the tradeoffs are theoretically the same  the FFT is certainly very handy and efficient for many kinds of analysis, but the problems of the time/frequency tradeoff and leakage between 'bands' are just inherent to any method of analysing waves.
In short, when you use the FFT, you have to make a trade, balancing two factors...
 Precise frequency measurement. This gets better for bigger blocks of samples passed to the FFT, but bigger blocks will add latency (time delay) while you collect the samples to fill the next block. The block size also determines the lowest frequency that you can measure (excepting bin zero, which is the DC offset plus everything below bin one)  so if you need an accurate display for the subbass octave, you'll need to use a very long block of samples!
 Precise timing/lowlatency. The output bins of the FFT only tell you what frequencies happened at some point within the block of samples  but not where in the block they are present. So to react to changes quickly, or to analyse transients, you have to use small block sizes, sacrificing frequency precision and the bass end.
For your display, there are also a couple of added complications...
 The frequency 'bins' output by the FFT are spread linearly across frequency  each bin spans the same number of Hz. So each octave of the signal will have to average a different number of bins  the top half of the bins will be the highest octave, the top half of the remainder, the next octave down, and so on, until you reach the lowest band, which will have only a single bin (repeated halving will always work because the block size has to be a power of two for the usual FFT implementation.)
 The boundaries for the bins depend only on the sample rate and the number of bins. So if you wanted to control where the boundaries between octaves are, you'd have to resample the signal to a different sampling rate.
 Each bin doesn't perfectly isolate a band of frequencies  they 'leak' into the bins on either side (a bit like the slope of a conventional filter.) Because the bands are spread linearly across frequency, the upshot is that the measurements will get less and less selective for lower octaves. Or you could say that the lower frequencies are trickier because the analysis has fewer cycles of the wave to work from  it amounts to the same thing in practice.
 It's not necessarily more efficient. An FFT with a sample block of N samples is effectively calculating N/2 bandpass filters. While it does calculate these very efficiently, if you use a block long enough to reach into the bass region, that still a lot more filters that your current method is using!
As I said in the other thread that I linked to, whatever method you use to split the frequencies, the tradeoffs are theoretically the same  the FFT is certainly very handy and efficient for many kinds of analysis, but the problems of the time/frequency tradeoff and leakage between 'bands' are just inherent to any method of analysing waves.
All schematics/modules I post are free for all to use  but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!

trogluddite  Posts: 1706
 Joined: Fri Oct 22, 2010 12:46 am
 Location: Yorkshire, UK
Re: Splitting FFT spectrum into octave bands? how? worth it?
Wow, you broke that down perfectly. Just what I needed to hear. Everything seems to have it's trade off.
Thank you Trogg !
Thank you Trogg !

guyman  Posts: 198
 Joined: Fri Mar 02, 2018 8:27 pm
Re: Splitting FFT spectrum into octave bands? how? worth it?
Here is an octave band analyzer demo. Have fun!
 Attachments

 OctaveSpectrumDisplay.fsm
 (35.41 KiB) Downloaded 577 times

martinvicanek  Posts: 1169
 Joined: Sat Jun 22, 2013 8:28 pm
Re: Splitting FFT spectrum into octave bands? how? worth it?
@guyman
You're welcome!
@martinvicanec
A brilliant example, as ever! One question for you  I'm guessing that the window is something like a gaussian function, but what are the polynomial coefficients generating exactly, and how did you work them out?
You're welcome!
@martinvicanec
A brilliant example, as ever! One question for you  I'm guessing that the window is something like a gaussian function, but what are the polynomial coefficients generating exactly, and how did you work them out?
All schematics/modules I post are free for all to use  but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!

trogluddite  Posts: 1706
 Joined: Fri Oct 22, 2010 12:46 am
 Location: Yorkshire, UK
Re: Splitting FFT spectrum into octave bands? how? worth it?
Results were unsatisfactory. I'm going with envelope followers on mono streams to float. Is there a more efficient way of doing this? I'm running crazy high cpu all over the place. 10 bands is a lot.

guyman  Posts: 198
 Joined: Fri Mar 02, 2018 8:27 pm
Re: Splitting FFT spectrum into octave bands? how? worth it?
guyman wrote:Is there a more efficient way of doing this?
A few things come to mind, but it would be easier to advise if you could upload a schematic for us to look at. Typically, for this kind of thing, I'd be thinking of...
 Filter code often has parts which don't need recalculating for every sample if/when the cutoff frequency is rarely changed.
 Multiple mono stream modules can often be condensed into mono4 stream modules, so that you get "four for the price of one."
 Animated GUI elements can often be optimised to reduce the CPU load from graphics rendering.
All schematics/modules I post are free for all to use  but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!

trogluddite  Posts: 1706
 Joined: Fri Oct 22, 2010 12:46 am
 Location: Yorkshire, UK
Re: Splitting FFT spectrum into octave bands? how? worth it?
Thank you, Trog. As you know, in analysis it is important to use a window function to reduce spectral leakage (at the cost of losing some resolution). Many different window functions have been proposed, however basically it is a tradeoff between contrast and reslution:
narrow window function > wide main lobe (low resolution), good side lobe attenuation (little spectral leakage)
wide window function > narrow main lobe (good resolution), bad side lobe suppression (strong spectral leakage)
The popular Kaiser window is a oneparametric family, however is is a bit difficult to evaluate since it involves Bessel functions. Therefore I designed my own window functions with the following properties:
win2  a fast approximation of the Hann window.
// Main lobe half width = 2
// Side lobe attenuation > 30 dB
// Tail falloff = 1/f^3
win3
// Main lobe half width = 3
// Side lobe attenuation > 60 dB
// Tail falloff = 1/f^3
win4
// Main lobe half width = 4
// Side lobe attenuation > 90 dB
// Tail falloff = 1/f^3
win3 and win4 have maximum side lobe attenuation at given main lobe half width and tail falloff. I used Excel solver to determine the coefficients.
narrow window function > wide main lobe (low resolution), good side lobe attenuation (little spectral leakage)
wide window function > narrow main lobe (good resolution), bad side lobe suppression (strong spectral leakage)
The popular Kaiser window is a oneparametric family, however is is a bit difficult to evaluate since it involves Bessel functions. Therefore I designed my own window functions with the following properties:
win2  a fast approximation of the Hann window.
// Main lobe half width = 2
// Side lobe attenuation > 30 dB
// Tail falloff = 1/f^3
win3
// Main lobe half width = 3
// Side lobe attenuation > 60 dB
// Tail falloff = 1/f^3
win4
// Main lobe half width = 4
// Side lobe attenuation > 90 dB
// Tail falloff = 1/f^3
win3 and win4 have maximum side lobe attenuation at given main lobe half width and tail falloff. I used Excel solver to determine the coefficients.
 Attachments

 MVsWindowFunctions.fsm
 (88.77 KiB) Downloaded 539 times

martinvicanek  Posts: 1169
 Joined: Sat Jun 22, 2013 8:28 pm
Re: Splitting FFT spectrum into octave bands? how? worth it?
martinvicanek wrote:As you know...
Well, in gist if not in detail  I run away when I see differential calculus! Your adeptness with the mathematics never ceases to amaze me! Many thanks for those, I've no doubt they'll come in handy when I emerge from my Ruby rabbit hole back into DSP land!
All schematics/modules I post are free for all to use  but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!

trogluddite  Posts: 1706
 Joined: Fri Oct 22, 2010 12:46 am
 Location: Yorkshire, UK
Re: Splitting FFT spectrum into octave bands? how? worth it?
I'll upload more cogs to my clock once I'm done doing my own optimizations. Here is my 8 pole lwr octave band splitter that I'm using. The config is setup for amplitude analysis only and not multiband recombination (phase shifts at each split). it has a x(y^n) float chain that calculates cutoff points, with text edit boxes to customize it. Could probably be more efficient, but again I'm full of afflatus and lacking craft.

guyman  Posts: 198
 Joined: Fri Mar 02, 2018 8:27 pm
15 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: Majestic12 [Bot] and 23 guests