# designParamEQ

Design parametric equalizer

## Syntax

## Description

`[`

specifies options using one or more `B`

,`A`

] =
designParamEQ(___,`Name,Value`

)`Name,Value`

pair
arguments.

## Examples

### Design Two-Band Parametric Equalizer

Specify the filter order, peak gain in dB, normalized center frequencies, and normalized bandwidth of the bands of your parametric equalizer.

N = [2, ... 4]; gain = [6, ... -4]; centerFreq = [0.25, ... 0.75]; bandwidth = [0.12, ... 0.1];

Generate the filter coefficients using the specified parameters.

[B,A] = designParamEQ(N,gain,centerFreq,bandwidth,"Orientation","row");

Visualize your filter design.

fvtool([B,A]);

### Filter Audio Using SOS Parametric Equalizer

Design a second-order sections (SOS) parametric equalizer using `designParamEQ`

and filter an audio stream.

Create audio file reader and audio device writer System objects. Use the sample rate of the reader as the sample rate of the writer.

```
frameSize = 256;
fileReader = dsp.AudioFileReader("RockGuitar-16-44p1-stereo-72secs.wav",SamplesPerFrame=frameSize);
sampleRate = fileReader.SampleRate;
deviceWriter = audioDeviceWriter(SampleRate=sampleRate);
```

Play the audio signal through your device.

count = 0; while count < 2500 audio = fileReader(); deviceWriter(audio); count = count + 1; end reset(fileReader)

Design an SOS parametric equalizer suitable for use with `dsp.BiquadFilter`

.

N = [4,4]; gain = [-25,35]; centerFreq = [0.01,0.5]; bandwidth = [0.35,0.5]; [B,A] = designParamEQ(N,gain,centerFreq,bandwidth);

Visualize your filter design. Call `designParamEQ`

with the same design specifications. Specify the output orientation as `"row"`

so that it is suitable for use with `fvtool`

.

[Bvisualize,Avisualize] = designParamEQ(N,gain,centerFreq,bandwidth,Orientation="row"); fvtool([Bvisualize,Avisualize], ... Fs=fileReader.SampleRate, ... FrequencyScale="Log");

Create a biquad filter.

myFilter = dsp.BiquadFilter( ... SOSMatrixSource="Input port", ... ScaleValuesInputPort=false);

Create a spectrum analyzer to visualize the original audio signal and the audio signal passed through your parametric equalizer.

scope = spectrumAnalyzer( ... SampleRate=sampleRate, ... PlotAsTwoSidedSpectrum=false, ... FrequencyScale="log", ... Title="Original and Equalized Signals", ... ShowLegend=true, ... ChannelNames=["Original Signal","Equalized Signal"]);

Play the filtered audio signal and visualize the original and filtered spectrums.

count = 0; while count < 2500 originalSignal = fileReader(); equalizedSignal = myFilter(originalSignal,B,A); scope([originalSignal(:,1),equalizedSignal(:,1)]); deviceWriter(equalizedSignal); count = count + 1; end

As a best practice, release your objects once done.

release(deviceWriter) release(fileReader) release(scope)

### Filter Audio Using FOS Parametric Equalizer

Design a fourth-order sections (FOS) parametric equalizer using `designParamEQ`

and filter an audio stream.

Construct audio file reader and audio device writer System objects. Use the sample rate of the reader as the sample rate of the writer.

frameSize = 256; fileReader = dsp.AudioFileReader( ... "RockGuitar-16-44p1-stereo-72secs.wav", ... SamplesPerFrame=frameSize); sampleRate = fileReader.SampleRate; deviceWriter = audioDeviceWriter( ... SampleRate=sampleRate);

Play the audio signal through your device.

count = 0; while count < 2500 x = fileReader(); deviceWriter(x); count = count + 1; end reset(fileReader)

Design FOS parametric equalizer coefficients.

N = [2,4]; gain = [5,10]; centerFreq = [0.025,0.65]; bandwidth = [0.025,0.35]; mode = "fos"; [B,A] = designParamEQ(N,gain,centerFreq,bandwidth,mode,Orientation="row");

Construct FOS IIR filters.

myFilter = dsp.FourthOrderSectionFilter(B,A);

Visualize the frequency response of your parametric equalizer.

fvtool(myFilter)

Construct a spectrum analyzer to visualize the original audio signal and the audio signal passed through your parametric equalizer.

scope = spectrumAnalyzer( ... SampleRate=sampleRate, ... PlotAsTwoSidedSpectrum=false, ... FrequencyScale="log", ... Title="Original and Equalized Signals", ... ShowLegend=true, ... ChannelNames=["Original Signal","Equalized Signal"]);

Play the filtered audio signal and visualize the original and filtered spectra.

count = 0; while count < 2500 x = fileReader(); y = myFilter(x); scope([x(:,1),y(:,1)]); deviceWriter(y); count = count + 1; end

As a best practice, release your objects once done.

release(fileReader) release(deviceWriter) release(scope)

## Input Arguments

`N`

— Filter order

scalar | row vector

Filter order, specified as a scalar or row vector the same length
as `centerFreq`

