I'm trying to use the Web Audio API's bandpass filter functionality, but I believe my question is more general. I don't understand the "Q" value of the bandpass filter. I would like to be able to configure the filter to pass frequencies that are within Y hertz of a middle frequency X hertz.
I'm very new to audio programming, so are there other variables I need to consider to compute Q?
Let's say you have a filter at 1000Hz, and you want it to start at 500Hz and end at 2000Hz.
First off, you'll notice it doesn't extend the same number of hertz in each direction. That's because filter bandwidth is based on octaves, not frequencies. So in this case, it extends one octave down and one octave up. Put another way, the frequency was divided by 2 on the low end and multiplied by 2 on the high end - which gives it a bandwidth of 2 octaves.
Anyway, here's how you can calculate it, assuming you know the frequencies:
Q = center_frequency / (top_frequency - bottom_frequency)
Which in this case would be 1000 / ( 2000 - 500 )
, or 0.667.
You can also calculate it without knowing the top and bottom frequencies as long as you have a target bandwidth (in octaves) in mind:
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'll get the same result: Q = 0.667.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With