Electrical and Computer Engineering Dept.
Dr. Monty A. Escabi
EE 3101, Fall 2018
MATLAB Application Project
Due: Dec. 7, 2018
3-Band Digital Audio Equalizer
The goal of this project is to build and test a digital audio equalization network in which you will be able to
boost or attenuate the low, mid and high frequency range of music sounds. Audible sounds cover a frequency
range from 20 Hz – 20 kHz (for human hearing). In many listening scenarios sounds are distorted by the audio
system (e.g., the speaker transfer function) or the acoustic environment (room transfer function). One can
correct for the magnitude of such distortions with an audio equalizer. High end audio equalizers typically have
~30 selectable bands that allow you to adjust the sound gain in 1/3 octave frequency steps for frequencies
between 20Hz – 20 kHz. For the purpose of this project, we will consider a simpler equalization network that
allows you to adjust the bass, midrange and treble bands.
In this project, you will design and build a three-band equalizer where you will be able to separately adjust the
bass, midrange and treble using MATLAB. The schematic for this design is illustrated below:
The input sound waveform, x(t), is decomposed by three filters and these outputs are routed a gain term for
each of the three bands (Gb=bass, Gm=mid, and Gt
=treble). The signals are then added together to generate the
corrected output.
The lowpass (LP) filter encompasses frequencies below 100 Hz (bass range). The midrange is selected with a
bandpass (BP) filter covering frequencies in the range 100Hz-5 kHz. The trebles is selected with a highpass
filter (HP) that encompasses the remainder of the audible range (5-22.05 kHz).
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
HP
BP
LP
x(t)
GB
GM
GT
Treble
Midrange
Bass
+ y(t)
Each of the above filters is implemented using a Kaiser window FIR (Finite Impulse Response) filter
(see chapter 4.9 & 12.8-1 for windowing and FIR filter design). 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, this is not
practically feasibleand the ideal filters cannot be implemented in practice. 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 which is widely used for singal processing. The Kaiser window
contains a single parameter ( β ) that is used to control the filter “smoothness” in the time domain. In the
frequency domain this parameter serves to adjust the passband and stopband errors.
In the above equation, each of the ideal filter impulse responses are given by
Lowpass
ideal
2p sinc 2
where Fc is the cutoff frequency of the ideal lowpass filter and Fs =44100 Hz is the sampling rate of the data.
Bandpass
"#$%& = 2 *+
,-
*+
,-
cos 2 89 +/2 />
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] = δ [k] 2Fc
Fs
sinc
2πFc
Fs
k "
#
$ %
&
'
where Fc is the ideal highpass filter cutoff frequency and δ [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 (δ [k]) and an ideal lowpass filter (the sinc function term).
In all of the above filters k spans the integers (from -∞ to ∞ ), however, in the actual filter
implementation described below the filters will be truncated from –N to N (for a total of 2N+1 coefficients).
Also, note that in MATLAB the sinc function is defined as sin(π x) /(π x) whereas above and in the book it is
defined as sin(x)/x. You will need to remove π from the sinc function during implementation in MATLAB to
obtain the correct results.
Filter Implementation
To generate the Kaiser filter you will
1) Need to determine the Kaiser order (N) and smoothness parameter ( β ). As described in the class for the
Butterworth filter, the filter parameters 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. This parameter corresponds to the amount of 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 δ =0.01 (relative to a passband gain of
1), then ATT = ?20log10 (δ) = ?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 + f ( p ) 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.
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
ROARK AND ESCAB′I: -SPLINE DESIGN OF MAXIMALLY FLAT AND PROLATE SPHEROIDAL-TYPE FIR FILTERS 703
for integer values of , where Equation
(5) for describes piecewise polynomials on the interval
and zero elsewhere, as indicated in Fig. 2.
The lowpass filter prototype is obtained by applying
(5) to the convolution integral for It is
straightforward to show that the result may be expressed as
for (6)
which describes a piecewise function that is nonzero on the
interval Equation (6) is valid for
and integer values of With
in (6) being a lowpass filter function, is recognized to
be the corresponding highpass filter function.
The discrete-time impulse response of the filter is obtained
by applying (3) to the integral formula (1) and using the
convolution theorem, resulting in
(7)
for , and It is noted that the magnitude
response in Fig. 1 and the impulse response in (7) approach
those of the rectangular filter as or as Impulse
response functions for other filter types, such as bandpass and
notch [16], may be developed in similar fashion.
Unlike most digital filters, these prototypes continue to
be unity throughout the passband and zero throughout the
stopband so that they are maximally flat for all derivatives
of with respect to for and
Further, is maximally flat at
in the sense that the first derivatives of are
zero there (as approached from ). Thus, the filter prototypes
have maximally flat prescriptions in both the passband and
stopband, in similar manner that prototypes are specified to
be maximally flat at and using the functions of
Hermann [1] in the FIR case or the polynomials of Butterworth
[17] for filters requiring rational function descriptions. The
original filter prototype, prior to convolving with , may
be any function for which it is desired to smooth transition
edges and not necessarily one with rectangular-like features.
The flatness features of are demonstrated in Appendix
A. A historical perspective of the evolvement of these filter
prototypes is provided in Appendix B.
III. PRINCIPALLY FLAT FILTERS
This manuscript follows the text of Mitra and Kaiser [7]
regarding definitions of cutoff frequency transition width
and stopband attenuation of the approximated frequency
response that results from truncation of the
convolution series, as depicted in Fig. 3.
The window method of FIR filter design maps target parameters
of the magnitude response to parameters of the impulse
response coefficients. For single-parameter window functions,
such as the Hamming, Hann, and Blackman windows, a
specification for transition width is mapped to a value
of (one half filter order). With these windows, there
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
and because many filtering applications require the highly
selective characteristics offered by a prolate spheroidal-type
window. However, the Kaiser window offers little control
otherwise over the basic shape of the filter magnitude response.
If control over shape of the magnitude response is desired (or,
equivalently, control over shape of the window), then another
parameter must be introduced into the window function.
Proposals of windows containing additional parameters have
met with mixed success [9], [10], [19]. Usually, the additional
parameter has been designed into the window function for
purposes of gaining a tighter transition width or increasing
stopband attenuation rather than to achieve other desirable
features, such as flatness in a selected region of the passband.
The filter introduced in this paper offers two parameters—
and —in addition to Therefore, specifications of and
can be expected to map to two of these parameters, whereas
the third may be used to control shape of the magnitude
response. Because the parameter in (7) represents the number
of convolutions or smoothing operations, it can be expected to
dominate control of amplitude error in the magnitude response.
Similarly, the parameter can be expected to dominate control
of transition width. Since the filter prototype has been
developed to be principally flat in the passband and stopband,
the filter magnitude response can be expected to offer
features of flatness as well.
A. The Need for Flat Passband Filters
There are many filtering applications in which passband
and stopband flatness are given equal or greater priority than
β =
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
#
$
% &
'
(
2) 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(2*N+1,Beta);
You will also need to generate the desired ideal filter impulse as described above but truncated 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.
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.
Equalizer Specifications
The filters are designed to satisfy the following specifications.
Lowpass Filter:
Gp = 0.9 Gs = 0.01
?@ = 150 Hz > = 250 Hz
Bandpass Filter:
Gp1 = Gp2 = 0.9 Gs1 = Gs2 = 0.01
@9 = 150 Hz >9 = 250 Hz
@D = 4950 Hz >9D = 5050 Hz
Highpass Filter:
= 0.9 Gp Gs = 0.01
> = 4950 Hz @ = 5050 Hz
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 several 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*10);
This generates a 10 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
equalization network for music. No additional work is necessary.
For both signals (white noise & music sample), you will simulate three versions of the equalization filterbank.
These include:
1) 20 dB gain in the bass section with the other two bands set to 0 dB gain.
2) 20 dB gain in the midrange section with the other two bands set to 0 dB gain.
3) 20 dB gain in the treble section with the other two bands set to 0 dB gain.
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
(pwelch; type ‘help pwelch’ for details). The syntax will typically be something as follows:
pwelch(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.
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 convert each data array into a WAV sound file. You can do this with the audiowrite command in
MATLAB. The syntax for the command is as follows:
audiowrite(wavfile,Ys,Fs,’BitsPerSample’,nbits)
where
Ys=Y/max(abs(Y)) is the rescaled 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 audiowrite
For this project, you will use the parameters
Fs=44100
nbits=16
Let’s say you want to write the data of an array X to a WAV file named: test.wav. You can use the syntax:
audiowrite(‘test.wav’,X/max(abs(X)),Fs,’BitsPerSample’,nbits);
Writeup and submission
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 the time waveform changes between input and output or both music and white noise.
b) How each equalization network changes 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 soundsc routine and compare and contrast the
audible differences between the input and output for all of the different conditions.
4) Program code – uploaded to Husky CT as a single file “Project3101_LastName.m”
5) Figures – time waveform and power spectrum of input and output for each condition.
6) Wav Sounds – You’ll need to upload the wav sounds for the three networks (bass, mid and treble
versions) and two sound versions (Music or white noise, WN) with the following file names
BassMusic_LastName.wav
TrebleMusic_LastName.wav
MidMusic_LastName.wav
BassWN_LastName.wav
TrebleWN_LastName.wav
MidWN_LastName.wav
Honors Student Requirements
In addition to implementing the equalization network using the Kaiser filters, also implement the above network
(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.
NOTE: When implementing the analog Butterworth filters using the transfer function syntax as described in the
book, you might run into some numerical stability issues. To overcome these issues, you will need to determine
the normalized passband (Wp) and stopband (Ws) frequencies (normalized by the Nyquist frequency) and
design a digital Butterworth filter using the zeros, poles, and gain syntax. For example, to design a digital
lowpass filter for given Gp, Gs (in dB), Wp, Ws use the following matlab commands
[n,Wc] = buttord(Wp, Ws, Gp, Gs);
[z,p,k] = butter(n,Wc);
sos = zp2sos(z,p,k);
Y = sosfilt(sos,X);
Where X is your input sound vector.
a) Contrast and compare the filters (Kaiser vs. Butterworth). 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.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。