Take control of your SAP testing with UiPath Test Suite
Digital Tuner Project Final Report
1. Digital Tuner Project
TU Berlin – Summer 2012
Mihir ,Jennifer Liu, Samantha Luber, Michael Ulrich
I. Introduction
The Digital Tuner Project consists of building a tuner board that accepts sound
signals through a microphone as input, performs signal processing and
analysis on the sound signal, and outputs the corresponding guitar note and
the guitar note’s “in tune-ness” via LED lights as output. This report contains
a detailed description of the Digital Tuner’s hardware and programming
implementation in addition to the signal sampling and processing theory
behind the project.
A. Digital Tuner Board Overview
The Digital Tuner Board is a device that analyzes the spectrum of a sound
signal and determines the corresponding guitar string and whether or not the
string is in tune, sharp, or flat. The project consists of four stages: building the
board, implementing an analog-to-digital converter, performing digital signal
processing on the signal, and developing and implementing an algorithm for
determining the note and tune of the sound signal [1]. This section provides an
overview of the hardware and software components utilized in the project and
the significance of the project’s underlying theoretical components to the
signal and microprocessor fields of study.
B. Project Tools
This subsection consists of a brief overview of the hardware and software
components utilized in the Digital Tuner Board project.
1. Hardware Components
The Digital Tuner Project consisted of hardware for the Digital
Tuner Board itself as well as hardware for testing the board.
Described in detail in the Digital Tuner Board Hardware section and
Appendix A., notable hardware components in the Digital Tuner
Board includes the ATmega1284P processor, the microphone, and
USB to UART transmitter. Hardware for building and testing the
Digital Tuner includes a soldering iron, an oscilloscope, a
multimeter, and a wave function generator.
2. Software Components
Software used in the Digital Tuner Project includes MATLAB and
AVRStudio. MATLAB was used for testing algorithms for
performing Fourier transforms on signals, calculating frequency
spectrum of signals, and analyzing and verifying the output of the
analog-to-digital converter implementation in the micro-controller.
AVRStudio is an IDE for micro-controller programming and was
used for programming the Digital Tuner Board and flashing code to
the board.
C. Relevance
The Digital Tuner is relevant to the fields of signal and microprocessor study
because it encapsulates the theoretical components of the digital measurement
2. chain, intelligent sensors, and frequency analysis [1]. Throughout the project,
hardware building, digital measurement technology, signal processing, and
micro-controller programming is learned and utilized.
II. Digital Tuner Board Hardware
The section contains details of the hardware components, the hardware layout,
and hardware testing of the Digital Tuner Board.
A. Hardware Overview
Shown below in Figure 1, the Digital Tuner Board consists of a series of
hardware components, described in detail in Appendix A., including resistors,
capacitors, LED lights, a crystal oscillator, a potentiometer, operational
amplifiers, a USB to UART transmitter, and an ATmega1284P micro-
controller.
Figure 1. The Digital Tuner Board. This figure shows a fully constructed Digital Tuner
Board, built through soldering hardware components to a basic board [1].
The ATmega1284P is an 8-bit Atmel micro-controller with 32 general-
purpose I/O lines (PORTA-PORTD) and two USARTs for serial
communication with peripherals [2].
B. Soldering
All components of the Digital Tuner Board were attached using Tin Lead
solder and standard soldering techniques. The recommended assembly order
for the board used included attaching hardware components in the following
order:
• Resistors, capacitors
• SMD parts
• EMI filter
• LEDs
• Crystal Oscillator
• Push-buttons
• IC Sockets
• Micro-controller
• Microphone
3. The full board circuitry layout and schematic can be found in Appendix A.
C. Hardware Testing
Hardware testing of the Digital Tuner Board consists of general testing and
filter testing. General testing includes applying and measuring various
voltages across the IC pins and LED’s. Filter testing includes using the
oscilloscope to verify the low-pass filter implemented on the board. Figure 2
shows the validated frequency response from the low pass filter of the Digital
Tuner Board.
Figure 2. Frequency Response of the Low Pass Filter. This figure shows the frequency
response of the Digital Tuner Board’s low pass filter. The blue line shows the frequency
response of the input signal. The red line shows the frequency response of the output signal
from the low pass filter. As the filter cuts off frequencies below the designated cutoff
frequency, the low pass filter of the Digital Tuner Board can be validated.
Final testing includes connecting the microphone to the system via jumper
pins and watching for sound signal output measured via the oscilloscope.
Once hardware construction and testing is complete, the project moves on to
sampling and analysis of guitar sound signals.
III. Theoretical Music Note Analysis
This section contains an overview of the digital measurement technology and
digital signal theories prevalent throughout the Digital Tuner Board Project.
A. Understanding the Digital Measurement Chain
The digital measurement chain consists of a series of steps required to
effectively perform digital signal processing on an input signal. Figure 3
shows a diagram of each step of the Digital Measurement Chain specific to
the Digital Tuner Project.
4. Figure 3. The Digital Measurement Chain. This flowchart depicts each stage in the
Digital Measurement Chain as it is used in the Digital Tuner Project, beginning with the
initial capture of the input signal at the microphone and ending with LED output
resulting from digital signal processing on the signal [1].
Corresponding to the elements in Figure 3, the general stages of the Digital
Measurement Chain include signal input, signal conditioning, anti-aliasing,
signal sampling, analog-to-digital conversion, digital signal processing, and
output [3]. Described in detail in Appendix B., each stage in the Digital
Measurement Chain is essential for a correct interpretation of an input signal.
B. Theory of Digital Signal Processing
After the input analog signal is conditioned and converted into a digital signal,
the Digital Tuner performs various processes for analysis. Described in detail
in Appendix C., the micro-controller converts the digital signal into an
amplitude spectrum in the frequency domain. In this state, the maximum
amplitude peak for the captured signal can be quickly determined. The
frequency corresponding to this amplitude peak is the calculated frequency of
the input guitar signal [4]. Using this information, further calculations can be
performed specific to the analysis of the guitar note frequency.
IV. Digital Tuner Board Implementation
This section contains an overview of the micro-controller code
implementation for the Digital Tuner Board, including a program flowchart,
design implementation decisions, and an overview of the user interface for the
Digital Tuner Board. Appendix D. includes a detailed description of the
program’s modules as well as the serial communication, interrupt, and timing
subsystems of the micro-controller, all of which are used in the Digital Music
Tuner code implementation.
A. Concept Overview
The Digital Tuner program runs continuously, waiting for user input and
producing output accordingly. The flow chart of the Music Tuner system,
including the micro-controller program, is shown below in Figure 4.
5. Figure 4. Digital Tuner Program Flow Chart. This flow chart shows the various states of
the Digital Tuner.
When a guitar string is played, if the analog-to-digital converter (ADC) isn't already
running, the ADC is triggered by the rising edge of the input signal's frequency. The
ADC can also be started via messages over the micro-controller's bus line using USART
[5]. Once the ADC starts running, a specified number of samples is collected from the
input signal and quantized into a digital signal [6]. The ADC concept and implementation
is described in detail in Appendix E. Once the conversion is complete, the micro-
controller does further processing on the digital signal, described in detail in Appendix C.
First, the a Fourier transformation is applied to the digital signal and an amplitude
spectrum is calculated, as shown in Figure 5a [2].
6. Figure 5a. Amplitude Spectrum of an Input Signal. This figure shows the amplitude spectrum of an input
guitar signal. The peak amplitude in the spectrum corresponds to the frequency of the guitar string being
played, as shown in Figure 5b.
Next, the largest amplitude in the spectrum is determined along with its corresponding
frequency. This frequency value is the calculated frequency of the input guitar string.
Using fixed ranges of frequency values to guitar note and tune correspondence, as shown
in Figure 5b below, the guitar note and whether the note is in tune, flat, or sharp is
determined.
Signal
Frequency
(Hz)
Guitar
Note
82.41
Low
E
110.0
A
146.8
D
196.0
G
246.9
B
329.6
High
E
Figure 5b. Signal Frequency to Guitar Note Chart. This chart shows the correspondence between
input signal frequency and guitar note. The micro-controller uses this chart with additional
ranges for flatness and sharpness to calculate the correct LED output.
LED’s are updated to reflect these calculations and communicate with the user.
Implementation details and code excerpts can be found in Appendix D.
B. User Interface Overview
The User Interface of the Digital Tuner Board consists of six LED lights to
provide user feedback. Shown below in Figure 6, Each LED light corresponds
7. to a string on the guitar with the left-most LED light representing the low E
note and the right-most LED light representing the high E note.
Figure 6. LED User Interface. This figure shows the user interface of the Digital Tuner
Board. The LED lights (labeled by pin numbers PB4-PB0 and PD7) represent the
corresponding guitar strings displayed above.
To represent the tune of each guitar note, LED’s blink to the left or right of
the lit guitar note LED light. For example, in reference to Figure 6 above, if a
very flat D guitar string is played, the Low E and A LED lights will blink.
Similarly, if a somewhat flat D guitar string is played, only the A LED light
will flash. This same process is used for indicating sharp notes by blinking
LED’s to the right of the out-of-tune note. In the event that the Low E note is
flat or the High E note is sharp, the blinking LED’s “wrap around” to the other
side of the LED lights.
V. Conclusion
The Digital Tuner Project provided an interactive learning environment for
building hardware by soldering, signal sampling, analog-to-digital signal
conversion, Fourier transformation of signals, signal spectrum analysis,
micro-controller programing in C, and user interface development [1].
VI. Acknowledgments
Special thanks to Joachim Priesnitz, Jürgen Funck, and Andreas Bock for
holding open lab hours to provide support and debugging assistance with the
Digital Tuner Project.
VII. Appendix A. Hardware Components
This appendix contains a detailed description of the hardware components
included in the Digital Tuner Board.
A. Atmega1284P Micro-controller
The Atmega1284P is an 8-bit micro-controller with 32 I/O pins, 32 general-
purpose registers, three flexible Timer/Counters, and Flash memory. The
board supports communication via USART and SPI [2]. Figure 7 below shows
the block diagram of the Atmega1284P micro-controller.
8. Figure 7. Atmel Atmega1284P Micro-controller [2].
B. Digital Tuner Board Circuitry Diagram
Figure 8 below shows the circuitry diagram of the Digital Tuner Board.
9.
Figure 8. Digital Tuner Board Circuitry Diagram [7].
C. Tuner Board Schematics
Figure 9 below shows the schematics of the Digital Tuner Board.
10. Figure 9. Digital Tuner Board Schematics [7].
VIII. Appendix B. Measurement Technology
This appendix contains a detailed description of the components of the Digital
Measurement Chain. The digital measurement chain consists of five stages: signal
conditioning, anti-aliasing, sample & hold, analog-to-digital conversion, and data
processing.
A. Signal Conditioning
Signal conditioning involves adjusting the input signal for more accurate analysis. This
stage typically involves using operational amplifiers to magnify the signal [3]. The
Digital Tuner Board has an operational amplifier for this purpose.
B. Anti-aliasing
The anti-aliasing stage is responsible for removing erroneous signals in the input signal,
resulting from aliasing in the signal sampling. Low-pass filters are typically used to filter
out these artifacts [3]. The Digital Tuner Board has a low-pass filter used in this anti-
aliasing stage.
C. Sample & Hold
The sample and hold stage includes capturing the data of an input signal and accepting no
new input until data processing on the captured data is complete.
D. Analog-to-Digital Conversion
The Analog-to-Digital Converter (ADC) converts an analog signal to a digital signal. The
accuracy of the ADC is dependent on the converter's resolution. An ADC with low
resolution typically produces an output digital signal with a significant amount of
quantization error [3].
E. Data Processing
The data processing stage includes advanced processing of the digital signal by the
micro-controller. In the Digital Tuner Board, the amplitude spectrum of the digital signal
11. is computed and analyzed in this stage to determine the guitar's note and tune.
IX. Appendix C. Signals and Sampling Theory
This appendix contains a brief overview of theoretical and practical signal sampling, the
Fourier transformation, and amplitude spectrum analysis as well as their application to
the Digital Tuner Project.
A. Signal Sampling
When sampling an analog signal, using an appropriate sample rate is essential for
reconstructing the input signal accurately. Theoretically, sampling a signal faster than the
Nyquist Rate, or twice the maximum frequency of the input signal, is sufficient for
accurate sampling [3]. However, in real-world applications, sampling must take place at a
much higher rate due to inaccuracies of electrical components. When a signal is not
sampled fast enough, aliasing, or the introduction of noise and erroneous artifacts into the
input signal, can occur.
B. The Fourier Transformation
The Fourier Transformation is a mathematical procedure for converter signals in the time
domain to signals in the frequency domain. In the frequency domain, analysis of signals
is often simpler as periodic signals are represented by pulses instead of continuous
signals [4]. For algorithm verification, the Digital Tuner Board implementation of the
Fourier transform and inverse Fourier transform was first written and tested in Matlab.
Below are code excerpts of both functions.
1. Fourier Transform MATLAB Code
function [x] = fourier_transform(signal, N)
x = zeros(N, 1);
for k = 1:N
for n = 1:N
x(k) = x(k) + signal(n)*exp(-1i*(n-1)*(k-1)*2*pi/N);
end
end
plot(x)
end
2. Inverse Fourier Transform MATLAB Code
function
[x]
=
inverse_ft(X,
N)
x
=
zeros(N,
1);
for
n
=
1:N
for
k
=
1:N
x(n)
=
x(n)
+
X(k)*exp(i*(n-‐1)*(k-‐1)*2*pi/N);
end
x(n)
=
(1/N).*x(n);
end
end
C. Amplitude Spectrum Analysis
In order to determine the guitar note and tune of the input frequency, the amplitude
spectrum of the input frequency must be analyzed. A maximum frequency function
calculates the frequency in the amplitude spectrum at which the amplitude is at a
maximum by iterating through all of the amplitude values. A special case is made for
lower guitar strings as resonance at this frequencies can occur.
12. X. Appendix D. Micro-controller Programming Specifications
This appendix includes a detailed description of the program’s modules as well as the
serial communication, interrupt, and timing subsystems of the micro-controller, all of
which are used in the Digital Tuner code implementation.
A. Digital Tuner Program Modules
The Digital Tuner program consists of five modules: serial communication, analog-to-
digital conversion, Fourier transformation, digital signal processing, and I/O. Serial
communication allows the micro-controller to communicate with peripherals via USART.
The analog-to-digital converter converts input analog signals to digital signals. The
Fourier transformation module generates the amplitude spectrum of the sampled signal.
The digital signal processing stage determines the guitar note and tune. The I/O module
consists of the microphone (input) and the LED's (output).
B. Serial Communication System
The Atmega1284P micro-controller supports serial communication over USART. For
testing and debugging purposes, output from the board can be sent over USART to
MATLAB or another peripheral for verification. The Digital Tuner Board establishes a
two-way communication channel with the computer, such that it can both send and
receive messages. The specific USART configurations for the Digital Tuner Board
include a 115200 baud rate and 8 data bit messages with 1 stop bit and no parity. USART
is a widely used serial communication system that allows data to be transmitted both
synchronously and asynchronously over a bus line. Advantages of USART include
simplicity and the need for only one or two data lines. A significant drawback of USART
is the slow communication rate, as data bits are transferred one at a time over the bus line
[5]. Below are code excerpts for sending and receiving data via USART. Note that an
interrupt, described in detail in the follow subsection, is triggered when a data bit is
received on the bus line.
void USART_transmit(unsigned char data) {
/* Wait for empty transmit buffer */
while (!( UCSR1A & (1<<UDRE1)));
/* Put data into buffer, sends the data */
UDR1 = data;
}
/*** INTERRUPT ROUTINES ***/
ISR(USART1_RX_vect) {
char data = (char)UDR1;
}
C. Interrupt Subsystem
The Atmega1284P micro-controller supports interrupts, a system for handling high-
priority events. Interrupts are triggered by per-defined events. When an interrupt occurs,
the executing program is paused, the state of the machine is saved, and the micro-
controller begins executing the interrupt handler routine associated with the interrupt.
Once the interrupt routine is complete, the micro-controller restores the state of the
machine and resumes the executing program [8]. In the Digital Tuner Board, interrupts
are used to pause the executing program when a message is received over USART or a
sample is converted in the ADC.
13. D. Timing Subsystem
The time subsystem of the Atmega1284P is essential for serial communication and signal
sampling. The crystal oscillator on the board oscillates and generates a clock. This clock
can be adjusted to run at a desired rate. In order to communicate with peripherals over
USART, the clock must be adjusted such that bits are sent at the correct rate.
Furthermore, in order to achieve the desired signal sample rate, the clock must be
adjusted to allow for correct sampling of the signal [9].
XI. Appendix E. Analog-To-Digital Converter
This appendix contains a detailed description of the Digital Tuner Board's
implementation and testing.
A. Configuring the Analog to Digital Converter
In order to convert analog input signals to digital signals on the Music Tuner board, we
have implemented an Analog to Digital Converter with the following specifications:
▪ AREF-Pin for voltage reference
▪ Single-ended input on channel ADC0
▪ ADC-Clock running at 1/64 of the CPU-Clock
▪ ADC conversions beginning with Auto-Triggering
• Each new conversion starting with a Compare-Match-Interrupt B
on Timer1
These settings are configured for desired digital signal output, specific to the
Music Tuner board.
B. Implementing the Analog to Digital Converter
The Analog to Digital Converter consists of four functions: adcInit, adcStart,
adcIsRunning, and an interrupt function (ADC_vect). The specifications of the function
implementations are as follows.
1. Analog to Digital Converter Initationation Function
The adcInit() function is responsible for initializing the ADC and setting the
corresponding registers to the desired settings.
void adcInit() {
// Set voltage to AFREF-Pin as a voltage reference (default)
// Sets ADC Enable to On, Initates an ADC, Enables Auto-Triggering, Enables interrupts
ADCSRA = (1<<ADEN) | (1<<ADATE) | (1 << ADPS2) | (1 << ADPS1) |(0 << ADPS0);
// Sets ADC-Clock to Fclk/64
ADCSRB = (1 << ADTS2) | (0 << ADTS1) | (1 << ADTS0);
}
2. Analog to Digital Converter Start Function
The adcStart() function is responsible for initiating an ADC conversion of the input
signal.
void adcStart(uint16_t sampleRateCode, uint16_t sampleCount, trigger_t triggerMode, int16_t triggerLevel,int16_t* adcBuf) {
// Put Timer1 in CTC mode with CPU clock and no prescaling
TCCR1B = (1<<WGM12) | (0<<CS12) | (0<<CS11) | (1<<CS10);
TIMSK1 = (1<<OCIE1B) | (1<<OCIE1A);
OCR1A = sampleRateCode;
OCR1B = sampleRateCode;
sample_rate = sampleRateCode;
trigger = triggerMode;
trigger_level = triggerLevel;
samples_aquired = 0;
samples_needed = sampleCount;
14. adcBuf2 = adcBuf;
sei(); //Enable interrupts
ADCSRA |= (1 << ADIE);
}
3. Analog to Digital Converter Running Function
The isADCRunning() function is responsible for returning whether or not the number of
samples taken is equal to the number of samples required. In other words, the
isADCRunning() function returns whether or not the ADC is running.
uint8_t adcIsRunning() {
return (samples_aquired < samples_needed && samples_needed != 0);
}
4. Analog to Digital Converter Sample Available Interrupt Function
The interrupt function handles reading the output of the ADC for each sample. This
function is called upon completion of a sample conversion.
/**
* fn ISR(ADC_vect)
* author your_name
* date day_of_implementation
* brief Interrupt-Routine for the ADC-Interrupt.
* Gets called when an analog-to-digital conversion is complete
*/
ISR(ADC_vect) {
// Check if ADC triggered
switch(trigger){
case RISING:
if (!adcIsRunning() && prev_value < trigger_level && ADC > trigger_level) {
adcStart(sample_rate, samples_needed,
trigger,trigger_level, adcBuf2);
}
break;
case FALLING:
if (!adcIsRunning() && prev_value > trigger_level && ADC < trigger_level) {
adcStart(sample_rate, samples_needed,
trigger,trigger_level, adcBuf2);
}
break;
default:
break;
}
// Read conversion result and write to buffer
adcBuf2[samples_aquired] = ADC-512;
prev_value = ADC-512;
samples_aquired++;
// Stop if desired samples reached
if (!adcIsRunning()) {
ADCSRA &= ~(1<<ADIE);
}
}
C. Validating the Analog to Digital Converter
In order to validate the accuracy of our Analog to Digital Converter, we have performed a
series of tests of various input signals to the ADC.
1. Constant Input Signal
In order to verify the output of our ADC, we sent various analog DC voltage signals in
the range of 0 to 3.3 volts to our Music Tuner board. We ran the ADC on these input
signals with a sample frequency of 1kHz for 1000 samples with the trigger mode
15. disabled. Our expected output was to see output results that are approximately the same
for all 1000 samples because the DC sample signals are all of the same voltage.
Furthermore, we expected to see higher output results as the input signal voltage
increased [6]. Consistent with these expectations, we saw approximately uniform output
values for our input signals that increased as the input signal voltage increased. For
example, with an input signal of 2.69 volts, our mean output value was 831.6040. Based
on our observations, we can see that our ADC is performing as expected (correctly).
2. Triangle Input Signal
In addition to testing our ADC system with a constant DC input voltage, we also tested
our ADC with a triangle signal, ranging from 0 to 3.3 volts). We expected to see output
results consistent with the shape of this input signal. Our results are shown below in
Figure 10.
Figure 10. Analog to Digital Converter Output from a Triangular Input Signal. This
graph demonstrates the ADC output from an inputted triangle signal. Consistent with our
expected output of the ADC, the shape of the output resembles that of the input in
quantized form.
16. Figure 11 Amplitude Spectrum of the ADC output from a triangular input signal. This
graph shows the amplitude spectrum of the ADC output displayed in Figure 10. Further
verifying the accuracy of our ADC, we can see that this amplitude spectrum, achieved
through fourier transformation of the ADC output values, is consistent with the amplitude
spectrum of a triangular signal.
Based on the close resemblance of our ADC output signal to the original triangular input
signal in both the time and frequency domain, we can confirm that our ADC is
performing conversions correctly for triangular input signals.
3. Sine Input Signal
In addition to testing our ADC system with a constant DC input voltage and triangular
signal, we also tested our ADC with a sinusoidal signal, ranging from 0 to 3.3 volts). We
expected to see output results consistent with the shape of this input signal [6]. Our
results are shown below in Figure 12.
17. Figure 12. Analog to Digital Converter Output from a Sinusoidal Input Signal. This
graph demonstrates the ADC output from an inputted sine signal. Consistent with our
expected output of the ADC, the shape of the output resembles that of the input in
quantized form.
Figure 14. Amplitude Spectrum of the ADC output from a sinusoidal input signal. This
graph shows the amplitude spectrum of the ADC output displayed in Figure 12. Further
verifying the accuracy of our ADC, we can see that this amplitude spectrum, achieved
through fourier transformation of the ADC output values, is consistent with the amplitude
spectrum of a sinusoidal signal.
18. Based on the close resemblance of our ADC output signal to the original triangular input
signal in both the time and frequency domain, we can confirm that our ADC is
performing conversions correctly for triangular input signals. Through our ADC
implementation and testing, we have created and verified a system for reliably converting
analog input signals to digital signals in order to perform further digital signal processing
on these input signals [6]. Specific to our project’s applications, we have created a system
for inputting sound signals from playing notes on a guitar and converting these sound
signals into a digital representation with the ultimate goal of determining the frequency
and corresponding guitar music note of these inputted sound signals.
XII. References
1. Gühmann, Clemens, Phd. IESS 2012 – The Digital Tuner
Project. Technische Universität Berlin.
2. ATmega1284P. Atmel Corporation.
<http://www.atmel.com/devices/atmega1284p.aspx>.
3. Gühmann, Clemens, Phd. Introduction to Measurement
Technology. Technische Universität Berlin.
4. Gühmann, Clemens, Phd. Time-discrete Signals in the Frequency
Domain. Technische Universität Berlin.
5. Serial Communication Subsystem. Technische Universität Berlin.
6. Analog-to-Digital Conversion. Technische Universität Berlin.
7. Bock, Andreas. Assembly Guide for the Guitar Tuner.
Technische Universität Berlin.
8. Interrupt Subsystem. Technische Universität Berlin.
9. Timing Subsystem. Technische Universität Berlin.