Main Content

designShelvingEQ

设计shelving equalizer

Description

example

[B,A] = designShelvingEQ(gain,slope,Fc)designs a low-shelf equalizer with the specifiedgain,slope, and cutoff frequencyFc.BandAare the numerator and denominator coefficients, respectively, of a single second-order section (biquad) IIR filter.

example

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

example

[B,A] = designShelvingEQ(___,Orientation=ornt)specifies the orientation of the returned filter coefficients as"column"or"row".

Examples

collapse all

Create audio file reader and audio device writer 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); deviceWriter = audioDeviceWriter(SampleRate=fileReader.SampleRate);

Play the audio signal through your device.

count = 0;whilecount < 2500 audio = step(fileReader); play(deviceWriter,audio); count = count + 1;endreset(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 shelving filter design.

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

Figure Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains an object of type line.

Create a biquad filter object.

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

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

scope = dsp.SpectrumAnalyzer(...SampleRate=fileReader.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.

count = 0;whilecount < 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(fileReader) release(deviceWriter) release(scope)

Figure Spectrum Analyzer contains an axes object and other objects of type uiflowcontainer, uimenu, uitoolbar. The axes object with title Original and Equalized Signal contains 2 objects of type line. These objects represent Original Signal, Equalized Signal.

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

Specify sample rate, peak gain, slope coefficient, and normalized cutoff frequency for the three shelving equalizers. The sample rate 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",Orientation="row"); [B2,A2] = designShelvingEQ(gain2,slope,Fc,"hi",Orientation="row"); [B3,A3] = designShelvingEQ(gain3,slope,Fc,"hi",Orientation="row");

Visualize your filter design.

fvt = fvtool([B1,A1;[1 0 0 1 0 0]],...[B2,A2;[1 0 0 1 0 0]],...[B3,A3;[1 0 0 1 0 0]],...Fs=Fs); legend(fvt,"gain = "+[gain1 gain2 gain3]+" dB",Location="northwest")

Figure Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains 3 objects of type line. These objects represent gain = -6 dB, gain = 6 dB, gain = 12 dB.

Design three second-order IIR low-shelf equalizers usingdesignShelvingEQ. 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,Orientation="row"); [B2,A2] = designShelvingEQ(gain,slope2,Fc,Orientation="row"); [B3,A3] = designShelvingEQ(gain,slope3,Fc,Orientation="row");

Visualize your filter design.

fvt = fvtool(...dsp.BiquadFilter([B1,A1]),...dsp.BiquadFilter([B2,A2]),...dsp.BiquadFilter([B3,A3]),...Fs=Fs,...FrequencyScale="log"); legend(fvt,"slope = 0.5","slope = 0.75","slope = 1")

Figure Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains 3 objects of type line. These objects represent slope = 0.5, slope = 0.75, slope = 1.

Input Arguments

collapse all

Peak gain in dB, specified as a real scalar.

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

Slope coefficient, specified as a positive scalar.

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

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

Normalized cutoff frequency is implemented as half the shelving filter gain, orgain/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

Orientation of returned filter coefficients, specified as"column"or"row".

Data Types:char|string

Output Arguments

collapse all

Numerator filter coefficients, returned as a vector. The size and interpretation ofBdepend on the orientation,ornt:

  • Iforntis set to"column", thenBis returned as a three-element column vector.

  • Iforntis set to"row", thenBis returned as a three-element row vector.

.

Denominator filter coefficients of the designed second-order IIR filter, returned as a vector. The size and interpretation ofAdepend on the orientation,ornt:

  • Iforntis set to"column", thenAis returned as a two-element column vector.Adoes not include the leading unity coefficient.

  • Iforntis set to"row", thenAis returned as a three-element row vector.

References

[1] Bristow-Johnson, Robert. "Cookbook Formulae for Audio EQ Biquad Filter Coefficients." Accessed September 13, 2021.https://webaudio.github.io/Audio-EQ-Cookbook/Audio-EQ-Cookbook.txt.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2016a