parametric equalizer design -凯发k8网页登录
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. audio 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 uses designparameq
. it is a simple function that provides support for the 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.
some basic designs
consider the following two designs of parametric equalizers. the design specifications are the same except for the filter order. the first design is a typical second-order parametric equalizer that boosts the signal around 10 khz by 5 db. the second design does the same with a sixth-order filter. notice how the sixth-order filter is closer to an ideal brickwall filter when compared to the second-order design. obviously the approximation can be improved by increasing the filter order even further. the price to pay for such improved approximation is increased implementation cost as more multipliers are required.
fs = 48e3; n1 = 2; n2 = 6; g = 5; % 5 db wo = 10000/(fs/2); bw = 4000/(fs/2); [b1,a1] = designparameq(n1,g,wo,bw,'orientation','row'); [b2,a2] = designparameq(n2,g,wo,bw,'orientation','row'); bq1 = dsp.sosfilter('numerator',b1,'denominator',a1); bq2 = dsp.sosfilter('numerator',b2,'denominator',a2); hfvt = fvtool(bq1,bq2,'fs',fs,'color','white'); legend(hfvt,'2nd-order design','6th-order design');
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 half the gain (2.5 db).
designs based on quality factor
another common design parameter is the quality factor, q. the q of the filter is defined as wo/bw (center frequency/bandwidth). it provides a measure of the sharpness of the filter, i.e., how sharply the filter transitions between the reference value (0 db) and the gain g. consider two designs with same g and wo, but different q values.
fs = 48e3; n = 2; q1 = 1.5; q2 = 10; g = 15; % 15 db wo = 6000/(fs/2); bw1 = wo/q1; bw2 = wo/q2; [b1,a1] = designparameq(n,g,wo,bw1,'orientation','row'); [b2,a2] = designparameq(n,g,wo,bw2,'orientation','row'); bq1 = dsp.sosfilter('numerator',b1,'denominator',a1); bq2 = dsp.sosfilter('numerator',b2,'denominator',a2); hfvt = fvtool(bq1,bq2,'fs',fs,'color','white'); legend(hfvt,'q = 1.5','q = 10');
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; bw2 = wo2/q; [b1,a1] = designparameq(n,g,wo1,bw1,'orientation','row'); [b2,a2] = designparameq(n,g,wo2,bw2,'orientation','row'); bq1 = dsp.sosfilter('numerator',b1,'denominator',a1); bq2 = dsp.sosfilter('numerator',b2,'denominator',a2); 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.
hfvt = fvtool(bq1,bq2,'frequencyscale','log','fs',fs,'color','white'); legend(hfvt,'fo1 = 2 khz','fo2 = 12 khz');
low shelf and high shelf filters
the filter's bandwidth bw is only perfectly centered around the center frequency wo when such frequency is set to 0.5*pi (half the nyquist rate). when wo is closer to 0 or to pi, there is a warping effect that makes a larger portion of the bandwidth to occur at one side of the center frequency. in the edge cases, if the center frequency is set to 0 (pi), the entire bandwidth of the filter occurs to the right (left) of the center frequency. the result is a so-called shelving low (high) filter.
fs = 48e3; n = 4; g = 10; % 10 db wo1 = 0; wo2 = 1; % corresponds to fs/2 (hz) or pi (rad/sample) bw = 1000/(fs/2); % bandwidth occurs at 7.4 db in this case [b1,a1] = designparameq(n,g,wo1,bw,'orientation','row'); [b2,a2] = designparameq(n,g,wo2,bw,'orientation','row'); bq1 = dsp.sosfilter('numerator',b1,'denominator',a1); bq2 = dsp.sosfilter('numerator',b2,'denominator',a2); hfvt = fvtool(bq1,bq2,'fs',fs,'color','white'); legend(hfvt,'low shelf filter','high shelf filter');
a parametric equalizer that cuts
all previous designs are examples of a parametric equalizer that boosts the signal over a certain frequency band. you can also design equalizers that cut (attenuate) the signal in a given region.
fs = 48e3; n = 2; g = -5; % -5 db wo = 6000/(fs/2); bw = 2000/(fs/2); [b,a] = designparameq(n,g,wo,bw,'orientation','row'); bq = dsp.sosfilter('numerator',b,'denominator',a); hfvt = fvtool(bq,'fs',fs,'color','white'); legend(hfvt,'g = -5 db');
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 [b1,a1] = designparameq(n,g,wo,bw,'orientation','row'); [num,den] = iirnotch(wo,bw); % or [num,den] = designparameq(2,g,wo,bw); bq1 = dsp.sosfilter('numerator',b1,'denominator',a1); bq2 = dsp.sosfilter('numerator',num,'denominator',den); hfvt = fvtool(bq1,bq2,'fs',fs,'frequencyscale','log','color','white'); legend(hfvt,'8th order notch filter','2nd order notch filter');
cascading parametric equalizers
parametric equalizers are usually connected in cascade (in series) so that several are used simultaneously to equalize an audio signal. to connect several equalizers in this way, use the dsp.filtercascade
.
fs = 48e3; n = 2; 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 [b1,a1] = designparameq(n,g1,wo1,bw,'orientation','row'); [b2,a2] = designparameq(n,g2,wo2,bw,'orientation','row'); bq1 = dsp.sosfilter('numerator',b1,'denominator',a1); bq2 = dsp.sosfilter('numerator',b2,'denominator',a2); fc = dsp.filtercascade(bq1,bq2); hfvt = fvtool(fc,'fs',fs,'color','white','frequencyscale','log'); legend(hfvt,'cascade of 2nd order filters');
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 [b1,a1] = designparameq(n,g1,wo1,bw,'orientation','row'); [b2,a2] = designparameq(n,g2,wo2,bw,'orientation','row'); bq1a = dsp.sosfilter('numerator',b1,'denominator',a1); bq2a = dsp.sosfilter('numerator',b2,'denominator',a2); 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');