Documentation

# designParamEQ

Design parametric equalizer

## Syntax

``````[B,A] = designParamEQ(N,gain,centerFreq,bandwidth)``````
``````[B,A] = designParamEQ(N,gain,centerFreq,bandwidth,mode)``````

## Description

example

``````[B,A] = designParamEQ(N,gain,centerFreq,bandwidth)``` designs an `N`th-order parametric equalizer with specified gain, center frequency, and bandwidth. `B` and `A` are matrices of numerator and denominator coefficients, with columns corresponding to cascaded second-order section (SOS) filters. ```

example

``````[B,A] = designParamEQ(N,gain,centerFreq,bandwidth,mode)``` specifies whether the parametric equalizer is implemented with second-order sections or fourth-order sections (FOS).```

## Examples

collapse all

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.10];```

Generate the filter coefficients using the specified parameters.

`[B,A] = designParamEQ(N,gain,centerFreq,bandwidth);`

Create a filter matrix compatible with `fvtool`.

`SOS = [B',[ones(sum(N)/2,1),A']];`

Visualize your filter design.

`fvtool(SOS)`

Design a second-order sections (SOS) 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. Call `setup` to reduce the computational load of initialization in an audio stream loop.

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

Play the audio signal through your device.

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

Design a SOS parametric equalizer.

```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.

```SOS = [B',[ones(4,1),A']]; fvtool(SOS,... 'Fs',fileReader.SampleRate,... 'FrequencyScale','Log');```

Construct a biquad filter System object.

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

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

```scope = dsp.SpectrumAnalyzer(... 'SampleRate',sampleRate,... 'PlotAsTwoSidedSpectrum',false,... 'FrequencyScale','Log',... 'FrequencyResolutionMethod','WindowLength',... 'WindowLength',frameSize,... 'Title','Original and Equalized Signals',... 'ShowLegend',true,... 'ChannelNames',{'Original Signal','Equalized Signal'});```

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

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

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. Call `setup` to reduce the computational load of initialization in an audio stream loop.

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

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);```

Construct FOS IIR filters.

```section1 = dsp.IIRFilter('Numerator',B(:,1)','Denominator',[1,A(:,1)']); section2 = dsp.IIRFilter('Numerator',B(:,2)','Denominator',[1,A(:,2)']);```

Visualize the frequency response of your parametric equalizer.

```[H1,w] = freqz(section1,8192,sampleRate); H2 = freqz(section2,8192,sampleRate); H = 20.*log10(abs(H1.*H2)); semilogx(w,H); title('Magnitude Response (dB)') xlabel('Frequency (Hz)') ylabel('Magnitude (dB)') grid on```

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

```scope = dsp.SpectrumAnalyzer(... 'SampleRate',sampleRate,... 'PlotAsTwoSidedSpectrum',false,... 'FrequencyScale','Log',... 'FrequencyResolutionMethod','WindowLength',... 'WindowLength',frameSize,... 'Title','Original and Equalized Signals',... 'ShowLegend',true,... 'ChannelNames',{'Original Signal','Equalized Signal'});```

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

```setup(scope,ones(frameSize,2)); count = 0; while count < 2500 x = fileReader(); y = section1(x); z = section2(y); scope([x(:,1),z(:,1)]); deviceWriter(z); count = count + 1; end release(fileReader) release(deviceWriter) release(scope)```

## Input Arguments

collapse all

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`

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`

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`

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×{\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`

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`

## Output Arguments

collapse all

Numerator filter coefficients, returned as a matrix. Each column of `B` corresponds to the numerator coefficients of a different second-order or fourth-order section of your cascaded equalizer.

Denominator filter coefficients, returned as a matrix. Each column of `A` corresponds to the denominator coefficients of a different second-order or fourth-order section of your cascaded equalizer.

`A` does not include the leading unity coefficient for each section.

Get trial now