Electrical and Computer Engineering Dept.

Electrical and Computer Engineering Dept.
Dr. Monty A. Escabi
EE 3101, Fall 2015
MATLAB Application Project
Due: Dec. 11, 2015
Digital Audio Crossover Design
The goal of this project is to build and test a digital audio crossover network. A crossover is a filterbank that is
used to separate out sounds so that they are efficiently delivered to a speaker array. Audible sounds cover a
frequency range from 20 Hz – 20 kHz (for human hearing). Individual speaker drivers (e.g., tweeter, midrange
and woofer), however, can only faithfully reproduce a portion of this spectrum. Therefore, speaker drivers of
different sizes can be combined to reproduce the entire hearing range. The crossover divides the sound spectrum
into the frequencies that each driver faithfully reproduces.
In this project you are to implement a digital crossover in MATLAB for a three-way speaker system. The
schematic for this design is illustrated below:
The input sound waveform, x(t) , is decomposed by three filters and these outputs are routed to each individual
speaker drivers. The lowpass (LP) filter encompasses frequencies below 500 Hz. The output from this filter is
used to drive the woofer (low frequency speaker). The midrange driver is driven by the output from a bandpass
(BP) filter. This filter only allows frequencies in the range 500Hz-5 kHz to pass through. The highpass filter
(HP) encompasses the remainder of the audible range (5-22.05 kHz). This output drives the high frequency
speaker (the tweeter).
You are allowed to work in groups of two or three. However, each student is required to hand in their own
independent report and is required to implement his/her own code. Reports using copied code or text will
be returned without a grade! (Yes, we will check for this! Code needs to be uploaded onto HUSKYCT). Group
members who worked on the project should be identified in the writeup.
Filter Design
For this project you will use a Kaiser window FIR (Finite Impulse Response) filters to implement the
crossover network. In general, windowed FIR filters are implemented as the product of an ideal filter impulse
response ( hideal [k] , for a lowpass, bandpass or highpass) and a window function (w[k] ) that is used to
smoothly truncate the ideal filter impulse response to a total of 2N+1 samples
h[k] = hideal [k]·w[k]
Here N is a filter parameter referred to as the filter order where the total number of coefficients in the discrete
time impulse response of the filter is 2N+1. Conceptually, note that any “ideal” filter requires an infinite amount
of time and therefore an infinite amount of coefficients to implement. As we have discussed in class, practically
this is not possible and the ideal filters cannot be implemented. To overcome this, the window function is used
to truncate the filter in a smooth fashion in order to 1) require only finite number of time samples (2N+1) and 2)
minimize filter distortions (or errors) in the passband and stopband.
There are a variety of window functions that can be used to generate an FIR filter as above. In this
project we will be using a Kaiser window. For the Kaiser window, there is an additional parameter (ß ) that is
used to control the filter “smoothness” in the time domain or equivalently, it serves to adjust the passband and
stopband specifications (error and frequencies) in the frequency domain.
In the above equation, each of the ideal filter impulse responses are given by
Lowpass
hideal [k] =
2Fc
Fs
sinc
2p Fc
Fs
k
!
” #
$
% &
where Fc is the cutoff frequency of the idel lowpass filter and Fs =44100 Hz is the sampling rate of the data.
Bandpass
hideal [k] =
BW
Fs
sinc
BW
Fs
k
!
” #
$
% &
· cos 2p Fc1 ( + BW / 2)k Fs ( )
hideal [k] =
BW
Fs
sinc
BW
Fs
p k
!
” #
$
% &
· cos 2p Fc1 ( + BW / 2)k Fs ( )
where Fc1 and Fc2 are the lower and upper cutoff frequencies of the ideal bandpass filter and BW = Fc2 – Fc1 is
the filter bandwidth.
Highpass
hideal [k] =d [k]-
2Fc
Fs
sinc
2p Fc
Fs
k

