Let's say you have a filter with a frequency of 1000 Hz, and you want it to start at 500 Hz and end at a frequency of 2000 Hz.
Firstly, you will notice that it does not expand the same number of hertz in each direction. This is because the filter bandwidth is based on octaves rather than frequencies. Thus, in this case, it expands one octave down and one octave up. In other words, the frequency was divided by 2 at the lower end and multiplied by 2 at the upper end, giving it a bandwidth of 2 octaves.
In any case, how can you calculate it if you know the frequencies:
Q = center_frequency / (top_frequency - bottom_frequency)
In this case, it will be 1000 / ( 2000 - 500 ) , or 0.667.
You can also calculate it without knowing the upper and lower frequencies if you have the target bandwidth (in octaves):
function getQ( bandwidth ){ return Math.sqrt( Math.pow(2, bandwidth) ) / ( Math.pow(2, bandwidth) - 1 ) }
Again, if you pass 2 as the bandwidth argument, you get the same result: Q = 0.667.
Hope this helps.
source share