Sunteți pe pagina 1din 32

DIGITAL FILTERING IMPLEMENTATION

12/10/2012

Digital Signal Processing Final Project Kerry 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.

Digital Filtering Implementation

Digital Filtering Implementation


D I G I T A L 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 RY C H AY K A

Table of Contents
1|INTRODUCTION AND BACKGROUND ...................................................................................................... 2 2|TECHNICAL APPROACH AND DETAILED ANALYSIS .................................................................................... 3 Microprocessor Selection ................................................................................................................................................... 3 Analog Design ..................................................................................................................................................................... 4 Digital 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

Page 1

Digital Filtering Implementation

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 dataacquisition 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 to prepare 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 and demonstrated so the results can be observed. This entire process will be carried out in the period of seven weeks.

Page 2

Digital Filtering Implementation

2|TECHNICAL APPROACH AND DETAILED ANALYSIS

MICROPROCESSOR SELEC TION

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 the number 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.

Page 3

Digital Filtering Implementation

ANALOG DESIGN

In order to properly sample and quantize an analog signal, it must be bandlimited 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.4V depending 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 was accomplished 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 all input and output op-amps to tune for maximum resolution and for volume control, respectively.

Page 4

Digital Filtering Implementation

Input Filtering Network

Output Filtering Network


Page 5

Digital Filtering Implementation

D I G I TA L F I LT 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: lowpass, high-pass, band-pass, notch. Hand calculations will be shown on request. The design parameters , 0 , and will be discussed in the system operation section.

1 1 1

.05 < < .95

1 + 1 1

.05 < < .95

1 2 0 + 1 + 2 2 1 2 0 1 + 2 2 = 1 2 0 1 + 2 2

1 2 0 1 + 2 2 = 1 2 0 + 1 + 2 2 1 2 0 1 + 2 2

Page 6

Digital Filtering Implementation

PROGRAMMING REQUIREM ENTS

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 was generated 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 memory that 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.

Page 7

Digital Filtering Implementation

PCB DESIGN

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.

Page 8

Digital Filtering Implementation

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.

Page 9

Digital Filtering Implementation

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

Page 10

Digital Filtering Implementation

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 the addition 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.

Page 11

Digital Filtering Implementation

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 Board This board was created by Atmel, the manufacturer of the microprocessor. It was used to program and debug the microprocessor. 3. Audio Processing Board This board was designed by the author to house the entire digital processing system. Its operation is described below. 4. Input Breadboard This breadboard was created to house extra components and modifications made to the system post-manufacture. Its components are described below.
Page 12

Digital Filtering Implementation

P C B A N D B R E A D B OA R D D I A G R A M

1. Input Stage The 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 Potentiometers These potentiometers are used to vary the parameters of each variable filter. They will be discussed in greater depth later in this section. 4. Microprocessor This 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 extension filter.)
Page 13

Digital Filtering Implementation

L O W - PA S S F I LT E R

The figure shown to the right is a diagram of this particular lowpass filter. Poles and zeros were constrained to the real axis for simplicity. The potentiometer shown below is mapped directly to the parameter . In the lowpass 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 1

-.95 < < .95

Page 14

Digital Filtering Implementation

H I G H - PA S S F I L T E R

The figure shown to the right is a diagram of this particular highpass filter. Poles and zeros were constrained to the real axis for simplicity. The potentiometer shown below is mapped directly to the parameter . In the highpass 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 1

-.95 < < .95

Page 15

Digital Filtering Implementation

B A N D - PA S S F I LT E R

The figure shown to the right is a diagram of this particular band-pass filter. A group of poles and zeros was designed 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 coefficients are calculated accordingly. The segment of code that calculates the coefficients and computes the output is shown in the bottom right.

1 2 0 + 1 + 2 2 1 2 0 1 + 2 2 = 1 2 0 1 + 2 2

Page 16

Digital Filtering Implementation

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 other notable 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 due to 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.

Page 17

Digital Filtering Implementation

L O W - PA S S F I LT 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 lowpass filter. Several screenshots from the test are shown below.

Page 18

Digital Filtering Implementation

Page 19

Digital Filtering Implementation

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 highpass filter was set with the highest possible cutoff frequency. Some low frequency attenuation 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 filter network, it can still be seen that higher frequencies are more present in this signal than in normal operation or the low-pass filter. A frequency sweep was not conducted for this filter due to the confounding effects noted above.

Page 20

Digital Filtering Implementation

B A N D - PA S S F I LT E R

The operation of the band-pass filter can be seen in the figure above. The potentiometers that correspond to r and 0 were set to roughly half of the maximum value. The parameter 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 also demonstrated through a sine-sweep test shown in the figures on the next page.

Page 21

Digital Filtering Implementation

Page 22

Digital Filtering Implementation

COEFFICIEN T A NA LYS IS

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 of digital 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 on the 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 to the 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.

Page 23

Digital Filtering Implementation

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 of the coefficients to become red since they all depend on r.

Page 24

Digital Filtering Implementation

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.

Page 25

Digital Filtering Implementation

N O TA 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.

Page 26

Digital Filtering Implementation

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.

Page 27

Digital Filtering Implementation

5|CONCLUSIONS, RECOMMENDATIONS, AND IMPACT OF WORK


CONCLUSIONS

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 PAC T O N T H E E D U C AT I O N O F T H E AU 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.

Page 28

Digital Filtering Implementation

MOBILE STUDIO DISCUSSION

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 and spectrum 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 a faulty 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.

Page 29

Digital Filtering Implementation

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://oshpark.com/>.

Page 30

Digital Filtering Implementation

7|APPENDICES

APPENDIX A| MICROPROCESSOR CODE

Page 31

S-ar putea să vă placă și