First Order Digital Filters - Audio Cookbook
First Order Digital Filters - Audio Cookbook
Design notes
Even though the expressions used to compute the coefficients
Shelf (bass, treble) are quite simple, the computation should be mechanized if more
The shelf filter utilizes both feed forward and feed back sec- than a few curves are required. I used Matlab, creating multiple
tions. If f1 < f2, output falls from higher to lower level with in- files, one for each of the graphs seen here (the file names are
creasing frequency, and response is suitable for bass boost or shown in parantheses), but MathCAD or even a spreadsheet
treble cut. If f2 < f1, output rises from lower to higher level with could also be used.
increasing frequency, and response is suitable for bass cut or
treble boost. Shelf level difference is dB(f1/f2). In the bass and
Example Matlab file, TREB_BC.M In conclusion—
%TREB_BC.M Creates treble control with corner fre-
Although I’ve presented a variety of equalization and filter
quency at 1kHz and sweeps from -20dB to +20dB in 20 curves here, the world of first order filters offers still more pos-
steps sibilities. The zero and the pole each can be located in two pos-
%
% revision date: March 3, 2001 sible regions: between zero and +1 (DC), and between zero and
% -1 (Nyquist frequency). This gives four possible combinations,
% constants
Fs=44100; % sampling rate
and, since there are an infinite number of possible locations,
t=1/Fs; % sampling interval many more curves are possible.
Fn=Fs/2; % Nyquist frequency
minF=10; % minimum frequency of analysis Acknowledgements
maxF=Fs/2; % maximum frequency of analysis I would like to thank the reviewers of this application note for
numPts=256; % number of points of analysis
% their helpful suggestions--Professor Douglas Preis, Tufts Uni-
% create array of frequencies to use for freqz versity; Erik Anderson; Dave Tweed; and Roman Litovsky.
Farray=logspace(log10(minF),log10(maxF),numPts);
%
% create arrays of frequencies in Hz to use for
sweeping the treble control
Bibliography
Fcarray1=[ 1000 1258 1584 1995 2512 3162 3981 5011 Ham, P. A. L. “Simple Digital Filters,” Wireless World, July
6310 7943 10000 1000 1000 1000 1000 1000 1000
1000 1000 1000 1000 ]; 1978, p 83-87.
Fcarray2=[ 1000 1000 1000 1000 1000 1000 1000 1000 McClellan, James H., Shaver, Ronald W., and Yoder, Mark A.
1000 1000 1000 1258 1584 1995 2512 3162 3981
5011 6310 7943 10000 ]; DSP First: A Multimedia Approach, Prentice Hall, NJ, 1998.
%
clf; % clear graph
Mitra, Sanjit K. Digital Signal Processing--A Computer-Based
for A_index = 1: 21 % plot 21 times for 2dB steps Approach, McGraw-Hill, New York, 1998.
of boost and cut over +/- 20dB range
% Orfanidis, Sophocles J. Introduction to Signal Processing,
title ('treb_bc.m'); % do every iteration to get Prentice Hall, NJ, 1996.
correct appearance
xlabel ('frequency Hz');
ylabel ('amplitude dB');
axis([minF maxF -20 20 ]);
grid on;
%
f2=Fcarray2(A_index); % numerator (zero) freq
f1=Fcarray1(A_index); % denominator (pole) freq
%
%-------------------------------------------------
% compute the digital filter coefficients
% Mission statement of Seven Woods Audio
L1= exp(-pi*f2/Fn); % numerator
K1= exp(-pi*f1/Fn); % denominator I am an electrical engineering consultant specializing in the con-
% ception and design of products and circuits used in audio appli-
b1=-1, %numerator coefficient X(n)
b2= L1, %numerator coefficient X(n-1)
cations. My company, Seven Woods Audio, is committed to
a1= 1, %denominator coefficient Y(n) helping manufacturers quickly create digital or analog audio
a2= K1, %denominator coefficient Y(n-1) products that generate a good return on investment, work right
normalize=(1-a2)/(b1+b2); % normalize to AV=0dB at
DC the first time, sound excellent, and please the end user. Seven
b1=normalize*b1; Woods Audio works with manufacturers of professional audio,
b2=normalize*b2; consumer audio, broadcast, telecommunications, and computer
%
%define numerator and denominator of transfer func- equipment.
tion
num=[ b1 b2 ], den=[ a1 -a2 ],
% num=[ Xn Xn-1 ], den=[ Yn Yn-1 ], rev: March 3, 2001 Copyright 2001. All rights reserved.
%
% fill array H with transfer function amplitude
[H,W]=freqz(num,den,Farray,Fs);
%
% plot digital filter magnitude response, log in x,
linear in dB in y
semilogx(Farray,20*log10(H),'w');
hold on; % Hold plot from prior to next case
%
end % A_index loop
44 Oak Avenue Belmont, MA 02478-2715 USA
voice/fax 617 489 6292
[email protected]
http://www.world.std.com/~cmoore/