How do I configure a bandpass filter?

前端 未结 1 1139
遥遥无期
遥遥无期 2021-01-13 12:29

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.

1条回答
  •  -上瘾入骨i
    2021-01-13 12:45

    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.

    0 讨论(0)
提交回复
热议问题