This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
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).
getFrequencyResponse(frequencyArray, magResponseOutput, phaseResponseOutput)
frequencyArrayA Float32Array containing an array of frequencies, specified in Hertz, which you want to filter.
magResponseOutputA Float32Array to receive the computed magnitudes of the frequency response for each frequency value in the frequencyArray.
phaseResponseOutputA Float32Array to receive the computed phase response values in radians for each frequency value in the input frequencyArray.
None (undefined).
NotSupportedError DOMException
Thrown if the three arrays provided are not all of the same length.
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:
const myFrequencyArray = new Float32Array(5); myFrequencyArray[0] = 1000; myFrequencyArray[1] = 2000; myFrequencyArray[2] = 3000; myFrequencyArray[3] = 4000; myFrequencyArray[4] = 5000; const magResponseOutput = new Float32Array(5); const 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>
const 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:
const feedforwardCoefficients = [0.1, 0.2, 0.3, 0.4, 0.5];
const feedbackCoefficients = [0.5, 0.4, 0.3, 0.2, 0.1];
const iirFilter = audioCtx.createIIRFilter(
feedforwardCoefficients,
feedbackCoefficients,
);
// …
function calcFrequencyResponse() {
iirFilter.getFrequencyResponse(
myFrequencyArray,
magResponseOutput,
phaseResponseOutput,
);
for (let i = 0; i < myFrequencyArray.length; i++) {
const listItem = document.createElement("li");
listItem.textContent = `${myFrequencyArray[i]}Hz: Magnitude ${magResponseOutput[i]}, Phase ${phaseResponseOutput[i]} radians.`;
freqResponseOutput.appendChild(listItem);
}
}
calcFrequencyResponse();
| Specification |
|---|
| Web Audio API> # dom-iirfilternode-getfrequencyresponse> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
getFrequencyResponse |
49 | 14 | 50 | 36 | 14.1 | 49 | 50 | 36 | 14.5 | 5.0 | 49 | 14.5 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IIRFilterNode/getFrequencyResponse