. Elements of the vector must be even
integers.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`gain`

— Peak gain (dB)

scalar | row vector

Peak gain in dB, specified as a scalar or row vector the same
length as `centerFreq`

. Elements of the vector must
be real-valued.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`centerFreq`

— Normalized center frequency of equalizer bands

scalar | row vector

Normalized center frequency of equalizer bands, specified as
a scalar or row vector of real values in the range 0 to 1, where 1
corresponds to the Nyquist frequency (π rad/sample). If `centerFreq`

is
specified as a row vector, separate equalizers are designed for each
element of `centerFreq`

.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`bandwidth`

— Normalized bandwidth

scalar | row vector

Normalized bandwidth, specified as a scalar or row vector the
same length as `centerFreq`

. Elements of the vector
are specified as real values in the range 0 to 1, where 1 corresponds
to the Nyquist frequency (π rad/sample).

Normalized bandwidth is measured at gain/2 dB.
If gain is set to `-Inf`

(notch filter), normalized
bandwidth is measured at the 3 dB attenuation point: $$10\times {\mathrm{log}}_{10}\left(0.5\right)$$.

To convert octave bandwidth to normalized bandwidth, calculate
the associated *Q*-factor as

$$Q=\frac{\sqrt{{2}^{\left(octave\text{\hspace{0.17em}}bandwidth\right)}}}{{2}^{\left(octave\text{\hspace{0.17em}}bandwidth\right)}-1}\text{\hspace{0.17em}}.$$

Then convert to bandwidth

$$bandwidth=\frac{centerFreq}{Q}\text{\hspace{0.17em}}.$$

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`mode`

— Design mode

`'sos'`

(default) | `'fos'`

Design mode, specified as `'sos'`

or `'fos'`

.

`'sos'`

–– Implements your equalizer as cascaded second-order filters.`'fos'`

–– Implements your equalizer as cascaded fourth-order filters. Because fourth-order sections do not require the computation of roots, they are generally more computationally efficient.

**Data Types: **`char`

| `string`

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **`'Orientation',"row"`

`Orientation`

— Orientation of returned filter coefficients

`"column"`

(default) | `"row"`

Orientation of returned filter coefficients, specified as the
comma-separated pair consisting of `'Orientation'`

and
`"column"`

or `"row"`

:

Set

`'Orientation'`

to`"row"`

for interoperability with FVTool,`dsp.DynamicFilterVisualizer`

, and`dsp.FourthOrderSectionFilter`

.Set

`'Orientation'`

to`"column"`

for interoperability with`dsp.BiquadFilter`

.

**Data Types: **`char`

| `string`

## Output Arguments

`B`

— Numerator filter coefficients

matrix

Numerator filter coefficients, returned as a matrix. The size and interpretation of
`B`

depends on the `Orientation`

and `mode`

:

If

`'Orientation'`

is set to`"column"`

and`mode`

is set to`"sos"`

, then`B`

is returned as an*L*-by-3 matrix. Each column corresponds to the numerator coefficients of your cascaded second-order sections.If

`'Orientation'`

is set to`"column"`

and`mode`

is set to`"fos"`

, then`B`

is returned as an*L*-by-5 matrix. Each column corresponds to the numerator coefficients of your cascaded fourth-order sections.If

`'Orientation'`

is set to`"row"`

and`mode`

is set to`"sos"`

, then`B`

is returned as a 3-by-*L*matrix. Each row corresponds to the numerator coefficients of your cascaded second-order sections.If

`'Orientation'`

is set to`"row"`

and`mode`

is set to`"fos"`

, then`B`

is returned as a 5-by-*L*matrix. Each row corresponds to the numerator coefficients of your cascaded fourth-order sections.

`A`

— Denominator filter coefficients

matrix

Denominator filter coefficients, returned as a matrix. The size and interpretation of
`A`

depends on the `Orientation`

and `mode`

:

If

`'Orientation'`

is set to`"column"`

and`mode`

is set to`"sos"`

, then`A`

is returned as an*L*-by-2 matrix. Each column corresponds to the denominator coefficients of your cascaded second-order sections.`A`

does not include the leading unity coefficients.If

`'Orientation'`

is set to`"column"`

and`mode`

is set to`"fos"`

, then`A`

is returned as an*L*-by-4 matrix. Each column corresponds to the denominator coefficients of your cascaded fourth-order sections.`A`

does not include the leading unity coefficients.If

`'Orientation'`

is set to`"row"`

and`mode`

is set to`"sos"`

, then`A`

is returned as a 3-by-*L*matrix. Each row corresponds to the denominator coefficients of your cascaded second-order sections.If

`'Orientation'`

is set to`"row"`

and`mode`

is set to`"fos"`

, then`A`

is returned as a 5-by-*L*matrix. Each row corresponds to the denominator coefficients of your cascaded fourth-order sections.

## References

[1] Orfanidis, Sophocles J.
"High-Order Digital Parametric Equalizer Design." *Journal of the
Audio Engineering Society.* Vol. 53, November 2005, pp.
1026–1046.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

## Version History

**Introduced in R2016a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)