Not a member?

# Peak/Notch Filter Design

Language: Matlab

Processor: Not Relevant

Submitted by on May 21 2011

# Peak/Notch Filter Design

This function will generate the coefficients for a single IIR biquad that is a "peak/notch" design.  Wierldy enough, this filter type is not part of the standard Matlab filter design toolbox.  These filters are commonly used is audio signal processing to create a graphic equalizer.

For example, you may remember cassette tape players that had 5 or 10 sliders all with different frequencies to equalize the sound.  Each one of those knobs represented one of these biquad types.  The Center Frequency(Fc) and shape(Q) would be fixed and the knob was attached to the gain (G) parameter.  If the gain is a positive dB it is said to be a peak filter and a negative dB is a notch.

See plots below to see what the magnitude response looks like:

function [b, a]  = peaking(G, fc, Q, fs)

% Derive coefficients for a peaking filter with a given amplitude and
% bandwidth.  All coefficients are calculated as described in Zolzer's
% DAFX book (p. 50 - 55).  This algorithm assumes a constant Q-term
% is used through the equation.
%
% Usage:     [B,A] = peaking(G, Fc, Q, Fs);
%
%            G is the logrithmic gain (in dB)
%            FC is the center frequency
%            Q is Q-term equating to (Fb / Fc)
%            Fs is the sampling rate
%
% Author:    sparafucile17 08/22/05
%

K = tan((pi * fc)/fs);
V0 = 10^(G/20);

%Invert gain if a cut
if(V0 < 1)
V0 = 1/V0;
end

%%%%%%%%%%%%%%
%   BOOST
%%%%%%%%%%%%%%
if( G > 0 )

b0 = (1 + ((V0/Q)*K) + K^2) / (1 + ((1/Q)*K) + K^2);
b1 =        (2 * (K^2 - 1)) / (1 + ((1/Q)*K) + K^2);
b2 = (1 - ((V0/Q)*K) + K^2) / (1 + ((1/Q)*K) + K^2);
a1 = b1;
a2 =  (1 - ((1/Q)*K) + K^2) / (1 + ((1/Q)*K) + K^2);

%%%%%%%%%%%%%%
%    CUT
%%%%%%%%%%%%%%
else

b0 = (1 + ((1/Q)*K) + K^2) / (1 + ((V0/Q)*K) + K^2);
b1 =       (2 * (K^2 - 1)) / (1 + ((V0/Q)*K) + K^2);
b2 = (1 - ((1/Q)*K) + K^2) / (1 + ((V0/Q)*K) + K^2);
a1 = b1;
a2 = (1 - ((V0/Q)*K) + K^2) / (1 + ((V0/Q)*K) + K^2);

end

%return values
a = [  1, a1, a2];
b = [ b0, b1, b2];

Rate this code snippet:
0

posted by

# fresha wrote:

9/14/2012

Found a slight 'hiccup' with your maths on the 'cut' formulas (the V0/Q should be 1/(V0/Q)... based on the  DAFX book, they should read..

%%%%%%%%%%%%%%
%    CUT
%%%%%%%%%%%%%%
else
b0 = (1 + ((1/Q)*K) + K^2) / (1 + ((1(V0/Q))*K) + K^2);
b1 =       (2 * (K^2 - 1)) / (1 + ((1(V0/Q))*K) + K^2);
b2 = (1 - ((1/Q)*K) + K^2) / (1 + ((1(V0/Q))*K) + K^2);
a1 = b1;
a2 = (1 - ((V0/Q)*K) + K^2) / (1 + ((1(V0/Q))*K) + K^2);

# fresha wrote:

9/14/2012

actual just seen the way you just worked it back... my error.. found the V0 < 1 then 1/V0

ok looks like I need to find why my filter 'shifts' in a different way... :D

# fresha wrote:

9/14/2012

yep reworked in Excel, your code works right way for sure... *gracefully bows*

I stand corrected.....

and my cut divisor should have read:
(1 + ((1/(V0 * Q))*K) + K^2);
to match the book calc (doing fixed prior calcs to be more efficient opposed to calcing all the time)