# $
%
& ‘
where Fc is the ideal highpass filter cutoff frequency and d [k] is the discrete time Diract delta function (i.e., 1
for k=0 and zero otherwise). Note that this highpass filter impulse response is simply the difference between an
allpass filter (d [k] ) and an ideal lowpass filter (the sinc function term).
In all of the above filters k spans the integers (from -8 to 8), however, in the actual filter
implementation described below the filters will be truncated from –N to N (for a total of 2N+1 coefficients).
Filter Implementation
To generate the Kaiser filter you will
1) first generate the desired ideal filter impulse as described above but truncate the filter for a total of 2N+1
coefficients (i.e., k=-N … N). In matlab, you can assign the vectors h_low, h_band, h_high for each of
these filters.
2) You need to determine the Kaiser order (N) and smoothness parameter (ß ). As described in the class for
the Butterworth filter, the filter paramters are obtain with a mapping equation that converts the filter
specifications to filter parameters. For a Kaiser filter, there are two filter specifications of interest.
a) ATT = is the filter attenuation. Simply speaking, this is the amount of allowed error in the
passband and stopband in units of dB. For Kaiser filters, the stopband and passband errors
are symmetric so we don’t need separate errors to describe each and we can use a single
number. For example, if the error in the passband is d =0.01 (relative to a passband gain of
1), then ATT = -20 log10 (d ) = -20 log10 (0.01) = 40 dB (in the graph below ATT=As). For the
case of a bandpass filter, two errors may be provided, one for the stopband and one for the
passband. Choose the more stringent of the two for the Kaiser filter design.
b) TW= is the transition width of the filter in units of Hz. Conceptually, TW is the frequency
range over which the filter transitions from the passband to the stopband (or vise versa for a
highpass filter). If fp is the passband frequency in Hz and fs is the stopband frequency, then
TW= fs – fp . The filter specifications are shown graphically below for a lowpass filter.
Note that the cutoff frequency is directly in the center between the stopband and passband
frequencies ( fc = fs + fp ( ) 2 ) (normalized to units of radians in the above graph). For the
case of a bandpass filter, two TW may be provided, one for the stopband and one for the
passband. Choose the more stringent of the two for the Kaiser filter design.
OF MAXIMALLY FLAT AND PROLATE SPHEROIDAL-TYPE FIR FILTERS 703
Equation
polynomials on the interval
elsewhere, as indicated in Fig. 2.
is obtained by applying
integral for It is
result may be expressed as
(6)
function that is nonzero on the
Equation (6) is valid for
With
function, is recognized to
filter function.
response of the filter is obtained
formula (1) and using the
in
(7)
is noted that the magnitude
impulse response in (7) approach
or as Impulse
types, such as bandpass and
similar fashion.
these prototypes continue to
passband and zero throughout the
Fig. 3. Definitions of stopband attenuation , transition width , and
cutoff frequency for the (real-valued) filter function associated with
the truncated convolution series (2).
are no additional parameters, and therefore no control is
provided over stopband attenuation or over the shape of
the magnitude response.
In 1974, Kaiser [3] introduced a window function that
approximated the prolate spheroidal wave function [18] while
being computationally easier to determine. Using the Kaiser
window, stopband attenuation of the magnitude response may
be controlled by mapping to a parameter of the window,
which is denoted by Kaiser as The Kaiser window filter
is a popular choice because it is relatively easy to design
Given the above filter specification (ATT and TW or alternately the stopband and passband frequencies
and errors), you will obtain the filter parameters N and ß using the following transformation
ß =
0 ATT<21
0.5842(ATT – 21)0.4 + 0.07886(ATT – 21) 21= ATT = 50
0.1102(ATT -8.7) ATT > 50
#
$
%%
&
%%
N = ceil
Fs (ATT – 7.95)
28.72 ·TW
#
$ %
&
‘ (
Once you obtain the filter parameters, the Kaiser window is obtain as a vector containing 2N+1 coefficients
using the following command in MATLAB:
w=kaiser(N,Beta);
If you generate the ideal filter impulse response as described above, the final filter is then generated as
h=h_ideal.*w;
where h_ideal is a vector containing the filter coefficients from the above equations.
Crossover Network Specifications
The filters will be designed to satisfy the following specifications.
Lowpass Filter:
Gp = 0.9 Gs = 0.01
fp = 250 Hz fs = 750 Hz
Bandpass Filter:
Gp1 = Gp2 = 0.9 Gs1 = Gs2 = 0.01
fp1 = 700 Hz fs1 = 300 Hz
fp2 = 4.5 kHz fs2 = 5.5 kHz
Highpass Filter:
= 0.9 p G Gs = 0.01
fp = 5.5 kHz fs = 4.5 kHz
All sound waveform are sampled at a sampling rate of 44.1 kHz. Once you generate the Kaiser impulse
response as described above you can simply convolve the impulse response with the sound waveform to
generate the output:
y=conv(h,x);
where h is the impulse response vector, x is the input sound vector, and y is the output sound vector.
Simulation
You are to simulate the crossover filtering procedure for two separate signals.
1) White noise – similar to the hissing noise you hear when your FM radio is not tuned to a station
2) Music sound sample provided
I will provide a short music sound sample as a MATLAB data file (to load type: ‘load filename.mat’). To
generate a sample of white noise simply use the command:
x=randn(1,44100*5);
This generates a 5 second white noise signal.
Note that once your code is written for white noise you simply have to change the array x to resimulate the
crossover filterbank for music. No additional work is necessary!
Plotting Results
You are required to plot the results both in the time and frequency domain for both the input and the output. To
plot the time-waveforms simply use the command:
plot(taxis,x)
where taxis is a time axis array containing the sample time points and x is an array containing the waveform. To
plot the magnitude spectrum of the input or output signals simply use the power spectral density command
(PSD; type ‘help psd’ for details). The syntax will typically be something as follows:
psd(x,512,Fs)
where Fs=44100 is the sampling rate.
Note that there are a total of 12 graphs to plot (2 sounds x 3 filters/sound * (1 time domain graph/filter + 1 freq.
domain graph/filter) = 12 graphs)
Generating WAV Sound File and playing the sound:
You are expected to listen to each of the sound files at each filter output stage of the crossover so that you gain
some insight into the transformations that are being performed at each stage. In order to do this, you need to
convert each data array into a WAV sound file. You can do this with the WAVWRITE command in MATLAB.
The syntax for the command is as follows:
wavwrite(Y,Fs,nbits,wavfile)
where
Y= is the signal vector
Fs= is the sampling frequency in Hz
nbits=is the number of bits (i.e. The resolution) of each sample
wavfile=is the output file name
For additional information in MATLAB you can type: help wavwrite
For this project, you will use the parameters
Fs=44100
nbits=16
Lets say you want to write the data of an array X to a WAV file named: test.wav. You can use the syntax:
wavwrite(X,44100,16,’test.wav’);
Alternately, on some computers, you can also listen to the sound using the SOUNDSC command. For the sound
vector X, you can play the sound using the syntax: soundsc(X,Fs). You can use this as an alternative approach
(to WAVWRITE) assuming that it works on your computer.
Writeup
A short writeup describing the methods and results is required. At minimal it should include.
1) A brief introduction describing the project objective (~ 1 page).
2) A brief description of the methods (~1-2 pages).
3) A discussion of the results. Focus on describing:
a) How each filter modifies the time waveforms for music and white noise.
b) How each filter modifies the magnitude spectrum of music and white noise.
c) Compare and contrast the input and output waveforms.
d) Listen to the input and output sounds using the wavwri routine and compare and contrast the
audible differences between the input and output.
4) Program code.
5) Figures.
Honors Student Requirements
In addition to implementing the filterbank using the Kaiser filters, also implement the above filterbank
(identical passband and stopband parameters) using a Butterworth filter. Details for the implementation of the
Butterworth filters in MATLAB can be found in section 7.5 of the book (e.g., see example C7.5). As for the
Kaiser filter, plot the same set of results (time and frequency domain), but only do so for white noise.
a) Contrast and compare the filters (Kaiser vs. Butterworht). Do they sound similar or are there audible
differences when you implement the crossover for the music. Visually, do the spectrums look similar or
different when you use white noise. Describe any discrepancies or similarities.

READ ALSO :   Masters in Nursing with emphasis in Public Health