Upload
kerry-chayka
View
224
Download
0
Embed Size (px)
Citation preview
7/29/2019 DSP Final Paper: Digital Filtering Implementation
1/32
DIGITAL
FILTERINGIMPLEMENTATION
12/10/2012 Digital Signal Processing Final ProjectKerry Chayka
Abstract: The purpose of this project is to implement digital filtering in the
audio frequency range on a physical system designed by the author. The
system will include several digital filters, three with variable parameters
based on user input, and one adaptive to the signal itself. The output of
the filters can be observed using a set of speakers and/or an oscilloscope
as seen in the picture above.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
2/32
Digital Filtering Implementation
Page 1
Digital Filtering ImplementationD I G I T AL S I G N A L P R O C E S S I N G F I N A L P R O J E C T K E R R Y C H A Y K A
Table of Contents
1|INTRODUCTION AND BACKGROUND ...................................................................................................... 2
2|TECHNICAL APPROACH AND DETAILED ANALYSIS.................................................................................... 3
Microprocessor Selection ................................................................................................................................................... 3
Analog Design ..................................................................................................................................................................... 4Digital Filter Design ............................................................................................................................................................ 6
Programming Requirements .............................................................................................................................................. 7
PCB Design ........................................................................................................................................................................... 8
3|SYSTEM OPERATION .............................................................................................................................. 12
Diagram of Boards Used ................................................................................................................................................. 12
PCB and Breadboard Diagram .................................................................................................................................... 13
Low-Pass Filter ................................................................................................................................................................... 14
High-Pass Filter .................................................................................................................................................................. 15
Band-Pass Filter ................................................................................................................................................................ 16
4|RESULTS ................................................................................................................................................ 17
Normal Operation ........................................................................................................................................................... 17
Low-Pass Filter .................................................................................................................................................................. 18
High-Pass Filter ................................................................................................................................................................. 20
Band-Pass Filter ................................................................................................................................................................ 21
Coefficient Analysis ......................................................................................................................................................... 23
Notable Phenomena ........................................................................................................................................................ 26
5|CONCLUSIONS, RECOMMENDATIONS, AND IMPACT OF WORK .......................................................... 28
Conclusions ........................................................................................................................................................................ 28
Impact on the Education of the Author ......................................................................................................................... 28
Mobile Studio Discussion ................................................................................................................................................. 29
6|REFERENCES ........................................................................................................................................... 30
7|APPENDICES........................................................................................................................................... 31
Appendix A| Microprocessor Code ............................................................................................................................. 31
7/29/2019 DSP Final Paper: Digital Filtering Implementation
3/32
Digital Filtering Implementation
Page 2
1|INTRODUCTION AND BACKGROUND
Digital Filters are used in an enormous number of applications. Digital
communications (as seen in cell phones), audio processing, radar / sonar and data-
acquisition systems are just a few examples. While designing the proper filter for any
given application is difficult in and of itself, implementing that filter on a physical
system becomes a new challenge. Hardware has to be chosen very carefully based on
the frequency range being processed, the range of the data, required bits of
quantization, accuracy of reconstruction required, as well as the architecture of the
processor itself if special functionality is needed. An analog input stage is necessary toprepare the signal for digital processing, as is an output stage for proper
reconstruction. Specially designed PCBs are necessary in most cases to minimize noise
and for high-frequency operation. The challenges of this process are significant;
however the flexibility and power of digital filtering make it worth the extra
complexity.
This project will act as a teaching tool both for the author and for future users of
the system in all of the areas mentioned above. For users, the operation of the onboard
variable digital filters and the observation of the output, both visually and aurally, will
help demonstrate filter design and operation. For the author, the process of designing
and manufacturing such a system provided valuable insight into the design of complex,
multi-discipline systems, a subject which is not taught in any depth in school, and
experience in designing digital filters and creating digital signal processing systems in
general.
To this end, the entire design process will be carried out by the author, using
manufacturers tools and libraries as necessary. This includes microprocessor selection,
analog input & output stage design, digital filter design, code generation, and design
of a printed circuit board to house the system. The system will be manufactured anddemonstrated so the results can be observed. This entire process will be carried out in
the period of seven weeks.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
4/32
Digital Filtering Implementation
Page 3
2|TECHNICAL APPROACH AND DETAILED ANALYSIS
M I C R O P RO C E S S O R S E L E C T I O N
The microprocessor is the most important part of the system because it is where
the digital filtering actually takes place. In this case it is also what samples and
quantizes the input signal (with the integrated analog to digital converter (ADC)), and
reconstructs the output signal (with the integrated digital to analog converter (DAC)).
Since both the ADC and DAC are integrated, additional constraints were put on the
microprocessor, including maximum ADC frequency and DAC sample and hold time. It
was decided, by using the Nyquist Theorem that the sample rate and DAC frequency
should be 50kHz in order to properly sample and reconstruct the signal, and thenumber of bits of quantization should be between 8 and 16 (# of bits of quantization
in radio and CDs respectively.) These numbers also require that the microprocessors CPU
clock speed be high enough to manage all of the data being generated, processed,
and moved around. By calculating the number of instructions required to implement the
most processor-intensive filter (band pass, worst case 100 instructions), multiplying by 3
to find the number of CPU cycles, and dividing the ADC sample period by this number,
the minimum possible CPU clock was found to be 15MHz. Using this information, and
other concerns like manufacturability and cost, the Atmel AT32UC3C264 was selected.
The AT32UC3C264 has maximum ADC clock 1.5MHz, maximum DAC clock 1MHz,
maximum CPU clock 60MHz, and enough memory to implement the program (64kB.)
Although other requirements were considered (GPIO, Peripheral Event Controller, etc)
they are beyond the scope of this report.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
5/32
Digital Filtering Implementation
Page 4
A N A L O G D E S I G N
In order to properly sample and quantize an analog signal, it must be band-
limited and be within a specific voltage range. In this case, the input was band-limited
to 20kHz, and the input voltage limited to 0 1V. For reconstruction, a similar
frequency limit is required due to the high frequency quantization noise of the DAC.
Band-limiting in both the input and output case was accomplished through the
use of a filter network. The original design utilized third order Bessel filters with cutoff
frequency 20kHz due to their linear phase characteristics, however these were later
replaced by second order RC filters due to manufacturing cost. An output high-pass
filter with cutoff frequency 1Hz was included to remove any DC bias added by the
system. A diagram of the input and output networks is shown below. Note that the
system is designed to function with stereo audio signals.
Since audio signals are centered on 0 volts and range from -0.4V to +0.4Vdepending on the source volume, an input stage was needed to add a 0.5V DC bias to
the signal in order to center it in the required range of 0 1V. This was accomplished
with a simple resistor network. It is not shown in the board schematic because it was
added post-manufacturing.
Other concerns included having an appropriate input (and output) impedance so
that the majority of the signal voltage drop would occur over the input stage, and in
the case of the output stage, an appropriate impedance so that most of the signal
voltage drop would occur in the output device (speakers, headphones.) This wasaccomplished through the use of an audio-grade op-amp (TLV2772) and appropriate
resistor values in the input stage. Trimmers are included in the feedback loops of allinput and output op-amps to tune for maximum resolution and for volume control,
respectively.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
6/32
Digital Filtering Implementation
Page 5
Input Filtering Network
Output Filtering Network
7/29/2019 DSP Final Paper: Digital Filtering Implementation
7/32
Digital Filtering Implementation
Page 6
D I G I T AL F I L T E R D E S I G N
The main purpose of this project was to implement variable digital filters to
demonstrate, among other things, the effect of pole and zero locations on the impulse
response of the filter. This presents a major design challenge because filters are almost
always designed to have very specific, known transfer functions, and therefore indirect
design through the analog domain is possible. However, for this project it was necessary
to find the exact effect that each coefficient had on the transfer function and therefore
direct design was necessary. The design process was carried out by hand on paper, but
the final transfer functions of each filter are shown below in the following order: low-
pass, high-pass, band-pass, notch. Hand calculations will be shown on request. The
design parameters , 0, andwill be discussed in the system operation section.
=1
1
=1 +
1
=120 +
+ 120 +
120 +
.05 < < .95
.05 < < .95
= 120
+
120 +
+ 1 20 +
7/29/2019 DSP Final Paper: Digital Filtering Implementation
8/32
Digital Filtering Implementation
Page 7
P R O G R A M M I N G R E Q U I R E M E N T S
Although a microprocessor was selected that exceeds the minimum requirements of
the project, it does not function at these rates initially. In fact, it does not function at all
until code is written to it that initializes the necessary processing blocks. Code wasgenerated by the author to initialize the main clock, CPU clock, peripheral bus clocks,
ADC, DAC, PDCA (peripheral DMA controller), INTC (interrupt controller) and GPIO
(general purpose I/O controller.) Manufacturer libraries were used wherever possible due
to the prototype nature of this project. Additional code was generated to use the ADC,
DAC, PDCA, INTC and GPIO processing blocks as required to implement the filters shown
above. The initialization code will not be described in detail here, as it is beyond the
scope of this report, however the entire program can be found in Appendix A.
The following is a summary of the program operation. The main function includes
calls to the initialization function of each processing block, and a main loop that starts an
ADC sample, waits until the conversion is done, checks if any buttons are pushed
(indicating a call to one of the filter functions,) and then waits again until the necessary
20uS period is completed. DAC output is triggered by interrupt every 20uS, with data
sent to the output register by the PDCA on each interrupt.
Each filter function re-initializes the ADC as necessary, to accommodate the
additional measurement of the potentiometer(s). It then enters a loop in which it starts the
ADC, delays for a few microseconds to ensure conversion, calculates the filter coefficients
and then computes the output value y[n]. This value is then written to a location in memorythat is linked to the PDCA, to be written to the DAC on each output interrupt. The
adaptive notch filter function attempts to compute the coefficients and output value
automatically based on a comparison of the current and previous output values.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
9/32
Digital Filtering Implementation
Page 8
P C B D E S I G N
Due to the nature of the microprocessor being used, a printed circuit board (PCB) was
required to implement this system. The PCB was manufactured through a third party
(OSHPark PCB Fab,) however it was designed and populated by the author. The design
includes the input and output stages, microprocessor and the components it requires for
operation, push-buttons, JTAG programming interface, USB interface, and headers for
expanded use. The design was created using EAGLE, and occurred in several stages.
The first stage was the design of the schematic seen above. This schematic gives the
program the details of component connections. The datasheet of the microprocessor was
used extensively to create this document, and by extension a functioning board.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
10/32
Digital Filtering Implementation
Page 9
The second stage was board layout, the final result of which is shown above. The
program generated a group of components based on the connections in the schematic.
The parts were then laid out on a board and all necessary connections between them,
called traces, were created by hand. Many design requirements were considered
including trace width, part location, trace length in differential communication and
analog lines, proximity of decoupling capacitors, etc.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
11/32
Digital Filtering Implementation
Page 10
The third stage was fabrication. The design was sent to OSHPark PCB fabrication to be
manufactured. Photo credit: OSHPark PCB Fabrication
The fourth stage was population of the board
7/29/2019 DSP Final Paper: Digital Filtering Implementation
12/32
Digital Filtering Implementation
Page 11
The fifth stage was test & modification. As with any project, the first design does not
always function as expected, so all stages of the design must be tested and modified to
match the desired operation. In this case, the only necessary modification was theaddition of the input DC bias resistor network and the potentiometers to control the
variable filters. In order to accommodate these changes, wires were added to the PCB
for power (red), ground (black), audio signal (yellow, green), and potentiometer value
(orange.) These changes will be included on the PCB in any future revisions.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
13/32
Digital Filtering Implementation
Page 12
3|SYSTEM OPERATION
D I A G R A M O F B OA R D S U S E D
1. Rensselaer Mobile Studio The Rensselaer Mobile Studio board was used
extensively as an oscilloscope, arbitrary waveform generator and spectrum
analyzer. Its use will be described and shown in detail in the results section. This
project would not have been possible without this tool.
2. AVR Dragon Programming & Debugging BoardThis board was created by Atmel,
the manufacturer of the microprocessor. It was used to program and debug themicroprocessor.
3. Audio Processing BoardThis board was designed by the author to house the entire
digital processing system. Its operation is described below.
4. Input BreadboardThis breadboard was created to house extra components andmodifications made to the system post-manufacture. Its components are described
below.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
14/32
Digital Filtering Implementation
Page 13
P C B A N D B R E A D B OA R D D I A G R A M
1. Input StageThe signal enters the system through a generic 3.5mm audio jack. The
resistor network adds a 0.5V DC bias.
2. Gain / filtering The signal goes directly into an audio op-amp (TLV2772, IC in
section 2) where the gain for each channel can be selected by the two
potentiometers. The signal then passes through a series of low-pass filters so it can be
band-limited.
3. Filter PotentiometersThese potentiometers are used to vary the parameters of each
variable filter. They will be discussed in greater depth later in this section.
4. MicroprocessorThis is where the sampling, filtering and reconstruction take place. It
is the main IC on the circuit board and the peripheral components needed to ensure
its operation can be seen to the bottom and left of it (resistors, capacitors, JTAG
programming header.) The IC to its right is included to make serial communication with
a computer possible through a USB cable.
5. Output stage / filters The signal will be reconstructed by the DAC inside the
microprocessor, and then sent to the other op-amp in the top right of the board.
Potentiometers are again included for volume control. The signal then passes to a
high-pass filter to remove the DC bias (this is necessary in order to hear the signal
through speakers) and a second-order low-pass filter to remove DAC quantization
noise.
6. Pushbutton Filter Selectors These buttons are used to select which filter is applied.
The order is band-pass, low-pass, high-pass, and vocals (the optional extensionfilter.)
7/29/2019 DSP Final Paper: Digital Filtering Implementation
15/32
Digital Filtering Implementation
Page 14
L O W - P A S S F I L T E R
=1
1 -.95 < < .95
The figureshown to the right is a
diagram of this particular low-
pass filter. Poles and zeros wereconstrained to the real axis for
simplicity. The potentiometer
shown below is mapped directly
to the parameter . In the low-
pass function, the value of that
potentiometer is read
immediately after the audio
channel, and the coefficients are
calculated accordingly. The
segment of code that calculates
the coefficients and computes the
output is shown in the bottom
right.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
16/32
Digital Filtering Implementation
Page 15
H I G H - PA S S F I L T E R
=1
1 -.95 < < .95
The figure shown to the right is a
diagram of this particular high-
pass filter. Poles and zeros wereconstrained to the real axis for
simplicity. The potentiometer
shown below is mapped directly
to the parameter . In the high-
pass function, the value of that
potentiometer is read
immediately after the audio
channel, and the coefficients are
calculated accordingly. The
segment of code that calculates
the coefficients and computes the
output is shown in the bottom
right. =
1 +
1
7/29/2019 DSP Final Paper: Digital Filtering Implementation
17/32
Digital Filtering Implementation
Page 16
B A N D - P A S S F I L T E R
The figure shown to the right is a
diagram of this particular band-pass
filter. A group of poles and zeros wasdesigned such that the entire group will
move together with the parameters r, 0,
and Q (since T is the sample rate
constant).The potentiometers responsible
for r and 0 are shown below. Q is set in
the program header. In the band-pass
function, the value of these
potentiometers is read immediately after
the audio channel, and the coefficientsare calculated accordingly. The segment
of code that calculates the coefficients
and computes the output is shown in the
bottom right.
= 120 +
+ 120 +
120 +
7/29/2019 DSP Final Paper: Digital Filtering Implementation
18/32
Digital Filtering Implementation
Page 17
4|RESULTS
The following sections include screenshots and discussion of the performance of the system
during normal operation (no filter selected), within each filter function, and at any othernotable instance (output quantization, unexpected results). In each figure, the blue
waveform is the input to the board and the green waveform is the output from the board.
Also note that the oscilloscope channel amplitude on the output is half that of the input due
to an internal gain of 2 in the system which is required for appropriate output volume.
N O R M A L O P E R AT I O N
The figure above shows the normal operation of the board with no filters selected. It
can be seen that the output signal does not perfectly match the input signal mainly dueto the high-frequency response of the system. This can be attributed to the use of simple
2nd order RC filters where higher order filters with steeper roll-off would be preferred.
This decision was made for cost and manufacturing purposes and is therefore an
acceptable design trade-off. It is worth noting that the loss of such high frequencies has
very little effect on the music and (for aural concerns) can be ignored.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
19/32
Digital Filtering Implementation
Page 18
L O W - P A S S F I L T E R
From the figure above, the operation of the low-pass filter can be observed. For this test, the
low-pass filter was set with the lowest possible cutoff frequency. Note that the high frequency
oscillations were blocked while the underlying base frequency was passed. In another test, the
system was given a sine wave input that swept from 16Hz to 20kHz and its response was
measured by a spectrum analyzer in order to characterize the impulse response of the low-
pass filter. Several screenshots from the test are shown below.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
20/32
Digital Filtering Implementation
Page 19
7/29/2019 DSP Final Paper: Digital Filtering Implementation
21/32
Digital Filtering Implementation
Page 20
H I G H - PA S S F I L T E R
The operation of the high-pass filter can be seen in the figure above. For this test the high-pass filter was set with the highest possible cutoff frequency. Some low frequencyattenuation can be seen, however it is not as much as expected. Although the high
frequencies passed by this filter are partially stopped by the output low-pass filternetwork, it can still be seen that higher frequencies are more present in this signal than innormal operation or the low-pass filter. A frequency sweep was not conducted for thisfilter due to the confounding effects noted above.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
22/32
Digital Filtering Implementation
Page 21
B A N D - P A S S F I L T E R
The operation of the band-pass filter can be seen in the figure above. The potentiometersthat correspond to r and 0 were set to roughly half of the maximum value. Theparameter Q was chosen to be 100 in order to have a very narrow pass-band. This
narrow band can be seen very easily above. The narrow pass band was alsodemonstrated through a sine-sweep test shown in the figures on the next page.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
23/32
Digital Filtering Implementation
Page 22
7/29/2019 DSP Final Paper: Digital Filtering Implementation
24/32
Digital Filtering Implementation
Page 23
C O E F F I C I E N T A N A L Y S I S
The main goal of this project was to create a teaching tool for the design of digital filters.
This is possible through examining the output of the system with an oscilloscope, as well as
listening to the output through speakers. However, the best demonstration of the design ofdigital filtering occurs within the code itself. Through the debugger, it is possible to make a
change to just one of the potentiometers and examine the effect that this change has onthe coefficients of the filter. This is best seen in the band-pass filter.
Above is the debugging environment for the band-pass filter before any changes are
made. Note the coefficients of the digital filter, B0, B1, B2, etc shown in white next tothe blue bullet points. These values will become red if they are changed by the program.
At this point, the potentiometer controlling 0 was turned to a new value.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
25/32
Digital Filtering Implementation
Page 24
In the figure above, we can see that after this change occurred, more than one coefficient
became red. This is proof to the reader that one parameter does not necessarily
correspond to a single coefficient. In fact, in this case nearly all of the coefficients are
influenced by 0. This is obvious when the equations for each coefficient are laid out as in
the program above, but it is very much the opposite when looking at the factored transfer
function. To prove that this change wasnt a coincidence, the potentiometer corresponding
to r was changed. Looking at the equations in the program above, we would expect all ofthe coefficients to become red since they all depend on r.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
26/32
Digital Filtering Implementation
Page 25
This is indeed what happens, and by extension we see that many coefficients are related
to both 0 and r. Unfortunately for the DSP student, this property causes significant
complexity to occur in even relatively simple filters such as the three shown in this project,
however it is partially due to this complexity that digital filtering is so highly regarded.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
27/32
Digital Filtering Implementation
Page 26
N O T A B L E P H E N O M E N A
During the course of this project, several interesting results were found. Although expected,the transformation from quantized output to smooth analog waveform through the output
filter network was still interesting and instructive. This phenomenon is shown in the two
figures below. These screenshots were taken before the DC bias network was added,
effectively clipping the input sine wave to purely positive values. The filtered output
waveform demonstrates another interesting phenomenon that will be shown in more detail
later.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
28/32
Digital Filtering Implementation
Page 27
The filtered output signal looks surprisingly like the input, even though the input was
clipped at 0V. This shows the second interesting result of partial-reconstruction of the
original signal through filtering. A more extreme case of this can be seen below, where
even though the input is saturated, the output contains that portion of the signal.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
29/32
Digital Filtering Implementation
Page 28
5|CONCLUSIONS, RECOMMENDATIONS, AND IMPACT OF WORK
C O N C L U S I O N S
This project shows some of the flexibility of digital filtering through the design and
operation of variable digital filters, and the attempt at an adaptive filter. The filters
shown in this project, though basic, demonstrate what is possible with modern
microprocessors and cleverly designed filters. Though the complexity of digital filtering is
intimidating, the benefits afforded by this domain far outweigh the drawbacks in almost
all advanced applications such as radar, image processing, and real-time signals analysis.
I M P AC T O N T H E E D U C A T I O N O F T H E A U T H O R
Through the design and manufacture of this system, many new skills were learned,
including PCB design and fabrication, the integration of analog, digital and DSP systems,
troubleshooting complex systems, and the design of a physical product. These lessons are
unique because they are not taught in school and are extremely beneficial in the work
place. These skills will be carried forward into all future projects and experiences.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
30/32
Digital Filtering Implementation
Page 29
M O B I L E S T U D I O D I S C U S S I O N
Throughout this project, the tool that was relied on most heavily was the Rensselaer Mobile
Studio board. It was used in all steps of the physical manufacturing and debugging of the
system, and was invaluable in demonstrating the systems operation. The oscilloscope andspectrum analyzer functions were used mainly, although the digital I/O function was useful
in debugging the filter selection switch connections, and actually led to the discovery of afaulty switch. An advanced project such as this is not possible without the ability to fully
debug any point of the system, and the Mobile Studio was an invaluable tool in this
regard. The Mobile Studio is shown in the picture below, assisting in the debugging of the
system.
7/29/2019 DSP Final Paper: Digital Filtering Implementation
31/32
Digital Filtering Implementation
Page 30
6|REFERENCES
Atmel Corporation, 2012. AT32UC3C Datasheet. [online] Place: Producer/Publisher.
Available at:http://www.atmel.com/images/32117s.pdf[Oct. 2012].
Oppenheim, Alan V., and Ronald W. Schafer. Discrete-time Signal Processing. Upper
Saddle River: Pearson, 2010. Print.
"OSH Park." OSHPark PCB Fabrication. Laen, Jan. 2010. Web. 4 Nov. 2012.
.
http://www.atmel.com/images/32117s.pdfhttp://www.atmel.com/images/32117s.pdfhttp://www.atmel.com/images/32117s.pdfhttp://www.atmel.com/images/32117s.pdf7/29/2019 DSP Final Paper: Digital Filtering Implementation
32/32
Digital Filtering Implementation
7|APPENDICES
A P P E N D I X A | M I C R O P RO C E S S O R C O D E