IIRFilterNode.getFrequencyResponse() - Web APIs 编辑

The getFrequencyResponse() method of the IIRFilterNode interface takes the current filtering algorithm's settings and calculates the frequency response for frequencies specified in a specified array of frequencies.

The two output arrays, magResponseOutput and phaseResponseOutput, must be created before calling this method; they must be the same size as the array of input frequency values (frequencyArray).

Syntax

IIRFilterNode.getFrequencyResponse(frequencyArray, magResponseOutput, phaseResponseOutput);

Parameters

frequencyArray
A Float32Array containing an array of frequencies, specified in Hertz, which you want to filter.
magResponseOutput
A Float32Array to receive the computed magnitudes of the freqency response for each frequency value in the frequencyArray.
phaseResponseOutput
Float32Array to receive the computed phase response values in radians for each frequency value in the input frequencyArray.

Return value

undefined

Exceptions

NotSupportedError
The three arrays provided are not all of the same length.

Examples

In the following example we are using an IIR filter on a media stream (for a complete full demo, see our stream-source-buffer demo live, or read its source.) As part of this demo, we get the frequency responses for this IIR filter, for five sample frequencies. We first create the Float32Array objects we need, one containing the input frequencies, and two to receive the output magnitude and phase values:

var myFrequencyArray = new Float32Array(5);
myFrequencyArray[0] = 1000;
myFrequencyArray[1] = 2000;
myFrequencyArray[2] = 3000;
myFrequencyArray[3] = 4000;
myFrequencyArray[4] = 5000;

var magResponseOutput = new Float32Array(5);
var phaseResponseOutput = new Float32Array(5);

Next we create a <ul> element in our HTML to contain our results, and grab a reference to it in our JavaScript:

<p>IIR filter frequency response for: </p>
<ul class="freq-response-output">
</ul>
var freqResponseOutput = document.querySelector('.freq-response-output');

Finally, after creating our filter, we use getFrequencyResponse() to generate the response data and put it in our arrays, then loop through each data set and output them in a human-readable list at the bottom of the page:

var feedforwardCoefficients = [0.1, 0.2, 0.3, 0.4, 0.5];
var feedbackCoefficients = [0.5, 0.4, 0.3, 0.2, 0.1];

var iirFilter = audioCtx.createIIRFilter(feedforwardCoefficients, feedbackCoefficients);

  ...

function calcFrequencyResponse() {
  iirFilter.getFrequencyResponse(myFrequencyArray, magResponseOutput, phaseResponseOutput);

  for(i = 0; i <= myFrequencyArray.length-1;i++){
    var listItem = document.createElement('li');
    listItem.innerHTML = '<strong>' + myFrequencyArray[i] + 'Hz</strong>: Magnitude ' + magResponseOutput[i] + ', Phase ' + phaseResponseOutput[i] + ' radians.';
    freqResponseOutput.appendChild(listItem);
  }
}

calcFrequencyResponse();

Specifications

SpecificationStatusComment
Web Audio API
The definition of 'getFrequencyResponse()' in that specification.
Working Draft 

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:61 次

字数:5862

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文