designShelvingEQ
Design shelving equalizer
Syntax
Description
Examples
Filter Audio Using Low-Shelf Equalizer
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; 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,Orientation="row");
Visualize your shelving filter design.
freqz(B,A,512,fileReader.SampleRate)
Create an SOS filter object.
myFilter = dsp.SOSFilter(B,A);
Create a spectrum analyzer object to visualize the original audio signal and the audio signal passed through your low-shelf equalizer.
scope = spectrumAnalyzer( ... SampleRate=fileReader.SampleRate, ... PlotAsTwoSidedSpectrum=false, ... FrequencyScale="log", ... 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; while count < 2500 originalSignal = fileReader(); equalizedSignal = myFilter(originalSignal); 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)
Design High-Shelf Equalizer
Design three second-order IIR high shelf equalizers using designShelvingEQ
. 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.
filterAnalyzer(B1,A1,B2,A2,B3,A3,SampleRates=Fs)
Design Low-Shelf Equalizer
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,Orientation="row"); [B2,A2] = designShelvingEQ(gain,slope2,Fc,Orientation="row"); [B3,A3] = designShelvingEQ(gain,slope3,Fc,Orientation="row");
Visualize your filter designs.
freqz(B1,A1,512,Fs)
freqz(B2,A2,512,Fs)
freqz(B3,A3,512,Fs)
Input Arguments
gain
— Peak gain (dB)
real scalar
Peak gain in dB, specified as a real scalar.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
slope
— Slope coefficient
positive scalar
Slope coefficient, specified as a positive scalar.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Fc
— Normalized cutoff frequency
real scalar in the range [0, 1]
Normalized cutoff frequency, specified as a real scalar in the range
[0, 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
type
— Filter type
"lo"
(default) | 'hi'
Filter type, specified as "lo"
or
"hi"
.
"lo"
–– Low shelving equalizer"hi"
–– High shelving equalizer
Data Types: char
| string
ornt
— Orientation of returned filter coefficients
"column"
(default) | "row"
Orientation of returned filter coefficients, specified as
"column"
or "row"
.
Data Types: char
| string
Output Arguments
B
— Numerator filter coefficients
three-element column vector | three-element row vector
Numerator filter coefficients, returned as a vector. The size and
interpretation of B
depend on the orientation,
ornt
:
If
ornt
is set to"column"
, thenB
is returned as a three-element column vector.If
ornt
is set to"row"
, thenB
is returned as a three-element row vector.
.
A
— Denominator filter coefficients
two-element column vector | three-element row vector
Denominator filter coefficients of the designed second-order IIR filter, returned as a vector.
The size and interpretation of A
depend on the
orientation, ornt
:
If
ornt
is set to"column"
, thenA
is returned as a two-element column vector.A
does not include the leading unity coefficient.If
ornt
is set to"row"
, thenA
is 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 R2016aR2024b: Warning that filter design functions will return coefficients in row orientation by default
The designVarSlopeFilter
, designParamEQ
, and designShelvingEQ
functions will
return filter coefficients in row orientation by default in a future release. With
row orientation, the functions return the coefficients as matrices where each row
contains the coefficients of the corresponding second-order section of the
filter.
The default value of the Orientation
name-value argument,
"column"
, will be removed in a future release and throws a
warning in R2024b. Set Orientation
to "row"
to return coefficients in row orientation in the current release.
R2024a: Filter design functions will return coefficients in row orientation by default
The designVarSlopeFilter
, designParamEQ
, and designShelvingEQ
functions will
return filter coefficients in row orientation by default in a future release.
See Also
Blocks
Objects
Functions
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)