Professional Documents
Culture Documents
Table of Contents
Some Basic Designs ............................................................................................................ 1
Designs Based on Quality Factor ........................................................................................... 2
Low Shelf and High Shelf Filters .......................................................................................... 4
A Parametric Equalizer That Cuts .......................................................................................... 5
Cascading Parametric Equalizers ............................................................................................ 6
Advanced Design Options: Specifying Low and High Frequencies ............................................... 7
Shelving Filters with a Variable Transition Bandwidth or Slope .................................................. 8
Shelving Filters with a Prescribed Quality Factor .................................................................... 10
This example shows how to design parametric equalizer filters. Parametric equalizers are digital filters used in audio for
adjusting the frequency content of a sound signal. Parametric equalizers provide capabilities beyond those of graphic
equalizers by allowing the adjustment of gain, center frequency, and bandwidth of each filter. In contrast, graphic
equalizers only allow for the adjustment of the gain of each filter.
Typically, parametric equalizers are designed as second-order IIR filters. These filters have the drawback that because
of their low order, they can present relatively large ripple or transition regions and may overlap with each other when
several of them are connected in cascade. The DSP System Toolbox provides the capability to design high-order IIR
parametric equalizers. Such high-order designs provide much more control over the shape of each filter. In addition,
the designs special-case to traditional second-order parametric equalizers if the order of the filter is set to two.
This example discusses two separate approaches to parametric equalizer design. The first is using 'iirparameq' and the
second is using 'fdesign.parameq'. 'iirparameq' should serve most needs. It is simpler and provides the ability for most
common designs. It also supports C code generation which is needed if there is a desire to tune the filter at run-time
with generated code. 'fdesign.parameq' provides many advanced design options for ultimate control of the resulting
filter. Not all design options are explored in this example.
One of the design parameters is the filter bandwidth, BW. In the previous example, the bandwidth was
specified as 4 kHz. The 4 kHz bandwidth occurs at the point the two filters intersect (roughly 3.18 dB).
In general, the bandwidth is met at the arithmetic mean between the squared magnitude of the gain of the
filter and one. This value can be computed analytically as follows
Gsq = 10.^(G/10); % Magnitude squared of filter; G = 5 dB
GBW = 10*log10((Gsq + 1)/2) % 3.183 dB
GBW =
3.1830
Although a higher Q factor corresponds to a sharper filter, it must also be noted that for a given bandwidth,
the Q factor increases simply by increasing the center frequency. This might seem unintuitive. For example,
the following two filters have the same Q factor, but one clearly occupies a larger bandwidth than the other.
Fs = 48e3;
N
= 2;
Q
= 10;
G
= 9; % 9 dB
Wo1 = 2000/(Fs/2);
Wo2 = 12000/(Fs/2);
BW1 = Wo1/Q; % Bandwidth occurs at 6.5 dB in this case
BW2 = Wo2/Q; % Bandwidth occurs at 6.5 dB in this case
[SOS1,SV1] = iirparameq(N,G,Wo1,BW1);
[SOS2,SV2] = iirparameq(N,G,Wo2,BW2);
BQ1 = dsp.BiquadFilter('SOSMatrix',SOS1,'ScaleValues',SV1);
BQ2 = dsp.BiquadFilter('SOSMatrix',SOS2,'ScaleValues',SV2);
hfvt = fvtool(BQ1,BQ2,'Fs',Fs,'Color','white');
legend(hfvt,'BW1 = 200 Hz; Q = 10','BW2 = 1200 Hz; Q = 10');
When viewed on a log-frequency scale though, the "octave bandwidth" of the two filters is the same (about
0.1 octaves in this example).
hfvt = fvtool(BQ1,BQ2,'FrequencyScale','log','Fs',Fs,'Color','white');
At the limit, the filter can be designed to have a gain of zero (-Inf dB) at the frequency specified. This
allows to design 2nd order or higher order notch filters.
Fs = 44.1e3;
N
= 8;
G
= -inf;
Q
= 1.8;
Wo = 60/(Fs/2); % Notch at 60 Hz
BW = Wo/Q; % Bandwidth will occur at -3 dB for this special case
[SOS1,SV1] = iirparameq(N,G,Wo,BW);
[NUM,DEN] = iirnotch(Wo,BW); % or [SOS2,SV2] = iirparameq(2,G,Wo,BW);
SOS2 = [NUM,DEN];
BQ1 = dsp.BiquadFilter('SOSMatrix',SOS1,'ScaleValues',SV1);
BQ2 = dsp.BiquadFilter('SOSMatrix',SOS2);
hfvt = fvtool(BQ1,BQ2,'Fs',Fs,'FrequencyScale','Log','Color','white');
legend(hfvt,'8th order notch filter','2nd order notch filter');
Low-order designs such as the second-order filters above can interfere with each other if their center
frequencies are closely spaced. In the example above, the filter centered at 1 kHz was supposed to have a
gain of -2 dB. Due to the interference from the other filter, the actual gain is more like -1 dB. Higher-order
designs are less prone to such interference.
Fs = 48e3;
N
= 8;
G1 = 3; % 3 dB
G2 = -2; % -2 dB
Wo1 = 400/(Fs/2);
Wo2 = 1000/(Fs/2);
BW = 500/(Fs/2); % Bandwidth occurs at 7.4 dB in this case
[SOS1,SV1] = iirparameq(N,G1,Wo1,BW);
[SOS2,SV2] = iirparameq(N,G2,Wo2,BW);
BQ1a = dsp.BiquadFilter('SOSMatrix',SOS1,'ScaleValues',SV1);
BQ2a = dsp.BiquadFilter('SOSMatrix',SOS2,'ScaleValues',SV2);
FC2 = dsp.FilterCascade(BQ1a,BQ2a);
hfvt = fvtool(FC,FC2,'Fs',Fs,'Color','white','FrequencyScale','Log');
legend(hfvt,'Cascade of 2nd order filters','Cascade of 8th order
filters');
=
=
=
=
=
=
=
=
=
44.1e3;
4;
3000;
4000;
1;
10*log10(Grsq);
-8;
10.^(G/10); % Magnitude squared of filter; G = 5 dB
10*log10((Gsq + Grsq)/2); % Flow and Fhigh occur at -2.37 dB
PEQ = fdesign.parameq('N,Flow,Fhigh,Gref,G0,GBW',...
N,Flow/(Fs/2),Fhigh/(Fs/2),Gref,G,GBW);
BQ = design(PEQ,'SystemObject',true);
hfvt = fvtool(BQ,'Fs',Fs,'Color','white');
legend(hfvt,'Equalizer with Flow = 3 kHz and Fhigh = 4 kHz');
Notice that the filter has a gain of -2.37 dB at 3 kHz and 4 kHz as specified.
The transition bandwidth and the bandwidth gain corresponding to each value of S can be obtained using
the measure function. We verify that the bandwidth reference gain GBW is the same for the three designs
and we quantify by how much the transition width decreases when S increases.
m1 = measure(BQ1);
get(m1,'GBW')
m2 = measure(BQ2);
get(m2,'GBW')
m3 = measure(BQ3);
get(m3,'GBW')
ans =
5
ans =
5
ans =
5
get(m1,'HighTransitionWidth')
get(m2,'HighTransitionWidth')
get(m3,'HighTransitionWidth')
ans =
0.0945
ans =
0.0425
ans =
0.0238
As the shelf slope parameter S increases, the ripple of the filters also increases. We can increase the filter
order to reduce the ripple while maintaining the desired transition bandwidth.
N
= 2;
PEQ = fdesign.parameq('N,F0,Fc,S,G0',N,Fo,Fc,S,G);
BQ1 = design(PEQ,'SystemObject',true);
PEQ.FilterOrder = 3;
BQ2 = design(PEQ,'SystemObject',true);
PEQ.FilterOrder = 4;
BQ3 = design(PEQ,'SystemObject',true);
hfvt = fvtool(BQ1,BQ2,BQ3,'Fs',Fs,'Color','white');
legend(hfvt,'N=2','N=3','N=4');
10
PEQ = fdesign.parameq('N,F0,Fc,Qa,G0',N,Fo,Fc,Q,G);
BQ1 = design(PEQ,'SystemObject',true);
PEQ.Qa = 1/sqrt(2);
BQ2 = design(PEQ,'SystemObject',true);
PEQ.Qa = 2.0222;
BQ3 = design(PEQ,'SystemObject',true);
hfvt = fvtool(BQ1,BQ2,BQ3,'Fs',Fs,'Color','white');
legend(hfvt,'Qa=0.48','Qa=0.7071','Qa=2.0222');
11