PRACTICAL EXAMPLE FOR IIR FILTER
We had discussed IIR filtering on my last post.
Due to its minimal MAC operation compared to FIR, this filter is commonly used in new HiFi audio.
Mainly for canned equalization we see such as ROCK, POP, CLASSIC, SOFT, JAZZ, etc.
Nevertheless, this is commonly found in digital parametric equalizers where one can adjust the Q and the frequency of the band to set.
For this example, I will give an example for bass boosting using DSP.
This is pretty simple. It is just using a shelving filter.
A shelving filter either increases or decreases one part of the band, either low or high but does not change the other band.
In our case, we will use a low shelving filter.
We will set our gain to positive to increase the bass and set our cut-off frequency to 400Hz.
A gain of 9 dB should give us a HUGE bass boost.
We will use the "Cookbook formulae for audio EQ biquad filter coefficients" by Robert Bristow-Johnson for our IIR coefficients computation:http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
Using MathCad or any formula solver (even MsExcel could be used), compute the following:
fo = 400
fs = 44100
S = 1
A = 10^(9/20)
w0 = 2 * 3.1416 * fo / fs
alpha = sin(w0)/2 * sqrt( (A + 1/A)*(1/S - 1) + 2 )
b0 = A*( (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha )
b1 = 2*A*( (A-1) - (A+1)*cos(w0) )
b2 = A*( (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha )
a0 = (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha
a1 = -2*( (A-1) + (A+1)*cos(w0) )
a2 = (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha
x0 = b0/a0
x1 = b1/a0
x2 = b2/a0
y0 = a1/a0
y1 = a2/a0
The value of S (shelf-slope) equal to "1" is chosen to be so the filter's response is as steep as it can be.
The resulting values x0, X1 and X2 are the coefficients for the input.
input coefficients = (+1.04457887924806,-1.94808417101059,+0.91244684520764)
WHile y0 and y1 are for the coefficients for the output.
output coefficients = (-1.95199211029050,+0.95311778517579)
Now that we have our coefficients for our filter, we will use our previous hifi sound sample.
We will only be using 2 seconds of it.
My computer, even a core2quad with 4Gb memory, freezed when I process the whole 10 seconds.
Scilab sucks on high memory requirement programs. Python with scipy/pylab should be nicer.
Anyway, c'est la vie, we will continue and only use 2 seconds of it.
To run our filter, we will use the our iir computation function discussed on the last topic.
We will cut the clip at between 5 and 7 seconds for our 2 second sample.
Then we separate the 2 channels (left and right) and process them separately.
After the 2 processed outputs are combined to become stereo again.
A demo matrix is then created by having the original clip and the processed clip concatenated.
The following is our resulting bass boost Scilab program:
//By: Regulus Berdin
function output = compute_iir(signal, x_coef, y_coef)
N = length(signal);
YN = length(y_coef);
XN = length(x_coef);
temp = zeros(1:XN);
win1 = progressionbar("Working.");
for i = YN+1:N
xframe = signal(i:-1:i-(XN-1));
yframe = temp(i-1:-1:i-YN);
temp(i) = sum(xframe * x_coef') - sum(yframe * y_coef');
output = temp;
x_coef = [+1.04457887924806 -1.94808417101059 +0.91244684520764];
y_coef = [-1.95199211029050 +0.95311778517579];
clip_start = 5;
clip_end = 7;
[signal,fs,bits] = wavread('c:/music.wav',[44100*clip_start, 44100*clip_end]);
//scale so not to clip
signal = signal * 0.2;
left_ch = compute_iir(signal(1,:), x_coef, y_coef);
right_ch = compute_iir(signal(2,:), x_coef, y_coef);
stereo_out = [left_ch; right_ch];
demo = [signal stereo_out];
printf("\nPlaying original and the processed sound clip....\n");
You should hear a very big difference in the bass on the first 2 seconds with the next 2 seconds but not changing the higher band.
Try experimenting with different filters, such as the high shelf.
Combine it with the low by passing the processed output into another IIR filter.
You can try also using the IIR filter on our previous FIR examples.
Please show your programs and describe the results so you could share with others what you have learned and experienced.
Now you have learned all the basic time-domain filtering.
We shall proceed next with the the frequency domain and creating spectrographs.
But before that, I will give another time-domain process example.
This is the STEREO WIDENING or 3D audio effect.
This is not using filters but an just an enhancement.
This is pretty much easy once you know its theory.http://en.wikipedia.org/wiki/3D_audio_effect
I will give +points to those who could do this in advance.