Documentation

# designShelvingEQ

Design shelving equalizer

## Syntax

``````[B,A] = designShelvingEQ(gain,slope,Fc)``````
``````[B,A] = designShelvingEQ(gain,slope,Fc,type)``````

## Description

example

``````[B,A] = designShelvingEQ(gain,slope,Fc)``` designs a low-shelf equalizer with the specified gain, slope, and cutoff frequency, `Fc`. The equalizer is returned as cascaded second-order section (SOS) IIR filters.```

example

``````[B,A] = designShelvingEQ(gain,slope,Fc,type)``` specifies the design type as a low-shelving or high-shelving equalizer.```

## Examples

collapse all

Design three second-order IIR low-shelf equalizers using `designShelvingEQ`. The three shelving equalizers use three separate slope specifications.

Specify sampling frequency, peak gain, slope coefficient, and normalized cutoff frequency for three shelving equalizers. The sampling frequency is in Hz. The peak gain is in dB.

```Fs = 44.1e3; gain = 5; slope1 = 0.5; slope2 = 0.75; slope3 = 1; Fc = 1000/(Fs/2);```

Design the filter coefficients using the specified parameters.

```[B1,A1] = designShelvingEQ(gain,slope1,Fc); [B2,A2] = designShelvingEQ(gain,slope2,Fc); [B3,A3] = designShelvingEQ(gain,slope3,Fc);```

Create filter matrices compatible with `fvtool`.

```SOS1 = [B1',[1,A1']]; SOS2 = [B2',[1,A2']]; SOS3 = [B3',[1,A3']];```

Visualize your filter design.

```fvtool(... dsp.BiquadFilter('SOSMatrix',SOS1),... dsp.BiquadFilter('SOSMatrix',SOS2),... dsp.BiquadFilter('SOSMatrix',SOS3),... 'Fs',Fs,... 'FrequencyScale','Log'); legend('slope = 0.1',... 'slope = 0.5',... 'slope = 1');```

Design a low-shelf equalizer, and then use it to filter an audio signal.

Construct audio file reader and audio device writer 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 = step(fileReader); play(deviceWriter,audio); count = count+1; end reset(fileReader)```

Design a second-order sections (SOS) low-shelf equalizer.

```gain = 10; slope = 3; Fc = 0.025; [B,A] = designShelvingEQ(gain,slope,Fc);```

Visualize your equalizer design.

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

Construct a biquad filter object.

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

Construct a spectrum analyzer object to visualize the original audio signal and the audio signal passed through your low-shelf equalizer.

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

Play the equalized audio signal and visualize the original and equalized 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(fileReader) release(scope) release(deviceWriter)```

Design three second-order IIR high shelf equalizers using `designShelvingEQ`. The three shelving equalizers use three separate gain specifications.

Specify sampling frequency, peak gain, slope coefficient, and normalized cutoff frequency for three shelving equalizers. The sampling frequency is in Hz. The peak gain is in dB.

```Fs = 44.1e3; gain1 = -6; gain2 = 6; gain3 = 12; slope = 0.8; Fc = 18000/(Fs/2);```

Design the filter coefficients using the specified parameters.

```[B1,A1] = designShelvingEQ(gain1,slope,Fc,'hi'); [B2,A2] = designShelvingEQ(gain2,slope,Fc,'hi'); [B3,A3] = designShelvingEQ(gain3,slope,Fc,'hi');```

Create filter matrices compatible with `fvtool`.

```SOS1 = [B1',[1,A1']]; SOS2 = [B2',[1,A2']]; SOS3 = [B3',[1,A3']];```

Visualize your filter design.

```fvtool(dsp.BiquadFilter('SOSMatrix',SOS1),... dsp.BiquadFilter('SOSMatrix',SOS2),... dsp.BiquadFilter('SOSMatrix',SOS3),... 'Fs',Fs); legend('gain = -6 dB',... 'gain = 6 dB',... 'gain = 12 dB',... 'Location','NorthWest')``` ## Input Arguments

collapse all

Peak gain in dB, specified as a real scalar in the range –12 to 12.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Slope coefficient, specified as a real scalar in the range 0 to 5.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Normalized cutoff frequency, specified as a real scalar in the range 0 to 1, where 1 corresponds to the Nyquist frequency (π rad/sample).

Normalized cutoff frequency is implemented as half the shelving filter gain, or `gain`/2 dB.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Filter type, specified as `'lo'` or `'hi'`.

• `'lo'`–– Low shelving equalizer

• `'hi'`–– High shelving equalizer

Data Types: `char` | `string`

## Output Arguments

collapse all

Numerator filter coefficients of the designed second-order IIR filter, retuned as a three-element column vector.

Denominator filter coefficients of the designed second-order IIR filter, returned as a two-element column vector. `A` does not include the leading unity coefficient.

## See Also

### Topics

#### Introduced in R2016a

##### Support Get trial now