DSPRelated.com
Code

Peak/Notch Filter Design

Jeff T May 21, 20113 comments Coded in Matlab

This function will generate the coefficients for a single IIR biquad that is a "peak/notch" design.  Weirldy 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:

Magnitude Response of Peak/Notch Filters

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];