You are on page 1of 147

ANALYSIS OF FREQUENCY

RECOGNITION ALGORITHMS
AND IMPLEMENTATION IN
REAL TIME
A Dissertation
Submitted In Partial Fulfilment Of
The Requirements For The Degree Of

MASTER OF SCIENCE
In

NETWORK CENTRED COMPUTING,


HIGH PERFORMANCE COMPUTING

in the

FACULTY OF SCIENCE

THE UNIVERSITY OF READING

by

Marc Bartels
23 September 2004

SUPERVISORS:

Dr. Scott Linfoot (University of Reading)


Prof. Dr. Horst Schwetlick (FHTW Berlin)
Prof. Dr. Friedrich Hoppe (FHTW Berlin)
Declaration of authorship

I declare that this dissertation is my own, unaided work, except where otherwise
acknowledged or referenced. It is being submitted for the degree of Master of Science at the
University of Reading.

It has not been submitted before for any other degree or examination in any other university.

Reading, 23 September 2004

Marc Bartels

ii
Acknowledgements

I would like to thank the members of staff of the School of Systems Engineering1 for their
support and for being open to any kind of question. I also want to thank Texas Instruments
for equipment support.

My special thanks go to Dr. Scott Linfoot, School of Systems Engineering 1, for his patient
supervision throughout the whole project. Dr. Linfoot was not only a motivator at difficult
stages of the project, but also a very good reflector in many fruitful discussions. I also want
to thank him for encouraging me to publish and present a paper as a first author at the 8th
IEEE ISCE2, September 2004, in the course of this project.

Many thanks also go to Martin Ostermayer1,3, together we struggled through the studies both
at the FHTW Berlin and at The University of Reading. As a team, we managed to handle the
TMS320C6713 DSP Starter KIT during long and frustrating nights.

My sincere thanks are dedicated to Prof. Dr. Horst Schwetlick3, who taught me to see further
than the end of my nose during my studies at the FHTW Berlin. Concerning the project, Prof.
Schwetlick gave me some very crucial advice, helping to get an overview.

I also want to thank Prof. Dr. Friedrich Hoppe3 for a decisive path finding talk at the early
stage of the project. Prof. Hoppe pointed out possible and important avenues, such as the
FFTW4, a very important approach to investigate.

My gratitude goes to mother, Petra Bartels, and to my family for being the moral and
financial backbone during the whole academic year in the United Kingdom. Without them, a
successful accomplishment of this MSc would not have been possible. My father, István
Bartucz, deserves special honour for being the reason for my ambitions to become an
electronic engineer.

Last but not least, I would like to thank Delphine Saulnier for her fertile reflections and proof
reading which helped me to break big problems into smaller pieces, allowing me to see the
wood for the trees.

1
The University of Reading
2
International Symposium on Consumer Electronics
3
Fachhochschule für Technik und Wirtschaft (FHTW) Berlin, Fachbereich 1
4
“Fastest Fourier Transform in the West”
iii
Abstract

Frequency recognition is an important task in many engineering fields, such as audio signal
processing and telecommunications engineering. There are numerous applications where
frequency recognition is absolutely necessary like in Dual-Tone Multi-Frequency (DTMF)
detection or the recognition of the carrier frequency of a Global Positioning System (GPS)
signal. Furthermore, frequency recognition has entered many other engineering disciplines
such as sonar and radar technology, spectral analysis of astronomic data, seismography,
acoustics and consumer electronics.

Listening to electronic music and playing electronic musical instruments is becoming more
and more popular, not only among young musicians. This dissertation details background
information and a preliminary analysis of a musical system, the Generic Musical Instrument
System (GMIS), which allows composers to experiment with electronic instruments without
actually learning how to play them.

This dissertation gives background information about frequency recognition algorithms


implemented in real time. It analyses state-of-the-art techniques, such as Dual-Tone
Multiple-Frequency (DTMF) implementations and MIDI-based musical systems, in order to
work out their similarities. The key idea is to adapt well-proven frequency recognition
algorithms of DTMF systems, which are successfully and widely used in telephony. The
investigations will show to what extent these principles and algorithms can be applied to a
musical system like the GMIS.

This dissertation presents results of investigations into frequency recognition algorithms


implemented on a Texas Instruments (TI) TMS320C6713 Digital Signal Processor (DSP)
core, in order to estimate the frequency of an audio signal in real time. The algorithms are
evaluated using selected criteria in terms of speed and accuracy with accomplishing over
9600 single measurements. The evaluations are made with simple sinusoids and musical
notes played by instruments as input signals which allows a solid decision, which of these
frequency recognition algorithms is appropriate for audio signal processing and for the
constraints of the GMIS in real time.

iv
Table of contents Page

Table of Figures...................................................................................................................... ix
List of Tables........................................................................................................................... xi
Nomenclature......................................................................................................................... xii
List of Symbols ..................................................................................................................... xiv
1. Introduction ..................................................................................................................... 1
1.1 Background.............................................................................................................. 2
1.1.1 Dual-Tone Multi-Frequency (DTMF) Systems ............................................ 2
1.1.2 Musical Instrument Digital Interface (MIDI) in Musical Systems............. 5
1.1.3 Comparing DTMF and Musical Systems using MIDI................................. 9
1.2 The Generic Musical Instrument System (GMIS) ............................................. 10
2. Background Theory ...................................................................................................... 12
2.1 Fourier Transform-based Frequency Recognition Algorithms ........................ 12
2.1.1 The Fourier Series......................................................................................... 12
2.1.2 The Fourier Transform ................................................................................ 13
2.1.3 The Discrete Fourier Transform (DFT)...................................................... 14
2.1.3.1 Mathematical Derivation of the DFT ...................................................... 14
2.1.3.2 Interpretation of the DFT......................................................................... 15
2.1.4 The Fast Fourier Transform (FFT)............................................................. 16
2.1.4.1 Decimation of the DFT in Time (DIT)..................................................... 16
2.1.4.2 Mathematical Approach ........................................................................... 17
2.1.4.3 Bit Reversal................................................................................................ 19
2.1.4.4 The Butterfly Network.............................................................................. 19
2.1.4.5 Interpretation of the FFT ......................................................................... 21
2.1.5 The Non-Uniform Discrete Fourier Transform (NDFT)........................... 21
2.1.5.1 Mathematical Derivation of the NDFT ................................................... 21
2.1.5.2 Interpretation of the NDFT...................................................................... 22
2.1.6 The Goertzel Algorithm................................................................................ 22
2.1.6.1 Mathematical Derivation of the Goertzel Algorithm............................. 22
2.1.6.2 Interpretation of the Goertzel Algorithm ............................................... 24
2.2 Leakage Effect ....................................................................................................... 25
2.3 Scallop Loss............................................................................................................ 27
2.4 Windowing ............................................................................................................. 27
2.5 Decision on the Usage of Window Functions...................................................... 28

v
3. Implementation.............................................................................................................. 29
3.1 The Target Hardware ........................................................................................... 29
3.1.1 The Digital Signal Processor (TI TMS320C6713 DSP) ............................. 29
3.1.2 The TI TMS320C6713 DSP Board .............................................................. 31
3.1.2.1 Chip Support Library (CSL) ................................................................... 31
3.1.2.2 Board Support Library (BSL) ................................................................. 32
3.1.3 The Code Composer Studio (CCS).............................................................. 33
3.2 Buffer Strategies.................................................................................................... 34
3.2.1 The Ring Buffer Technique.......................................................................... 34
3.2.2 The Ping Pong Buffer Technique using EDMA ......................................... 35
3.2.3 Decision on the Buffer Technique................................................................ 36
3.3 Usage of the Timer ................................................................................................ 37
3.4 Possibilities of Code Optimisation ....................................................................... 38
4. Implementation of the Frequency Recognition Algorithms...................................... 41
4.1 Methodology .......................................................................................................... 41
4.2 Principle of the Frequency Recognition Algorithms.......................................... 42
4.2.1 The Discrete Fourier Transform (DFT)...................................................... 43
4.2.1.1 Simulation with MatLab........................................................................... 43
4.2.1.2 Implementation of the DFT in C.............................................................. 44
4.2.2 The Fast Fourier Transform (FFT)............................................................. 45
4.2.2.1 Simulation in MatLab............................................................................... 45
4.2.2.2 Implementation of the FFTW in C .......................................................... 46
4.2.2.3 Implementation of the FFT in C .............................................................. 50
4.2.3 The Non-Uniform Discrete Fourier Transform (NDFT)........................... 52
4.2.4 The Goertzel Algorithm................................................................................ 53
4.3 Comparison of schedulable Buffer Sizes............................................................. 55
5. Measurements................................................................................................................ 56
5.1 Measurement Setups ............................................................................................. 56
5.2 Analysis of Input Signals ...................................................................................... 58
5.2.1 Sinusoidal Inputs........................................................................................... 59
5.2.2 Inputs of Musical Instruments ..................................................................... 62
5.2.2.1 Note C6 (1046.5Hz) for Piano, Violin, Flute and Trumpet ................... 63
5.2.2.2 Note C5 (523.25Hz) for Piano, Violin, Flute and Trumpet ................... 65
5.2.2.3 Note C4 (261.63Hz) for Piano, Violin, Flute and Trumpet ................... 67
5.3 Prediction of the Algorithms’ Frequency Recognition Capability ................... 69
5.4 Evaluation Criteria ............................................................................................... 70
5.4.1 Fixed Quantities............................................................................................. 70

vi
5.4.1.1 Sampling Rate............................................................................................ 70
5.4.1.2 Spectral Resolution ................................................................................... 71
5.4.1.3 Minimum Buffer Size for a sufficient Spectral Resolution ................... 71
5.4.1.4 Time to settle.............................................................................................. 72
5.4.1.5 Computational Costs of Investigated Algorithms .................................. 72
5.4.2 Performance Metrics..................................................................................... 74
5.4.2.1 Latency ....................................................................................................... 74
5.4.2.2 Speedup ...................................................................................................... 75
5.4.2.3 Accuracy..................................................................................................... 75
6. Results ............................................................................................................................ 76
6.1 Frequency Recognition Algorithms analysing simple Sinusoids ...................... 76
6.1.1 Latency ........................................................................................................... 76
6.1.2 Speedup .......................................................................................................... 79
6.1.3 Accuracy......................................................................................................... 81
6.1.4 Comparison of the Investigated Metrics ..................................................... 85
6.2 Frequency Recognition Algorithms analysing Musical Notes .......................... 87
6.2.1 Note C6 (1046.5Hz) for Piano, Violin, Flute and Trumpet ....................... 87
6.2.2 Note C5 (523.25Hz) for Piano, Violin, Flute and Trumpet ....................... 90
6.2.3 Note C4 (261.63Hz) for Piano, Violin, Flute and Trumpet ....................... 93
6.2.4 Comparison of Frequency Recognition Capability for Musical Notes..... 95
7. Conclusions and Future Work ..................................................................................... 97
7.1 Frequency Recognition Algorithms analysing Simple Sinusoids...................... 97
7.2 Frequency Recognition Algorithms analysing Musical Notes .......................... 98
7.3 Alternatives ............................................................................................................ 99
References ............................................................................................................................ 101
Appendix A: MIDI Numbers and Corresponding Frequencies ..................................... 103
Appendix B: Measurement Results for Sinusoidal Inputs .............................................. 104
Appendix C: Measurement Results for Inputs of Musical Notes ................................... 107
Appendix D: MatLab Script and C Source Code for the DFT ....................................... 110
Appendix E: MatLab Script and C Source Code for the FFTW and the FFT ............. 112
Appendix F: C Source Code for the Goertzel Algorithm ................................................ 120
Appendix E: C Source Code for the NDFT ...................................................................... 123
Appendix I: Academic Paper, published at the 8th IEEE ISCE, September 2004 ........ 129

vii
Table of Figures
Figure 1: MIDI notes and their according frequencies ................................................. 6
Figure 2: The Generic Musical Instrument System (GMIS)....................................... 11
Figure 3: Bit reversal of the input data......................................................................... 19
Figure 4: A basic butterfly for a 2-point DFT .............................................................. 20
Figure 5: The butterfly network for an 8-point FFT ................................................... 20
Figure 6: Filter structure of the Goertzel algorithm.................................................... 23
Figure 7: Leakage factor of 0.0 ...................................................................................... 26
Figure 8: Leakage factor of 0.1 ...................................................................................... 26
Figure 9: Leakage factor of 0.2 ...................................................................................... 26
Figure 10: Leakage factor of 0.3 .................................................................................... 26
Figure 11: Leakage factor of 0.4 .................................................................................... 26
Figure 12: Leakage factor of 0.5 .................................................................................... 26
Figure 13: Memory Map for the TMS320C6713 DSP Starter KIT ........................... 30
Figure 14: Defining hard and software interrupt in the DSP/BIOS .......................... 31
Figure 15: Source code, original and spectrum of a 5kHz input in CCS ................... 33
Figure 16: Principle of a ring buffer.............................................................................. 34
Figure 17: Principle of a ping pong buffer.................................................................... 35
Figure 18: Pseudo code for applying time measurements ........................................... 37
Figure 19: Implementation of the DFT using the MAC command ............................ 39
Figure 20: Frequency recognition in principle ............................................................. 42
Figure 21: Input signal, magnitude, real and imaginary part of a sinusoid of 1kHz 43
Figure 22: Original signal of an 1kHz sinusoid (wave file) ......................................... 46
Figure 23: Spectrum of an 1kHz sinusoid (wave file) .................................................. 46
Figure 24: Pseudo code for a 1D FFTW........................................................................ 47
Figure 25: Magnitude calculated by an 8192-point FFTW of an 1kHz sinusoid ...... 48
Figure 26: Parallel debugging ........................................................................................ 51
Figure 27: Arbitrarily chosen frequencies for the NDFT............................................ 53
Figure 28: Measurement setup for sinusoidal signals.................................................. 56
Figure 29: Measurement setup for instrumental inputs.............................................. 57
Figure 30: Spectrum vs. time for a 440Hz input .......................................................... 60
Figure 31: Spectrum vs. time for a 4186.01Hz input ................................................... 60
Figure 32: Spectrum vs. time for a 27.5Hz input ......................................................... 61
Figure 33: Spectrum vs. time for a 1046.5Hz input (piano) ........................................ 63
Figure 34: Spectrum vs. time for a 1046.5Hz input (violin) ........................................ 63
Figure 35: Spectrum vs. time for a 1046.5Hz input (flute).......................................... 64
Figure 36: Spectrum vs. time for a 1046.5Hz input (trumpet).................................... 64
Figure 37: Spectrum vs. time for a 523.25Hz input (piano) ........................................ 65
Figure 38: Spectrum vs. time for a 523.25Hz input (violin) ........................................ 65
Figure 39: Spectrum vs. time for a 523.25Hz input (flute).......................................... 66
Figure 40: Spectrum vs. time for a 523.25Hz input (trumpet).................................... 66
Figure 41: Spectrum vs. time for a 261.63Hz input (piano) ........................................ 67
Figure 42: Spectrum vs. time for a 261.63Hz input (violin) ........................................ 67
Figure 43: Spectrum vs. time for a 261.63Hz input (flute).......................................... 68
Figure 44: Spectrum vs. time for a 261.63Hz input (trumpet).................................... 68
Figure 45: Latency vs. Buffer size for a 440Hz input .................................................. 77
Figure 46: Latency vs. Buffer size for a 4186.01Hz input ........................................... 78
Figure 47: Latency vs. Buffer size for a 27.5Hz input ................................................. 78
Figure 48: Speedup vs. Buffer size for a 440Hz input.................................................. 79
Figure 49: Speedup vs. Buffer size for a 4186.01Hz input........................................... 80
Figure 50: Speedup vs. Buffer size for a 27.5Hz input................................................. 80
viii
Figure 51: Estimated frequency vs. Buffer size for a 440Hz input............................. 81
Figure 52: Absolute deviation vs. Buffer size for a 440Hz input ................................ 82
Figure 53: Estimated frequency vs. Buffer size for a 4186.01Hz input...................... 83
Figure 54: Absolute deviation vs. Buffer size for a 4186.01Hz input ......................... 83
Figure 55: Estimated frequency vs. Buffer size for a 27.5Hz input............................ 84
Figure 56: Absolute deviation vs. Buffer size for a 27.5Hz input ............................... 84
Figure 57: Estimated frequency vs. time for a 1046.5Hz input (piano) ..................... 88
Figure 58: Estimated frequency vs. time for a 1046.5Hz input (violin) ..................... 88
Figure 59: Estimated frequency vs. time for a 1046.5Hz input (flute) ....................... 89
Figure 60: Estimated frequency vs. time for a 1046.5Hz input (trumpet)................. 89
Figure 61: Estimated frequency vs. time for a 523.25Hz input (piano) ..................... 90
Figure 62: Estimated frequency vs. time for a 523.25Hz input (violin) ..................... 90
Figure 63: Estimated frequency vs. time for a 523.25Hz input (flute) ....................... 91
Figure 64: Estimated frequency vs. time for a 523.25Hz input (trumpet)................. 92
Figure 65: Estimated frequency vs. time for a 261.63Hz input (piano) ..................... 93
Figure 66: Estimated frequency vs. time for a 261.63Hz input (violin) ..................... 93
Figure 67: Estimated frequency vs. time for a 261.63Hz input (flute) ....................... 94
Figure 68: Estimated frequency vs. time for a 261.63Hz input (trumpet)................. 95

ix
List of Tables
Table 1: DTMF frequencies according to ITU-T Q.24.................................................. 2
Table 2: ITU-T Q.24 DTMF specifications..................................................................... 3
Table 3: Main properties of DTMF and MIDI based musical systems...................... 10
Table 4: The FFT algorithm (Decimation in Time) ..................................................... 16
Table 5: Decimation of input data in time and corresponding DFTs......................... 18
Table 6: Filter coefficients for the Goertzel algorithm ................................................ 23
Table 7: Estimated frequencies according to the leakage factor ................................ 25
Table 8: Comparison of the properties of window functions...................................... 27
Table 9: Possible sampling rate settings........................................................................ 32
Table 10: Frequencies and filter coefficients for 88 MIDI notes ................................ 54
Table 11: Actual buffer size requirements for a problem size N ................................ 55
Table 12: Input signal categories ................................................................................... 58
Table 13: Constraints and properties of instrument samples ..................................... 62
Table 14: Probable frequency recognition capability of instruments ........................ 69
Table 15: Fourier Transform-based algorithmic complexity ..................................... 72
Table 16: Maximum buffer size N for a latency less than 50ms ................................. 78
Table 17: Minimum buffer size for a sufficient accuracy for 440Hz.......................... 82
Table 18: Minimum buffer size for a sufficient accuracy for 4186.01Hz................... 83
Table 19: Minimum buffer size for a sufficient accuracy for 27.5Hz......................... 84
Table 20: Comparing latency and speedup for an input of 27.5Hz............................ 85
Table 21: Comparing minimum buffer sizes for a sufficient accuracy...................... 86
Table 22: MIDI numbers and corresponding frequencies ........................................ 103
Table 23: Measurement results for a sinusoidal input of 440Hz .............................. 104
Table 24: Measurement results for a sinusoidal input of 4186.01Hz ....................... 105
Table 25: Measurement results for a sinusoidal input of 27.5Hz ............................. 106
Table 26: Estimated frequencies for instrumental inputs of 1046.5Hz.................... 107
Table 27: Estimated frequencies for instrumental inputs of 523.25Hz.................... 108
Table 28: Estimated frequencies for instrumental inputs of 261.63Hz.................... 109
Table 29: MatLab script demonstrating the DFT with leakage effect ..................... 110
Table 30: Implentation of the DFT for the DSP in C................................................. 111
Table 31: MatLab script analysing wave files using the FFT ................................... 112
Table 32: Implementation of an 8192-point FFTW in C........................................... 113
Table 33: Generation of 8192 complex data elements for the FFTW in C .............. 114
Table 34: Generation of complex interleaved data for the FFT in C ....................... 115
Table 35: Calculating magnitude and maximum spectral power in C..................... 115
Table 36: Generation of twiddle factors for in C (TI FFT support files)................. 115
Table 37: Bit reversal in C (TI FFT support files) ..................................................... 119
Table 38: Implementation of the Goertzel IIR filter for the DSP in C .................... 120
Table 39: Goertzel filter bench, peak detection and evaluation in C ....................... 120
Table 40: Pre-calculated Goertzel filter coefficients.................................................. 121
Table 41: Keyboard frequencies (keyboard_notes.h) ................................................ 121
Table 42: Generation of Goertzel filter coefficients in C........................................... 122
Table 43: Implementation of the NDFT in C.............................................................. 123
Table 44: Generation of the arbitrarily chosen frequency vector in C .................... 124
Table 45: Arbitrarily chosen frequency vector (problem size N = 1024)................. 125

x
Nomenclature

ADC Analogue Digital Converter

ALU Arithmetic-Logic Unit

ANSI American National Standards Institute

API Application Program Interface

BIOS Basic Input Output System

BOSR Base Oversampling Rate

BSL Board Support Library

CCS Code Composer Studio

CD Compact Disk

CODEC Coder-Decoder

CPU Central Processing Unit

CSL Chip Support Library

DAC Digital Analogue Converter

DFT Discrete Fourier Transform

DIT Decimation In Time

DSK DSP Starter Kit

DSP Digital Signal Processor

DTMF Dual-Tone Multi-Frequency

EDMA Enhanced Direct Memory Access

FFT Fast Fourier Transform

FFTW Fastest Fourier Transform in the West

FIFO First In First Out

FIR Finite Impulse Response

GMIS Generic Musical Instrument System

xi
GPS Global Positioning Systems

HWI Hardware Interrupt

I/O Input/Output

IEEE Institute of Electrical and Electronic Engineers

IIR Infinite Impulse Response

ISCE International Symposium on Consumer Electronics

ISR Interrupt Service Routine

ITU-T International Telecommunication Union - Telecommunication Sector

LED Light Emitting Diodes

LSM Least Mean Squares

LUT Look-Up Table

MAC Multiply-ACumulate = Multiply and Add

McBSP Multichannel Buffered Serial Bus

MCLK Master Clock

MIDI Musical Instrumental Digital Interface

MIT Massachusetts Institute of Technology

MUSIC MUltiple SIgnal Classification

NDFET Normalised Discrete Frequency Estimation Technique

NDFT Non-Uniform Discrete Fourier Transform

NFFT Non-Uniform Fast Fourier Transform

PC Personal Computer

RADAR RAdio Detection and Ranging

SDRAM Synchronous Dynamic Random Access Memory

SNR Signal-to-Noise-Ratio

TI Texas Instruments

USB Universal Serial Bus

xii
List of Symbols

a0 Amplitude of direct current of the Fourier Series

ad Absolute deviation

ad min Minimum absolute deviation

α Parameter for window functions

an Amplitude of the nth cosine function of the Fourier Series

bn Amplitude of the nth sine function of the Fourier Series

∆ nMIDI Difference between two arbitrarily chosen frequencies (NDFT)

e Euler number, e ≈ 2.718281828

f Frequency domain

f CPU Frequency of the CPU

f ep Expected frequency

f es Estimated frequency

fk Frequency vector of the NDFT

f0 Fundamental frequency

fs Sampling frequency, Sampling rate

H (z ) System function

j −1

k Discrete spectral index

K Intermediate constant for the Discrete Fourier Transform, K = 2 ⋅ π / N

lt Latency

lt average Average latency

N Buffer size

n Sample index for discrete time domain signals

n MIDI MIDI number index

xiii
N min Minimum buffer size for a sufficient spectral resolution

π π ≈ 3.141592654

R Spectral resolution

R max Maximum spectral resolution

sp Speedup

t Time domain

T0 Period of the fundamental frequency

Ts Period of the sampling frequency

t settle Time to settle

ω0 Angular frequency

− j⋅ ⋅k
W Nk Twiddle factors, WNk = e N

x(t ) Continuous time signal

X(f ) Continuous frequency spectrum

x[n] Discrete time signal

X [k ] Discrete frequency spectrum

xiv
1. Introduction

Frequency recognition is an important task, not only in many scientific disciplines such
as astronomy, physics or engineering but also in everyday life like in telephony, medical
applications or consumer electronics. Frequency recognition is used in many applications,
for example spectrum analysers and seismographs to analyse earth quakes which make
life both more convenient and secure.

In consumer electronics, musical systems have found a broad distribution and have a
remarkable market potential. Playing and listening to electronic music is becoming more
and more important as a leisure activity, for young and old alike. Therefore, the design of
a Generic Musical Instrument System (GMIS), allows musicians the chance to
experiment with other musical instrument sounds without actually having to learn them.

One very widely spread application of frequency recognition is used in telephony and is
called Dual-Tone Multiple-Frequency (DTMF). Its advantageous, well-proven algorithms
could be adapted to musical systems which show similarities to DTMF systems. These
comparable properties of DTMF systems have to be analysed and their usability has to be
evaluated with respect to musical systems such as the GMIS.

Therefore, four different Fourier transform-based frequency recognition algorithms are


subject to an analysis: the Discrete Fourier Transform (DFT) taken as a baseline to
evaluate all algorithms, the Fast Fourier Transform (FFT) which is the workhorse in
many engineering applications, the Goertzel algorithm and the Non-Uniform Discrete
Fourier Transform (NDFT) which are both successfully used in DTMF systems.

These frequency recognition algorithms are implemented on a Texas Instruments (TI)


TMS320C6713 digital signal processor (DSP) core in order to estimate the frequency of
the audio signal in real time. These frequency recognition algorithms are evaluated by
selected criteria in terms of speed and accuracy by using both simple sinusoids and
musical notes played by instruments as input signals. This analysis allows a solid
conclusion to be drawn regarding the application of the frequency recognition algorithms
in musical systems such as the GMIS.

1
1.1 Background

1.1.1 Dual-Tone Multi-Frequency (DTMF) Systems

Dual-Tone Multi-Frequency (DTMF) is used for remote mono-directional user-to-


machine communication in telephony, service selection in Intelligent Networks and user-
interactive phone services such as telephone banking to obtain a desired service. The
addressed machine is controlled by an unique mixture of two standardised sinusoids [1].
In a telephone handset, the 16 number keys are arranged in a grid according to table 1.

Table 1: DTMF frequencies according to ITU-T Q.24

High group
f in Hz
1209 1336 1477 1633

1 2 3 A
697
abc def
Low group

4 5 6 B
770
ghi jkl mno
7 8 9 C
852
pqrs tuv wxyz
* 0 # D
941

For each column and row, one sinusoid of a standardised frequency is allocated. When a
button is pressed, the mixture of two of these frequencies is sent to the exchange.
Therefore, in order for the exchange to determine the key being pressed, accurate
frequency recognition is required to separate the two tones. The accuracy of this
recognition is very high in order to comply with the ITU-T specification [1] listed in table
2.

DTMF systems are well-proven and have several advantages which make them
convenient for signal processing and frequency recognition. For instance, DTMF systems
operate on a low sampling frequency of fs = 8000Hz. Consequently, compared to other
systems with higher sampling rates, the number of sampling points per second of a signal
is smaller than sampled. Taking a sampling rate of fs = 44100Hz as an example, the
number of sampling points is smaller by a factor of approximately 5.51.

2
Table 2: ITU-T Q.24 DTMF specifications
Frequency tolerances
Acceptance of frequency ≤ 1.5%
Rejection of frequency ≥ 3.5%
Signal duration
Accepted frequency ≥ 23ms
Rejected frequency ≥ 40ms
Pause between two tones ≥ 40Ms
Signal interruption ≤ 10ms
Power difference between frequencies (twist)
Low frequency group ≤ 8dB
high frequency group ≤ 4dB
Signal power specification
Signal-to-Noise-Ratio (SNR) ≥ 15dB
Signal power ≥ - 26dB

Regarding the requirement on the spectral resolution for DTMF signals for the same
example, it can be clearly stated that for the same buffer length N, this spectral resolution
for DTMF systems is smaller by the same factor, too, since the frequency bin is smaller
for a lower sampling rate. This is due to the ratio of the sampling rate and the buffer size
N. Having a fixed buffer size N for two systems, the demand for a spectral resolution
increases with the sampling rate.

Another feature that DTMF systems have that can be used to simplify the processing is
the use of simple pure sinusoidal signals only, because these signals are meant to control
machines and so these signals have to be unique. The frequency recognition algorithms
used to determine these signals, simply have to perform a simple peak detection after
having estimated the spectrum and do not have to take the shape of the spectrum into
account.

Also, a benefit for DTMF systems is the limitation of the bandwidth they have to deal
with. Frequency recognition can be restricted to a minimum frequency of 697Hz and a
maximum frequency of 1633Hz. The fact that the 8 standardised frequencies of interest
are known in advance and the limited bandwidth make the design of filters simpler.
3
One very important and requirement for the design of frequency recognition algorithms
in DTMF systems is the fact that the tolerance of the frequency recognition is only 1.5%.
This might not sound much, but actually regarding the lowest frequency of 697Hz, the
absolute tolerance is 10.46Hz. This is, anticipatory, a relatively big tolerance, compared
to other systems like musical systems as described in the following system.

Summing up, DTMF systems benefits from the following characteristics

• Low sampling rate of fs = 8kHz


• 8 standardised simple sinusoidal signals, known in advance
• Limited bandwidth: 697Hz - 1633Hz
• Minimum absolute tolerance: 10.46Hz (1.5%)

These advantages are taken into account for DTMF detectors and are used to reduce
computational requirements and increase accuracy when developing frequency
recognition algorithms for the purpose of DTMF detection.

4
1.1.2 Musical Instrument Digital Interface (MIDI) in Musical Systems

The Musical Instrument Digital Interface (MIDI) version 1.0 was defined by a
consortium of musical instrument manufacturers, The International MIDI Association
[2], in 1983. The main purpose was to set up a standard interface in order to make
electronic musical instruments of different manufacturers compatible among each other.
The communication of these musical devices increased the sales quantities but what is
more, this standard also caused a boom in the composition, development and recording of
electronic music among musicians who cannot afford a professional recording studio
[3,4].

MIDI notes and their corresponding frequencies are the basis for the following
investigations. An electronic keyboard has 88 keys, starting with MIDI note #21 until
MIDI note #108, and has its origin in the theory of the equal tempered piano [5]. Based
on note A4 (440Hz) [6], each neighboured note is one 12th part of an octave distant. This
distance is also called tempered semitone [5]. Between two octaves, the notes’
frequencies double. Taking these principles into account, the corresponding frequency of
each MIDI note is [6]

nMIDI − 69
f (n MIDI ) = 440 ⋅ 2 12
Hz
for 21 ≤ n MIDI ≤ 108 (1)

where nMIDI is the MIDI note number.

A complete overview of the MIDI notes, their corresponding frequencies, the differences
between neighboured MIDI notes and the resulting tolerance (equals to half the
difference) is given in appendix A. The target frequency range, therefore, will be within
the minimum and maximum MIDI note of an electronic keyboard, i.e. the bandwidth of
27.5Hz and 4186.01Hz as shown in figure 1.

5
MIDI
Note Frequency
number

21 A0 27.50Hz
22 A0# 29.14Hz
23 B0 30.87Hz
24 C1 32.70Hz
25 C1# 34.65Hz
26 D1 36.71Hz
27 D1# 38.89Hz
28 E1 41.20Hz
29 F1 43.65Hz
30 F1# 46.25Hz
31 G1 49.00Hz
32 G 1# 51.91Hz
33 A1 55.00Hz
34 A1# 58.27Hz
35 B1 61.74Hz
36 C2 65.41Hz
37 C2# 69.30Hz
38 D2 73.42Hz
39 D2# 77.78Hz
40 E2 82.41Hz
41 F2 87.31Hz
42 F2# 92.50Hz
43 G2 98.00Hz
44 G 2# 103.83Hz
45 A2 110.00Hz
46 A2# 116.54Hz
47 B2 123.47Hz
48 C3 130.81Hz
49 C3# 138.59Hz
50 D3 146.83Hz
51 D3# 155.56Hz
52 E3 164.81Hz
53 F3 174.61Hz
54 F3# 185.00Hz
55 G3 196.00Hz
56 G 3# 207.65Hz
57 A3 220.00Hz
58 A3# 233.08Hz
59 B3 246.94Hz
60 C4 261.63Hz
61 C4# 277.18Hz
62 D4 293.66Hz
63 D4# 311.13Hz
64 E4 329.63Hz
65 F4 349.23Hz
66 F4# 369.99Hz
67 G4 392.00Hz
68 G 4# 415.30Hz
69 A4 440.00Hz
70 A4# 466.16Hz
71 B4 493.88Hz
72 C5 523.25Hz
73 C5# 554.37Hz
74 D5 587.33Hz
75 D5# 622.25Hz
76 E5 659.26Hz
77 F5 698.46Hz
78 F5# 739.99Hz
79 G5 783.99Hz
80 G 5# 830.61Hz
81 A5 880.00Hz
82 A5# 932.33Hz
83 B5 987.77Hz
84 C6 1046.50Hz
85 C6# 1108.73Hz
86 D6 1174.66Hz
87 D6# 1244.51Hz
88 E6 1318.51Hz
89 F6 1396.91Hz
90 F6# 1479.98Hz
91 G6 1567.98Hz
92 G 6# 1661.22Hz
93 A6 1760.00Hz
94 A6# 1864.66Hz
95 B6 1975.53Hz
96 C7 2093.00Hz
97 C7# 2217.46Hz
98 D7 2349.32Hz
99 D7# 2489.02Hz
100 E7 2637.02Hz
101 F7 2793.83Hz
102 F7# 2959.96Hz
103 G7 3135.96Hz
104 G 7# 3322.44Hz
105 A7 3520.00Hz
106 A7# 3729.31Hz
107 B7 3951.07Hz
108 C8 4186.01Hz

Figure 1: MIDI notes and their according frequencies

6
In terms of digital signal processing, the advantages of the Musical Instrument Digital
Interface (MIDI) used in musical systems (in particular of a keyboard), are worked out in
this section.

One major important issue is the limited bandwidth with a minimum frequency of 27.5Hz
and a maximum frequency of 4186.01Hz. Frequency recognition algorithms have to be
designed with respect to this bandwidth which limitation reduces their complexity
immensely. Also, since all 88 frequencies of interest are standardised [2], the algorithms
can be developed by referring to these expected frequencies.

There are some considerable disadvantages of musical systems, however, which have to
be faced when developing frequency recognition algorithms. Mostly, musical systems use
a high sampling frequency of fs = 44100Hz to meet the Nyquist-Shannon theorem [7,8]
and to ascertain CD quality as described in the “Red Book” by Phillips [9] at the same
time.

The Nyquist-Shannon states that the sampling rate fs has to be greater than the twice
highest frequency in the signal, in order to be able reconstruct this signal correctly. If this
condition is not fulfilled, all the frequencies above the half the sampling rate, i.e. the
Nyquist frequency, will appear as lower frequencies in the reconstructed signal which is
called “aliasing”. Initially formulated in 1928 by Harry Nyquist [7], the Nyquist-Shannon
theorem was mathematically proven by Claude Elwood Shannon [8] in 1949.

Since the audible range of human is within 0Hz and 20000Hz [5] and is therefore below
the Nyquist frequency of fs/2 = 22050Hz, the Nyquist-Shannon sampling theorem is
fulfilled using a sampling rate fs = 44100Hz.

As discussed in the section 1.1.1, it has to be taken into account that with a high sampling
rate the number of sampling points increases. Sampling a signal of one second with a
sampling rate of fs = 44100Hz, a buffer size of N = 44100 has to be allocated.

Also noteworthy is, that the higher the sampling rate, the need for a high spectral
resolution becomes more important. Having a buffer size of N = 1024 for a system with a
sampling rate of fs = 44100Hz, the frequency bins are 43.07Hz large, whereas systems
with a sampling frequency of fs = 8000Hz have to cope with frequency bins of a size of
7.81Hz for the same buffer size.
7
Though there is a constant tolerance of 2.81% only and one might think this is relatively
high, the non-uniform distribution of the 88 frequencies of interest, especially for the
lower frequencies however, result in an absolute tolerance of minimum 0.82Hz which
makes frequency recognition more difficult.

Recapitulating, the properties of musical systems as analysed above are listed as follows:

• Sampling rate of fs = 44.1kHz


• 88 standardised MIDI frequencies
• Limited bandwidth: 27.5Hz - 4189.01Hz
• Minimum absolute tolerance: 0.82Hz (2.81%)

8
1.1.3 Comparing DTMF and Musical Systems using MIDI

Comparing DTMF and musical systems using MIDI, the main outstanding issue is the
advantage of having a limited bandwidth in both systems (697Hz - 1633Hz and 27.5Hz -
4186.01Hz respectively) which makes frequency recognition more convenient.
Additionally, the previous knowledge of the frequencies of interest for both systems (8
and 88 respectively) is benefiting for the design of frequency recognition algorithms.

However, an obvious difference between DTMF and musical systems is the use of
different sampling rates (8kHz and 44.1kHz respectively). Generally, the higher the
sampling rate the more sampling points have to be processed. This has a direct influence
on the computational costs, as analysed in section 5.4.1.5, and is an important fact to
consider.

There is also a difference concerning the absolute frequency range. Musical systems have
a minimum frequency of 27.5Hz and a maximum frequency of 4186.01Hz, whereas
DTMF systems have a smaller bandwidth, limited by 697Hz and 1633Hz.

Another issue to consider is the purpose of the signals in different both systems. DTMF
has been specified for a remote user-to-machine communication and is used as a control
function in contrast to musical systems, where sound quality is important. That is why the
common signal shape of DTMF systems is simply sinusoidal and as apposed to the
signals found in musical systems which are musical notes having complex waveforms.
Furthermore, in the course of this observation and in terms of accuracy, the higher the
sampling rate is, the higher are the frequency bins.

DTMF systems and musical systems also differ in the frequency gap of two neighbouring
signals. The spectral difference in DTMF systems between two neighboured signals is
between 73Hz and 156Hz. Hence, according to the ITU-T Q.24 specification, the
maximum tolerated deviation of a frequency is 1.5% [1]. Thus, the minimum absolute
tolerance of DTMF systems is 10.46Hz. In MIDI based musical systems, however,
musical note frequency spacings, for most of the lower frequencies of interest, are closer
together. In order to correctly ascertain which MIDI command is to be produced, the
accuracy of any recognition algorithms must be at least half the frequency gap between
MIDI channels. In this case, the spectral difference between two adjoining notes ranges
9
from 1.64Hz to 234.94Hz [2]. That means an accuracy of 0.82Hz to 117.47Hz is required
(based on the A440 Standard [6]), which is a constant tolerance of 2.81%. Although this
margin is greater than the tolerance for DTMF systems, each algorithm being used has to
be accurate within this tolerance. Table 3 contrasts the main characteristics and properties
of DTMF systems and MIDI based musical systems.

Table 3: Main properties of DTMF and MIDI based musical systems


DTMF systems Musical systems
(MIDI based, keyboard)
Sampling rate 8kHz 44.1kHz
Number of frequencies of interest 8 88
Limited Bandwidth 697Hz-1633Hz 27.5Hz-4186.01Hz
Tolerance ≤1.5% ≤2.81%
Minimum absolute tolerance 10.46Hz 0.82Hz
Shape of signals simple sinusoids complex musical notes

Since DTMF systems and musical systems are equal in structure, the adaptation of
frequency recognition methods used in DTMF systems is subject to further investigation.
However, the differences between both systems should not to be underestimated. These
differences have to be taken into account when designing the frequency recognition
algorithms.

1.2 The Generic Musical Instrument System (GMIS)

Among young musicians, playing electronic instruments has become more and more
popular. At the same time, the attraction towards learning classical instruments (for
example flute, saxophone, etc) has decreased despite their importance in music
composition. The design of a Generic Musical Instrument System (GMIS), therefore,
allows musicians the opportunity to experiment with other musical instrument sounds
without actually having to learn how to play them. The advantage to this is the reduction
in funding required to run a professional band and also that a keyboard player is no
longer necessary (the traditional method of solving this problem).

10
The GMIS is a system which can make any instrument sound like any other instrument.
In order to attain maximum benefits, the system should operate in real time. The
advantage of real time behaviour is the musician’s chance to listen to the result
immediately and actually compose by ear. Figure 2 depicts the top level view of the
GMIS.

The GMIS consists of a common Digital Signal Processor (DSP) system [10] which is
used to recognise the frequencies of the incoming audio data’s input in real time. The
time and amplitude continuous audio data passes an anti-aliasing band-limiting low pass
filter, before a sample and hold unit samples the signals in time. There is still continuous
amplitude whose infinite values have to be quantised by the analogue to digital converter
(ADC). The time and value discretised data can now be processed by the digital signal
processor (DSP). After the processing the digital to analogue converter (DAC) converts
the digital data into an analogue form. Before the audio data is output, another low pass
filter smoothes the signal by removing the high frequency components which are an
undesired by-product of the converting process.

In actual fact, the GMIS does not use the post processing units, i.e. the digital to analogue
converter (DAC) and the anti aliasing low pass filter. The recognised frequency is
calculated and is output as a numerical value. A frequency to MIDI conversion unit
converts this value into the corresponding Musical Instrument Digital Interface (MIDI)
[2] command which can be further processed by any MIDI device.

This dissertation analyses the frequency recognition part only and does not carry out
further investigations on the frequency to MIDI conversion.

Figure 2: The Generic Musical Instrument System (GMIS)

11
2. Background Theory

2.1 Fourier transform-based Frequency Recognition Algorithms

In 1807, Jean Baptiste Joseph Fourier (1798 - 1830) developed the theory about the
Fourier Series but was rejected by his supervisors Lagrange, Laplace and Legrendre [11].
Finally, in 1822, he published his work in his book “Théorie analytique de la chaleur”
[12]. More or less as a side product of this work, he derived the so-called Fourier Series,
where he proved that any periodic signal consists of an infinite number of sinusoids and a
constant. His theories have revolutionised science and are indispensable in many
technical applications.

In this section, after a brief definition of the Fourier Series and the Fourier Transform,
four Fourier transform-based algorithms are going to be introduced. These algorithms are
the Discrete Fourier Transform (DFT) and its faster implementation Fast Fourier
Transform (FFT), the Goertzel algorithm, and the Non-Uniform Discrete Fourier
Transform (NDFT).

2.1.1 The Fourier Series

With the Fourier Series, it is possible to create any periodic signal, x(t), in the time
domain from the sum of an infinite number of sinusoids, i.e. sine and cosine functions,
which are integer multiples of the fundamental frequency, f0. The Fourier Series is
defined as [13]:


a0
x(t ) = + ∑ (a n ⋅ cos(n ⋅ ω 0 ⋅ t ) + bn ⋅ sin (n ⋅ ω 0 ⋅ t )) n = 0,1,..., ∞ (2)
2 n =1

Where a0 is the amplitude of the direct current component, n is the current number of the
sinusoidal component, an and bn the amplitude of the nth sine and nth cosine function
respectively, t the representative of the time domain, ω0 the angular frequency, with w0 =
2 ·π · f0, where f0 is the fundamental frequency. The even and odd parts are denoted in
equation (3) and (4) respectively

12
T0
+
2
2 (3)
an =
T0
⋅ ∫ x(t ) ⋅ cos(n ⋅ ω ⋅ t )dt
T0
0

2

T0
+
2
2 (4)
bn =
T0
⋅ ∫ x(t ) ⋅ sin (n ⋅ ω ⋅ t )dt
T0
0

2

where T0 is the period of fundamental frequency, f0, of the signal, with ω 0 = 2π ⋅ f 0 .

2.1.2 The Fourier Transform

The Fourier Series is a special case of the Fourier integral [13] and is valid for periodic
signals only [10]. For any non-periodic signal, the Fourier Series cannot be applied
anymore and the Fourier Transform has to be taken into account and is defined as [13]:

+∞
X(f )= ∫ x(t ) ⋅ e
− j ⋅ω 0 ⋅t
dt (5)
−∞

where t and f stand for the time and frequency domain respectively; x(t) represents the
continuous time signal and X(f) its spectrum in the frequency domain. The indicator for
the imaginary part j = − 1 and ω0 is the angular frequency and is defined for the
Fourier Transform as:

ω0 = 2π ⋅ f (6)

with equation (6), the Fourier Transform can finally be written as

+∞
X(f )= ∫ x(t ) ⋅ e
− j ⋅ 2π ⋅ f ⋅t
dt (7)
−∞

Since the Fourier Transform is valid for infinite continuous signals only and a numerical
implementation is just possible with finite discrete signals, due to limited memory and
computation time, the Discrete Fourier Transform (DFT) can be derived.

13
2.1.3 The Discrete Fourier Transform (DFT)

The easiest and most direct way to obtain the discrete spectrum of a signal is the Discrete
Fourier Transform (DFT) [13]. It is also the basis for the four Fourier transform-based
frequency recognition algorithms described in section 5.4.2.2. Because the DFT is the
slowest algorithm, it is also taken as a baseline to evaluate all the other investigated
algorithms.

2.1.3.1 Mathematical Derivation of the DFT

Again, the basis of the DFT is the Fourier Transform as defined in equation (5)

+∞
X(f )= ∫ x(t ) ⋅ e
− j ⋅ 2 π ⋅ f ⋅t
dt (8)
−∞

Both the time and the frequency domain have to be discretised due to the lack of infinite
resources [13]. The Fourier integral is replaced by a discrete sum over N samples and the
continuous domains by a sampled equivalent as expressed in (9) and (10)

t → n ⋅ Ts n = 0,1,..., N − 1 (9)

fs
f →k⋅ k = 0,1,..., N − 1 (10)
N

where n represents the sample index for discrete time domain signal values and k the
discrete spectral index. The sampling frequency fs and the accordant period Ts are linked
via the relation

1 (11)
Ts =
fs

According to equations (9) and (10), the DFT can be rewritten as

 f 
− j ⋅2π ⋅ k ⋅ s ⋅( n ⋅Ts )
 f  N −1
X  k ⋅ s  = ∑ x[n ⋅ Ts ] ⋅ e  N 
(12)
 N  n =0

14
which is


 f s  N −1
X  k ⋅  = ∑ x[n ⋅ Ts ] ⋅ e N
− j ⋅ ⋅k ⋅n
(13)
 N  n =0

Due to the fact, that in practical applications the number of samples N, the sampling
frequency fs (and so its period Ts, according to equation (11)) are fixed, they can be
considered as constant and the DFT is finally formulated more convenient as

N −1 2π

X [k ] = ∑ x[n] ⋅ e
− j⋅ ⋅k ⋅ n
k = 0,1,..., N − 1
N
(14)
n=0

Equation (14) is the definition of the Discrete Fourier Transform (DFT), with x[n] as the
sampled time signal and X[k] as the representative of the discrete frequency spectrum.

2.1.3.2 Interpretation of the DFT

The DFT is a pure mathematical application of transforming signals from the time
domain into the frequency domain. The interpretation of the result has to be done
separately in a successive step. Equation (15) evaluates the actual frequencies at each
discrete equidistant spectral index value k:

f (k ) = k ⋅
fs
N k = 0,1,..., N − 1 (15)

15
2.1.4 The Fast Fourier Transform (FFT)

The Fast Fourier Transform (FFT) is not an independent time to frequency domain
transform but an effective recursive algorithm to calculate the DFT [7, 9] and was
developed by Cooley and Tukey in 1965. It has revolutionised digital signal processing
and is the basis for many real time applications whenever a transform of signals from
time to frequency domain is required.

2.1.4.1 Decimation of the DFT in Time (DIT)

The FFT takes advantage of reducing redundant calculation of DFT coefficients, also
called twiddle factors. A prerequisite, therefore, is that the number of samples or the
buffer size, N, is a power of two. If this condition is not given, zero-padding (in other
words, adding zeros at the end of the input buffer) has to be applied. Then, according to
the principle of divide and conquer, the input samples have to be re-ordered N times until
N/2 2-point DFTs can be calculated. This process is also known as bit reversal and will
be discussed in section 2.1.4.3. Starting with the calculation of the 2-point DFTs, this
procedure follows log2(N) times with N/4 4-point DFTs, then with N/8 8-point DFTs
until the (N/N) N-point DFT is reached. This computational part is also known as
butterfly computation [10] and will be explained in section 2.1.4.4. The whole algorithm
as described above and is summed up in table 4.

Table 4: The FFT algorithm (Decimation in Time)


Step # Action Comment
Zero padding (add zeros to the
The FFT requires N = 2m (with m as
0 buffer), if the number of samples N is
an integer number) input samples.
not to the power of two.
Bit-reverse input samples until N/2
1 input sample pairs for N/2 2-point This stage requires N steps.
DFT are reached.
Apply butterfly computations
2 This stage needs log2(N) steps.
recursively.

16
2.1.4.2 Mathematical Approach

As previously discussed, the DFT is the basis for the FFT as described in equation (14)

N −1 2π

X [k ] = ∑ x[n] ⋅ e
− j⋅ ⋅k ⋅ n
k = 0,1,..., N − 1
N
(16)
n=0

and can be rewritten in order to exploit the redundancy of the twiddle factors

N −1
X [k ] = ∑ x[n] ⋅ W Nn⋅k k = 0,1,..., N − 1 (17)
n =0

The twiddle factors are defined as


− j⋅ ⋅k
W =e
k
N
N
(18)

Following the principle of divide and conquer, the DFT can be split up into two half size
N-point DFT, the even and the odd part as shown in equation (19) and (20) respectively.

X [k ] = X even [k ] + X odd [k ] k = 0,1,..., N − 1 (19)

N −1 N −1
2 2
X [k ] = ∑ x[2 ⋅ n]⋅ W 2⋅n⋅k
N + ∑ x[2 ⋅ n + 1]⋅ W ( N
2⋅n +1)⋅k
k = 0,1,..., N − 1 (20)
n =0 n =0

In order to be able to tap the full potential of the computational redundancy, equation (20)
can be transformed into

N −1 N −1
2 2
X [k ] = ∑ x[2 ⋅ n]⋅ W 2⋅n⋅k
N +W ⋅ k
N ∑ x[2 ⋅ n + 1]⋅ W 2⋅n⋅k
N k = 0,1,..., N − 1 (21)
n =0 n =0

 2π  2π
2⋅ − j ⋅ ⋅n⋅k  − j⋅ ⋅n ⋅k
2⋅n⋅k
Considering that W N =e  N 
=e N /2
= W Nn⋅/k2 which has to be calculated only
once, the equation (22) is obtained

N −1 N −1
2 2
X [k ] = ∑ x[2 ⋅ n]⋅W n ⋅k
N /2 +W ⋅ k
N ∑ x[2 ⋅ n + 1]⋅W n⋅k
N /2 k = 0,1,..., N − 1 (22)
n=0 n =0

17
Finally, it can be concluded that

X [k ] = X 11[k ] + WNk ⋅ X 12 [k ] k = 0,1,..., N − 1 (23)

This divide and conquer process continues until a basis of N/2 2-point DFTs is reached.
The principle remains always the same: Two DFTs of equal length have to be calculated
at the same time, whereas the DFT with the odd indices needs to be multiplied with
2⋅π
− j⋅ ⋅k
W Nk = e N
. The advantage of having twiddle factors is that they have to be calculated
log2(N) times only, instead of N2 as it is with a common DFT. Table 5 gives an overview
of the development of an 8-point-FFT. The time domain input data is decimated and the
different DFTs are applied at the same time. Due to the algorithms recursive character, all
DFTs can be calculated only if the 2-point DFTs are be calculated.

Table 5: Decimation of input data in time and corresponding DFTs


N-point Decimation of input data in time
8 x[n] = {x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]}

4 x11 [n] = {x[0], x[2], x[4], x[6]} x12 [n] = {x[1], x[3], x[5], x[7]}

2 x21 [n] = {x[0], x[4]} x 22 [n] = {x[2], x[6]} x 23 [n] = {x[1], x[5]} x 24 [n] = {x[3], x[7]}

N-point N-point DFT


8 X [k ] = X 11 [k ] + W Nk ⋅ X 12 [k ]

4 X 11 [k ] = X 21 [k ] + W Nk / 2 ⋅ X 22 [k ] X 12 [k ] = X 23 [k ] + WNk / 2 ⋅ X 24 [k ]

2 X 21 [k ] = x[0] + WNk / 4 ⋅ x[4] X 22 [k ] = x[2] + WNk / 4 ⋅ x[6] X 23 [k ] = x[1] + WNk / 4 ⋅ x[5] X 24 [k ] = x[3] + W Nk / 4 ⋅ x[7]

Technically, the decimation of the input data in time is done by a bit reversal of the
samples’ physical addresses as explained in the following section.

18
2.1.4.3 Bit Reversal

As figured out in the previous section, the key to the success of the FFT is the use of the
butterfly network, which takes log2(N) stages. A preliminary for using the butterfly
network is the re-ordering of the input data in the time domain. This preparation of the
data can be achieved by a bit reversal of the samples’ physical addresses as shown in
figure 3. This step of the algorithm takes N stages.

2.1.4.4 The Butterfly Network

The bit reversal is a preparation of the input data for the butterfly network which is a
recursive application of N DFTs. Starting with N/2 2-point DFTs, which are the basis for
N/4 4-point DFTs, the recursive computation will be applied until the (N/N) N-point DFT
is reached. The whole process of applying the butterfly network takes log2(N) stages.

original original address bit-reversed address bit-reversed


input buffer of buffer element of buffer element input buffer

x[0] 000 000 x[0]

x[1] 001 100 x[4]

x[2] 010 010 x[2]

x[3] 011 110 x[6]

x[4] 100 001 x[1]

x[5] 101 101 x[5]

x[6] 110 011 x[3]

x[7] 111 111 x[7]

Figure 3: Bit reversal of the input data

19
bit-reversed spectral
input buffer output buffer

x[0] X[0]

x[1] X[1]
W2k −1
Figure 4: A basic butterfly for a 2-point DFT

In figure 4, a basic butterfly for a 2-point DFT is shown. Taking the bit reversed input
data as a basis, the twiddle factors WNn are multiplied with the input sample with the odd
index, whereas the odd indexed spectral component is additionally multiplied by -1.
Mathematically interpreted, figure 4 can also be written as in two equations as

X [0] = x[0] + W20 ⋅ x[1] (24)

X [1] = x[0] − W21 ⋅ x[1] (25)

By applying the butterflies, the redundancy of the twiddle factors can be exploited for the
computation of the FFT, because they have to be calculated only once but can be applied
twice for each butterfly. This fact is illustrated in figure 5, which shows an 8-point DFT
with 8 / 2 = 4 twiddle factors ( W80 , W81 , W82 and W83 ) which are only needed.

bit-reversed spectral
intermediate intermediate
input buffer output buffer
result result

x[0] X21[0] X11[0] X[0]

x[4] X21[1] X11[1] X[1]


W80 −1

x[2] X22[0] X11[2] X[2]


W80 −1

x[6] X22[1] X11[3] X[3]


W80 −1 W82 −1

x[1] X23[0] X12[0] X[4]


W80 −1
x[5] X23[1] X12[1] X[5]
W80 −1 W81 −1
x[3] X24[0] X12[2] X[6]
W80 −1 W82 −1

x[7] X24[1] X12[3] X[7]


W80 −1 W82 −1 W83 −1

Figure 5: The butterfly network for an 8-point FFT

20
2.1.4.5 Interpretation of the FFT

Due to the fact that the FFT is an algorithm that applies the DFT in a very effective way,
the interpretation of the result of the FFT is the same approach as with the DFT.
Following equation (15), the actual frequencies again are evaluated at each discrete
equidistant spectral index value k.

2.1.5 The Non-Uniform Discrete Fourier Transform (NDFT)

The disadvantage of the DFT and FFT is the use of an evenly spaced frequency range
which leads into a transform of the whole frequency spectrum for the sampling rate fs as a
constraint. With the Non-Uniform Fourier Transform (NDFT) [14] it is possible, to
analyse arbitrary frequency ranges with irregular intervals. Therefore, an increase of
accuracy is possible by the application of a well-conditioned frequency vector.

2.1.5.1 Mathematical Derivation of the NDFT

Considering equation (14) of the DFT and taking the equidistant sampled frequency
domain in equation (10) into account with

fk k
=
fs N k = 0,1,..., N − 1 (26)

where fs is the sampling frequency, N the number of samples and f k = [ f 0 , f1 ,..., f N −1 ]


the arbitrary chosen frequency at k, the DFT can be rewritten as a NDFT:


N −1 − j⋅ ⋅ f k ⋅n
X (k ) = ∑ x(n) ⋅ e fs
k = 0,1,..., N − 1 (27)
n=0

The NDFT has still a complexity of N2 but due to the vector of arbitrarily chosen
frequencies, it is more accurate within the desired range. Everything outside that range
will be of a lesser accuracy but as this range is not required and can be ignored. The
vector itself holds the relevant frequencies of interest with well-conditioned arbitrarily
chosen frequencies in between these frequency points as to be discussed in section 4.2.3.

21
2.1.5.2 Interpretation of the NDFT

The interpretation of the NDFT’s results is raised by assigning the discrete non-
equidistant spectral index value k directly to the arbitrarily chosen frequency vector fk
(28) after having estimated the spectrum.

f (k ) = f k = [ f 0 , f 1 ,..., f N −1 ] k = 0,1,..., N − 1 (28)

2.1.6 The Goertzel Algorithm

Another effective derivative of the DFT is the Goertzel algorithm [14] which found its
earliest formulation in 1958. It is a widely-used algorithm used for DTMF [1]
applications. As already stated, DTMF systems benefit from their advantages of having a
limited bandwidth of 697Hz minimum and 1633Hz at most and the knowledge of the 8
frequencies of interest in advance. Different from DFT and FFT, the Goertzel algorithm
does not regard the whole frequency spectrum. These advantages can be used in the
adaptation of the Goertzel algorithm for musical systems, since the frequency range is
also known from 27.5Hz to 4186.01Hz (see appendix A) as well as the number of
expected frequencies of interest which is 88. Therefore, it is only necessary to perform an
analysis over this range hence fewer points are required for the computation.

2.1.6.1 Mathematical Derivation of the Goertzel Algorithm

The Goertzel algorithm is a filter bench consisting of recursive second order Infinite
Impulse Response (IIR) filters [15]. An example of these filters is depicted in figure 6. Its
system function can be deduced from its structure and is stated in equation (29) with the
filter coefficients listed in table 6.

b0 ⋅ z −0 + b1 ⋅ z −1
H (z ) =
1 + a1 ⋅ z −1 + a2 ⋅ z − 2 (29)

22
qk [n]
x[n] + + y k [n]
b0

z-1

+
a1 b1

z-1
a2
Figure 6: Filter structure of the Goertzel algorithm

Table 6: Filter coefficients for the Goertzel algorithm

Feed forward section Recursive section

 2π 
b0 = 1 a1 = 2 ⋅ cos ⋅k
 N 

b1 = −e
− j⋅
N
⋅k
a 2 = −1

Inserting these coefficients into the system function, equation (30) is obtained


− j⋅ ⋅k
1− e ⋅ z −1
H (k , z ) =
N
k = 0,1,...,88 (30)
 2π  −1
1 − 2 ⋅ cos ⋅ k  ⋅ z + z −2
 N 

fk
With respect to equation (10) k = ⋅ N and
fs

2π f
ωk = ⋅ k = 2π ⋅ k
k = 0,1,...,88 (31)
N fs

The system function can be rewritten as

1 − e − j⋅ωk ⋅ z −1
H (k , z ) = k = 0,1,...,88 (32)
1 − 2 ⋅ cos(ω k ) ⋅ z −1 + z −2

23
Denoting the output signal in equation (33) and regarding the intermediate values (34)

y k [n] = q k [n] − e − j⋅ωk ⋅ q k [n − 1] n = 0,1,..., N − 1 and k = 0,1,...,88 (33)

qk [n] = 2 ⋅ cos(ω k ) ⋅ qk [n − 1] − qk [n − 2] + x[n] n = 0,1,..., N − 1 and k = 0,1,...,88 (34)

where the initial conditions are

qk [− 1] = qk [− 2] = 0 k = 0,1,...,88 (35)

The recursively calculated output signal finally is

y k [n] = a k ⋅ q k [n − 1] − q k [n − 2] + x[n] − e − j⋅ωk ⋅ q k [n − 1] k = 0,1,...,88 (36)

2.1.6.2 Interpretation of the Goertzel Algorithm

The highest energetic spectral index value k holding the signal’s maximum power is a
result of the digital filter’s output and is then assigned to the equivalent 88 keyboard
frequencies.

24
2.2 Leakage Effect

Leakage is an undesired widening of a spectrum and is due to incoherent sampling, i.e. a


periodic signal [13] is not windowed within an integer multiple of its period. The leakage
effect finds is maximal if the window is exactly between two periods, i.e. if the leakage
factor of 0.5.

A MatLab simulation of the Discrete Fourier Transform (DFT) (appendix D) estimating


the spectra of an sinusoidal signal of 1KHz with different leakage factors results in table
7. A sampling rate of fs = 44100Hz and a rectangular window have been used to
discretise the signal.

Table 7: Estimated frequencies according to the leakage factor


Leakage factor Estimated frequency [Hz]
0.0 1000.000
0.1 999.001
0.2 998.004
0.3 997.009
0.4 996.016
0.5 995.025

It can clearly be seen that, as expected, the higher the leakage factor is, the more difficult
is it to determine the maximum peak of the spectra due to a higher the leakage effect.

Figures 7 - 12 show the results listed in table 7 obtained with the same MatLab
simulation It can clearly be seen that, the higher the leakage factor, the higher the leakage
effect is, again as expected. At the special case in figure 7 of a leakage factor of 0.0, the
Signal-to-Noise-Ratio (SNR) is especially high.

25
Figure 7: Leakage factor of 0.0 Figure 8: Leakage factor of 0.1

Figure 9: Leakage factor of 0.2 Figure 10: Leakage factor of 0.3

Figure 11: Leakage factor of 0.4 Figure 12: Leakage factor of 0.5

26
2.3 Scallop Loss

For detected tones, the power of their estimated spectra might not be constant an effect
that is known as scallop loss [13]. A scallop loss, also known as picket fence effect,
occurs in the case if a spectral component does not match exactly the frequency bin.

Anticipatory, scallop loss can be avoided by an oversampling (for instance with a


sampling rate of 48kHz or 96kHz instead of 44.1kHz) or, in the case of the Fast Fourier
Transform, with zero padding, as explained in section 2.1.4.1. Another possibility is the
use of window functions as explained in section 2.4.

2.4 Windowing

For the reduction of scallop loss and leakage effect other window functions rather than a
simple rectangular window can be used. Table 8 lists common window functions and
compares their highest side slope level, their Scallop loss and their 3dB bandwidth. A
substantial and extensive analysis on window functions can be found in Winthrop [16]
based on Harris [17].

Table 8: Comparison of the properties of window functions


Highest Side Scallop Loss
Window 3dB Bandwidth
Lobe Level [dB] [dB]
Rectangular -13 3.92 0.89
Triangle -27 1.82 1.28
Hanning -32 1.42 1.44
Hamming -43 1.78 1.30
Blackman -58 1.10 1.68
Blackman-Harris -92 0.83 1.90
Kaiser-Bessel (α = 3.5) -82 0.89 1.83
Gaussian (α = 3.5) -69 0.94 1.79
Dolph-Chebyshev (α = 4.0) -80 1.65 1.65

The 3dB bandwidth of a window is the frequency range within the signal is not more
attenuated than the half of the power held by its centre frequency. The factor α denotes
the parameter to change the properties of the Kaiser-Bessel, Gaussian and Dolph-
Chebyshev window. The property of the highest side lobe gives information how
distinctive the disturbing power level of the nearest maximum in the spectrum is.

27
2.5 Decision on the Usage of Window Functions

A decision to be made is to ascertain whether it is worth the extra complexity to apply a


window function to extenuate the effects of leakage and scallop losses. A balance
between the increase of computational costs and decreasing these undesired effects has to
be found. It is always important to remember that the GMIS is a real time system, which
means massive prerequisite calculations are to be avoided.

Mathematically, the use of a window function requires a multiplication with the signal in
the time domain or, according to the Fourier Transform, a convolution of their spectra in
the frequency domain. Practically, both operations mean an additional computational
cost; in the latter case, the convolution of their spectra, is a sum of products is, i.e. even
more cycles would have to be scheduled.

Figures 7 - 12 show, that the leakage effect is not deniable . However, since despite the
maximal leakage effect does not change the relative spectral distribution of the power, a
simple peak detection mechanism works.

For the scallop losses, since zero padding is designated anyway for the FFT for instance,
no initially windowing is necessarily planned in the first place. If the accuracy suffers
from the lack of windowing, then an additional application of window functions is the
logical consequence.

Consequently, since the computational requirement in practice cannot be estimated at that


stage, the decision is to start to implement the algorithms without extra any windowing. If
this approach is insufficient in terms of accuracy, windowing can be reconsidered,
although of being aware, that the real time constraints of the GMIS then might not be
met.

28
3. Implementation

3.1 The Target Hardware

It took about half of the project’s time to set up the necessary requirements for the
measurements. Since there was no previous knowledge concerning the state-of-the-art
TMS320C6713, settings such as the timer, a correct sampling rate, file I/O, memory
management and many other project’s time consuming prerequisites needed to be built up
from scratch. Partly with assistance, it was then possible to start off with the
measurements. The reason why this statement is made at this stage is that, in most of the
cases, this kind of work is underestimated and considered as a matter of course. It is
therefore crucial to underline the efforts which have been made for a successful
fulfilment of the project.

3.1.1 The Digital Signal Processor (TI TMS320C6713 DSP)

The Texas Instruments (TI) TMS320C6713 digital signal processor (DSP) is a 32 Bit
floating point DSP of the C6000 series and runs at a frequency of 225MHz [18] and is
optimised for audio applications. The DSP core contains two exclusively fixed point
Arithmetic-Logic Units (ALU), four both fixed and floating point ALU and two both
fixed and floating point multipliers. It can perform both in single and double precision.

As in many commercially used processors, the TMS320C6713 has an 8KB first level and
a second level cache of 256KB as internal memory. The reason for this unbalanced
distribution of internal memory is that level 1 cache is on the other hand fast and
therefore contains both program and data cache, but is more expensive compared to the
level 2 cache on the other hand. Additionally, the TMS320C6713 also has access to
peripheral 16MB external Synchronous Dynamic Random Access Memory (SDRAM)
which can directly be accessed. For the sake of completeness, the complete address space
is shown in figure 13 [18].

29
Figure 13: Memory Map for the TMS320C6713 DSP Starter KIT

The user of the processor can choose between the two orders little and big endian. That
means, for the little endian mode (the default mode), the least significant byte is stored at
the lowest address, literally, little end first. In contrast to this, in the big endian mode, the
most significant byte is stored at the lowest address, meaning, big end first.

The TMS320C6713 also makes use of an Enhanced Direct Memory Access (EDMA)
Controller. This technique enables the acquisition of audio data directly from the stereo
audio codec (AIC 23). The EDMA can also be combined with the two Multichannel
Bidirectional Serial Ports (McBSP)

Finally, the TMS320C6713 is provided with an optimised C/ C++ compiler for the
processor’s architecture. Especially the Multiply-ACumulate (MAC) commands is
supported and the use of this multiply and add combination (also known as sum of
products) is recommended.

30
3.1.2 The TI TMS320C6713 DSP Board

The target hardware used for the analysis of frequency recognition algorithms is the
TMS320C6713 DSP Starter Kit, developed by Spectrum Digital and Texas Instrument
respectively, is referred as DSP board in the following. The reason why not a Personal
Computer (PC) (which nowadays has enough computational power to compete with a
DSP core), was not chosen for the analysis on frequency recognition algorithms is
because the aim was to target an embedded solution. The Signal Processing Laboratory
was provided with two of these DSP boards by Texas Instruments. Due to financial
restrictions, one further requirement of the project was that the implementation of the
frequency recognition algorithms should be done on this board.

3.1.2.1 Chip Support Library (CSL)

To handle interrupts, scheduling tasks and their priorities and to manage memory, Texas
Instruments has developed a DSP/BIOS real time operating system [19]. It operates
independently from the application. All the settings for the issues can be set up by a
graphical configuration manager as to be seen in figure 14 and are stored to a *.cdb file.
When compiling, the settings are then applied by the Chip Support Library (CSL) [19]. In
figure 14, it can be seen that a hardware interrupt (HWI_INT8) for the EDMA controller
is defined. The software interrupt (processBufferSwi) is defined for the software interrupt
service routine (ISR) which contains the frequency recognition algorithm.

Figure 14: Defining hard and software interrupt in the DSP/BIOS

31
3.1.2.2 Board Support Library (BSL)

The Board Support Library (BSL) offers with its Application Program Interface (API) the
opportunity to operate the board’s peripheral devices such as the four Light Emitting
Diodes (LED) and the four Dual Inline Package (DIP) switches for custom applications.
What is more, the stereo audio codec AIC 23 is configured and controlled by the API
functions of the BSL, too.

The stereo audio codec is one of the most important features for configuring the board. It
consists of ten registers [20] controlling for instance volume for input channels and
headphones for left and right each or the sampling rate fs. Since the sampling rate is one
of the fixed quantities as stated in section 5.4.1.1 and crucial for the spectral resolution, it
deserves special attention. The AIC23 stereo audio codec can be run either in the USB
(master) mode or the normal (slave) mode. In the latter case, the analogue to digital
converter (ADC) und digital to analogue (DAC) can be set up separately with different
sampling rates. Based on the master clock (MCLK) with a crystal frequency of 12MHz,
the following different basic sampling rates can be set: 8kHz, 32kHz, 44.1kHz, 88.2kHz,
and 96kHz. However, since these sampling rates are produced in the normal mode only,
there are slight differences in the USB mode, i.e. 8.021kHz, 44.117kHz and 88.235kHz
that need to be considered. Table 9 lists the considerable sampling rates according to the
constraints of the GMIS.

Table 9: Possible sampling rate settings

Mode D8 D7 D6 D5 D4 D3 D2 D1 D0 Hex value fs [Hz] (ADC / DAC)

USB 0 0 0 1 0 0 0 1 1 0x0023 44117/ 44117

Normal 0 0 0 1 0 0 0 0 0 0x0020 44100/ 44100

Normal 0 0 0 1 0 0 0 1 0 0x0022 44100/ 44100

Besides the audio codec, the use of the four LEDs and the four DIP switches are useful
for quick interactions between user and DSP board

32
3.1.3 The Code Composer Studio (CCS)

The Code Composer Studio Code (CCS) is the front end of the TMS320C6713 DSP
starter KIT and has a lot of advantageous properties.

The most obvious feature is the data visualisation. The CCS offers the chance to observe
the data which are currently present in the internal buffers. In the animation mode, even
the change over time is recognisable,. i.e. a change in frequency would change the
diagrams, too. Figure 15 depicts a 5kHz sinusoid both in time and frequency domain.

Another, very important issue is the simple data import to and export capabilities from
these internal buffers. The latter scenario is very useful for debugging purposes, i.e. for
verifying results and frequency recognition algorithms either in a simulation environment
like MatLab or with an alternative ANSI C compiler. This approach has been used in the
course of the project and has been proved to be the most effective way.

Furthermore, the CCS has the convenient feature of a simplified file I/O which enables to
trace results by using injections. Injections are soft breakpoint which halt the CPU far a
short moment to perform a file I/O. Like break and animation points, they can just be
used in a debug/release environment.

Figure 15: Source code, original and spectrum of a 5kHz input in CCS

33
3.2 Buffer Strategies

3.2.1 The Ring Buffer Technique

The ring buffer technique [10] is the most common way to buffer audio samples for
processing and is widely used in audio applications. The ring buffer, as shown in figure
16, is also called virtual ring buffer because it is an implementation of a quasi infinite
First-In-First-Out (FIFO) buffer. The read pointer has to be at least one sample in
advance in relation to the write buffer which holds the latest sample coming from the
audio codec. In figure 16, the read pointer points at the oldest sample which is just about
to be overwritten.

One advantage of a ring buffer is the ease of use, because just the writing and reading
process have to be synchronised. Another benefit of using a ring buffer is that memory
just has to be allocated for this buffer only. The importance of this fact will be more
obvious when discussing the ping pong buffer technique in the next section.

One big problem is that just one buffer is used for both receiving and transmitting audio
data from and to the audio codec. The risk, that unprocessed data is overwritten if a very
slow algorithm is implemented, cannot be negated. In this case, a very sensitive time
management is mandatory.

Figure 16: Principle of a ring buffer


34
3.2.2 The Ping Pong Buffer Technique using EDMA

Enhanced Direct Memory Access (EDMA) is used to write audio data directly from the
audio codec into an internal buffer via a Multichannel Bidirectional Serial Bus (McBSP).
Using EDMA has the big advantage of acquiring audio data without using the processor’s
resources whose only purpose is processing the audio data. This makes (audio)
processing more efficient. For the realisation of the EDMA, a start address, the length of
the buffer N, the bit depth of the audio samples of 16 bit have to be specified in
advanced. For the ping pong buffer technique [21] as depicted in figure 17, two
independent buffers (the ping and the pong buffer), each of length N, are used. The idea
is to fill one of the buffers in the first stage, while the other buffer is used for processing
the data which have been written in the previous step. Then, once this buffer is filled, the
write and read pointers are redirected to the compliment buffer controlled by the EDMA
controller. The buffer’s content which has just been processed is now subject to be
overwritten with new data, whilst the other buffer is processed.

Figure 17: Principle of a ping pong buffer


35
Simultaneously, when one buffer is filled, a hardware interrupt, generated by the EDMA
controller occurs and a hardware Interrupt Service Routine (ISR) is called. This ISR calls
a software interrupt routine (ISR) which contains the algorithm. The algorithm then is
used to process the current process buffer.

The advantages of the ping pong buffer technique are that an improved exploiting of the
limited computation time that is available by acquiring audio data while processing the
previous gathered audio samples while an overwriting of the current processed buffer is
avoided.

Of course, there are two main disadvantages using the ping pong buffer technique. The
most obvious is the need for a second buffer. Since memory is limited on a DSP board
(see section 3.1.1) and the higher the buffer size the higher the computational costs (see
section 5.4.1.5) every additional increase of a buffer has to be considered.

The other issue is the synchronisation of writing and reading to both buffers. This
procedure has to work perfectly, since writing into one buffer and processing the other
buffer happen at the same time. If the processing takes more time than the writing, the
hardware interrupt is called before the whole calculation is determined successfully and
the unprocessed data will be overwritten. A well-conditioned algorithm avoids this
asynchrony.

3.2.3 Decision on the Buffer Technique

For reason of efficiency, the approach of the ping pong buffer technique with EDMA is
the avenue chosen for the acquisition of the data. Being aware of the possible difficulties
concerning the synchrony of reading and writing and the fact that a limited time window
is available for a calculations, the ping pong buffer technique is the most promising
strategy since Texas Instruments has an illustrative example that can be taken as an
example for an understanding of this technique.

36
3.3 Usage of the Timer

In order to use the 32-bit timer, two steps must be completed. At first, the timer has to be
configured and second a calibration has to be done which measures the starting and the
stopping of the timer itself [21].

There are three timer registers to be initialised: the control, the period and the counter
register. The timer control register is used to determine the timer’s mode. The timer
period register stores the maximum value the timer counts to. Once this value is reached,
a timer overflow occurs and the time measurements become corrupt. The maximum
value, a timer can maximal count is 0xFFFFFFFF. To circumvent a timer overflow, either
the overflows have to be counted or the number is downscaled through a division by
constant, e.g. 1000. This constant has to be bared in mind for the correction of the
exported data. The timer counter register stores the current value of the timer. To init the
timer, the constant 0x00000000 is to be taken.

The second step, the calibration of the timer in conjunction with the time measurement is
illustrated by the figure 18.

Open timer;
Configure timer;
Set timer to zero;
Calibrate timer;
Start timer;
Stop timer;
Calibration cycles = Stop – Start;
Start timer;
Perform algorithm;
Stop timer;
Elapsed cycles = Stop – Start – Calibration cycles;
Close timer;

Figure 18: Pseudo code for applying time measurements

37
After having opened and having configured the timer as described above, the timer needs
to be calibrated because the measuring the time itself takes some time, too. This
calibration is the difference between two successive timer events, i.e. the starting and the
stopping of the timer. Then, the difference of both is estimated, measured in cycles.

The actual measurement of the time works as follows. The timer is started, then the
algorithm is performed. After having finished the calculation, the timer stops again and
the elapsed cycles are calculated out of difference of the start time, the stop time and the
calibration.

3.4 Possibilities of Code Optimisation

It is useful to accommodate the C compiler which is specialised for MAC (Multiply-


ACumulate = multiply and add) commands [21]. The MAC command is ideal for
transforming, filter calculation and any other sum-of-product-calculation having the
structure as denoted in equation (37).

N −1
y = ∑ b[i ]⋅ x[i ]
i =0 (37)

where y is the sum of the all N products, b is the array holding factors, x is the array
containing the signal and N is the buffer size for both arrays with I as the index for the
current sample. As far as possible, the algorithms have been developed with respect to
this MAC command. Figure 19 illustrates how the MAC command can extensively
applied to the DFT.

38
K = 6.283185 // = 2 * pi (pre-calculated)

for k = 0,N-1

for n = 0,N-1

X_Real += x[n] * cos(K*k*n);


X_Imaginary -= x[n] * sin(K*k*n);

endfor

endfor

Figure 19: Implementation of the DFT using the MAC command

Another issue is the use of the TI TMS320C67x Fast Run-Time-Support library [22].
This library contains 26 processor optimised basic mathematical floating point functions
such as sqrtsp (square root for single precision), powsp (exponential function for single
precision) and divsp (division for single precision). Since this library has an ANSI C
compatible API, it can be called from within their own routines. The question may arise,
why single precision should be used only. As the input signal’s SNR are relatively high,
the data can be treated with single precision which is another time saving fact, because
there is a difference in number of cycles when accessing a 32-bit address instead of a 64-
bit address.

When developing application in the CCS, the debug mode is useful because error
messages, buffer and variable contents can be observed. The cost for this development
convenience is the slow down of the application. However, running an application in the
release mode, it runs much faster. In the course of the project it has been shown that the
speedup of debug and release mode is 1.43. However, while running an application in the
release mode only, it is not possible to take measurements via file I/O, because therefore,
injections are required. Consequently, a compromise (a combination of maximum
optimisation and minimum debug features) has to be found between the modes. In all
implementations of the frequency recognition algorithms the options –gp (allows
debugging at function level) and –o3 (maximum optimising mode) are used.

39
The use of pointers is to be extended as much as possible and is preferable instead of an
actual physical copying of the buffer contents. Whenever possible, actual physical
copying should be avoided because it increases the computational costs.

Furthermore, pre-calculation of filter coefficients and storing them in to a lookup table


(LUT), such as for the Goertzel algorithm, can increase the speedup by a factor of 102 as
it could be observed in the course of the implementation. Additionally, it is important to
calculate constant values as early as possible. If a value is needed at least twice, it does
not have to be calculated at each stage, especially not in loops. Advantageously in terms
of code optimisation therefore is the use of (pre-processor) constants. Instead of
calculating for instance 2 · π at each stage of the algorithm, this constant can be
predefined directly as 6.283185.

Other optimisations are due to the algorithms’ nature. For instance intermediate values
for the calculation of the DFT, such as real, imaginary part and magnitude can be stored
temporarily in a variable instead of in a buffer which saves expensive memory. The
estimation of the maximum power peak in the spectrum, i.e. the search for the maximum
spectral component, can be performed on the fly. That means, only the maximum value is
stored until it is subject to an update whenever it becomes excelled. This procedure just
has to be done for half the frequency range, since this range is just interesting up to the
Nyquist frequency, which is half the sampling rate.

To sum it up, there are these opportunities to optimise the code implemented in C:

• Extensive use of DSP oriented MAC commands.


• Reference to optimised Fast Run-Time-Support library using mathematical API
• Using single precision (floating point) rather than double precision (double)
• Finding a good compromise between debug and release mode
• Use of pointers instead of physical copying of values
• Pre-calculation of filter coefficients and constants
• Estimating the maximum spectral power on the fly in half of the spectrum
• Temporarily storage of intermediate values instead of in buffers

40
4. Implementation of the Frequency Recognition Algorithms

4.1 Methodology

For the implementation of the algorithms, the real time characteristic is of less
importance in the first place. The main purpose is to get them working properly and to
verify their results in terms of correctness. In order to achieve this, several tools are very
useful.

As a first approach, MatLab and Simulink are consulted for a first implementation of the
algorithms. Their ease of use and their undisputable ability to monitor results graphically
very quickly are of assistance to get proof of the correctness of the algorithms. The
second step is a direct implementation of the algorithms in ANSI C using Microsoft
Visual Studio C++ 6.0. Since ANSI C is the programming language which is used for
developing applications for the Texas Instruments (TI) TMS320C6713 Digital Signal
Processor (DSP) core in the Code Composer Studio (CCS), a fast implementation close to
the final application is possible. This step also ensures simultaneous debugging by taking
a working algorithm as a reference. This is a very effective way to verify intermediate
steps. Since the Code Compose Studio offers the opportunity to export complete buffer
content’s into text files, MatLab is used for verifying and displaying the results.

As input sources, several options can be considered. Cleary defined unique sinusoids
generated by WaveLab and played by the soundcard are valid input signals. Signals from
a signal generator are preferable though because they are more reliable signal sources. At
a later stage instrument samples playing musical notes are taken as input source too.

To summarise, for the implementation of the algorithms onto the target hardware,
MatLab and both developer studios (Microsoft Visual Studio C++ 6.0 and Code
Composer Studio go hand in hand) and complement each other. This methology
accelerates the developing process crucially and, what is also very important, it helps to
verify the results to make sure that they are correct.

41
4.2 Principle of the Frequency Recognition Algorithms

The process which all frequency recognition algorithms undergo can be described as
follows. At first, the sampled and quantised input signal x(n) is transformed into the
frequency range, in order to obtain real ℜ{X (n )} and imaginary part ℑ{X (n )} of its
spectrum X(n). The calculation of magnitude Mag(X(n)) is initial for a peak detection
mechanism, which finds the spectral component of the signal with the maximum power.
The index kmax of this spectral component is finally evaluated with respect to the number
of samples N and the sampling rate fs. Since the frequency is now given as a numerical
value, it is ideal for a post processing MIDI conversion. The whole process of a Fourier
transform-based frequency recognition algorithm is illustrated in figure 20.

Input signal

 x(n)

Fourier transform-based
Frequency Recognition
Algorithm

 ℜ{X (n )}, ℑ{X (n )}

Calculation of
Spectrum’s Magnitude

 Mag(X(n))

Peak Detection  kmax = max(Mag(X(n)))

Frequency Point Evaluation  fmax = kmax · fs / N

Figure 20: Frequency recognition in principle


42
4.2.1 The Discrete Fourier Transform (DFT)

4.2.1.1 Simulation with MatLab

According to equation (14) in section 2.1.3, the Discrete Fourier Transform is defined as

N −1 2π

X [k ] = ∑ x[n] ⋅ e
− j⋅ ⋅k ⋅ n
k = 0,1,..., N − 1
N
(38)
n=0

and directly implemented in MatLab (appendix D). The result is shown in figure 21
depicting the original input signal, its spectrum together with the spectrum’s real and
imaginary part of a 1kHz sinusoidal input at a sampling rate of fs = 44100Hz.

The signal is deliberately maximal non-coherent sampled as with a leakage factor of 0.5
as explained in section, in order to obtain a maximum leakage effect. It is noticeable that
even under this worse case condition the peak detection mechanism will succeed in terms
of finding the maximum energetic spectral component which underlines the decision not
to apply extra windowing as explained in section 2.4.

Figure 21: Input signal, magnitude, real and imaginary part of a sinusoid of 1kHz

43
4.2.1.2 Implementation of the DFT in C

A direct implementation of the DFT in C as in the case of the MatLab simulation in the
previous section is possible, however with slight differences. As MatLab supports the
scientific notation of complex numbers but since this convenient implementation in C is
not available, the twiddle factors have to be rewritten by using the Euler equation:


− j⋅ ⋅k  2π   2π 
W Nk = e N
= cos ⋅ k  − j ⋅ sin  ⋅k
 N   N  (39)

This preliminary study is very important for the implementation of the DFT on the
TMS320C671 because the real and the imaginary part of the spectrum can be regarded
separately. Then the MAC (Multiply-ACumulate) command can be applied as explained
in section 3.4. Since the architecture and the compilers of the C6000 series are specialised
for this product summing up command, an implementation of the DFT in the way as
described above, is promising in terms of a fast calculation speed.

A considerable point is that the AIC23 audio codec provides interleaved stereo data only.
However, for the analysis mono data is required only and thus every even sample is taken
only. This approach avoids a superfluous copying into an auxiliary additional buffer
which would mean additionally requirements of memory and extra computational time.

Another issue is the pre calculation of constants once only, especially if processing power
consuming numeric divisions are applied. For instance, as the constant K = 2 · π / N is
dependent on the buffer size N only and used permanently in both loops, it is calculated a
priori.

Furthermore, what is crucial for saving internal memory, is the calculation of the
magnitude on the fly. According to the classical implementation of the DFT, the interim
values, such as the real, the imaginary part of the spectrum and the magnitude, are stored
in buffers of the size of N each. When determining the most powerful spectral
component, no additional buffers for these interim values are required because always the
latest maximum value of the magnitude only is subject to storage.

44
What is more, as a consequence of the Nyquist-Shannon Theorem, only half the
calculated spectrum is relevant for an evaluation, more precisely, the frequency range of
0Hz until half the sampling rate fs/2. Therefore, only a scan of half the spectrum is
necessary, a fact that results in an economisation of computation time.

4.2.2 The Fast Fourier Transform (FFT)

4.2.2.1 Simulation in MatLab

Since the Fast Fourier Transform (FFT) is a very efficient algorithm to apply the Discrete
Fourier Transform (DFT) by exploiting the redundancy of calculating the twiddle factors,
the approach to implement this algorithm implies previous knowledge and understanding
of the DFT.

For the simulation of the FFT, in order to get a feeling for its handling, the MatLab script
as listed in appendix E is used. It reads wave files which contain signals to be analysed
and outputs both its spectrum graphically and stores the input signal numerically in a user
defined output file. The intention is to take this numerical data as a known reference for
the implementation on the TI TMS320C6713. Another derivative of this simulation has
been used, but instead of referring to wave files as input, actual buffer contents of the TI
TMSC6713 were taken as the input for the MatLab file. This method ensures a direct
comparison of the obtained spectra estimated both in MatLab and with the TI
TMS320C6713 and is very helpful for the development of the algorithm.

Figures 22 and 23 show the original signal of an 1kHz sinusoidal input stored in a wave
file and its spectrum calculated by the integrated FFT of MatLab respectively. Since the
Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT) are working
reliably in the simulation environment of MatLab, they can both be taken as an
orientation and reference for verifying results of the following two algorithms, the
Goertzel algorithm and the Non-uniform Discrete Fourier Transform (NDFT).
Additionally, both algorithms can be used for analysing exported input buffers of the TI
TMS320C6713, because MatLab is not limited to wave files only but also can take the re-
imported buffers for debugging reasons.

45
Figure 22: Original signal of an 1kHz Figure 23: Spectrum of an 1kHz sinusoid
sinusoid (wave file) (wave file)

The combination of simulation MatLab and implementation in C is utmost effective


because algorithms can both be verified and debugged at the same time.

4.2.2.2 Implementation of the FFTW in C

After having verified the FFT under simulation conditions with MatLab, the next step is
to get a feeling for the implementation of this algorithm in C. The first approach is an
investigation on the “Fastest Fourier Transform in the West” (FFTW) [23], an application
program interface (API) which peculiar naming is given by their authors of the
Massachusetts Institute of Technology (MIT) is known as the fastest implementation of
the FFT and it is the same implementation of the FFT as used in MatLab.

Taking the avenue of implementing the FFTW is ambiguous. On the one hand, TI
provides a library with an API [24,25] with an assembly coded, one dimensional radix-2-
FFT. With a very high probability, this routine is unbeatable in terms of speed, because it
has been optimised especially for the TMS320C6713 DSP core architecture. The question
is therefore, why not simply use this API function? A look into the API documentation
[25,26] shows the disadvantages of this API routine. It accepts interleaved complex data
only of the size of 2n with n as an integer of n ≥ 5. This is, in terms of memory
management, extremely inflexible because it has to be considered that according to table
11, 5.5 times more memory is required than originally anticipated (see section 4.3, table
11).

46
In contrast to this, the FFTW offers other very convenient features. Arbitrary input sizes
can be used with the possibility of using real input data only. This alone makes the FFTW
function definitively more flexible than the FFT function of the TI API. The FFTW is
also known for its ability to adapt its algorithm to the target hardware. These advantages
might not make the FFTW necessarily faster for small problem sizes on the
TMS320C6713, however, if the buffer size increases, the FFTW may prove to be a more
efficient algorithm. Consequently, it was decided that the FFTW was worth investigating.

The implementation of the simplest FFTW, the one dimensional FFTW is developed as
illustrated in figure 24 The first step is to estimate how much memory is required for a
FFTW of a problem size N. This integer value is used for allocating sufficient memory
for input and output buffers similar to the calloc() function in C. Then, a so-called FFTW
plan is created with respect to the number of samples, the input and output buffers. This
plan also takes the architecture of the processor into account, a fact why the FFTW is
supposed to be superior to a common approach on an implementation of the FFT. After
having executed the FFTW, the output buffer holds the spectrum with interleaved
complex data which now can be further processed, in this case, by a calculation of the
magnitude and the maximum frequency respectively. The last step is the clear up of the
used resources, i.e. both the estimated FFTW plan and the allocated memory is to be
freed for a further use of these resources.

When implementing the FFTW, it is recommended to get familiar with the API by
programming a spectral analysis of an example, in this case a FFTW over an 8912-point
sampled input signal. In order to reduce the development time, there are pre compiled
libraries available [23] which simplify the development of the algorithm.

estimate the amount of memory for a problem size of N;

allocate memory for complex input, output buffer of size N;

create FFTW plan according to architecture of hardware;

execution of the FFTW plan;

free allocated memory and delete plan;

Figure 24: Pseudo code for a 1D FFTW

47
Figure 25: Magnitude calculated by an 8192-point FFTW of an 1kHz sinusoid

Again, the simulation in MatLab as described in the previous section and the
implementation in C go hand in hand in order to verify the results. The MatLab script is
used for both an analysis of the signal stored in a wave file and the conversion of this
wave file into a text file which contains the signal as numerical data. The text file is then
the input source for the C file in which the FFTW is coded.

After having calculated the 8192-point FFTW in C, the maximum frequency is output as
well as the magnitude again as a text file for a graphical display in MatLab as it can be
seen in figure 25. The FFTW C program estimates for an 8192-point FFTW a signal with
a frequency of fes = 1001.29Hz. This result is accurate enough for an expected maximum
44100 Hz
spectral resolution of ≈ 5.38 Hz , because the absolute deviation of this
8192
estimated frequency from the expected frequency of fep = 1000Hz equals 1.29Hz only.

This short example and relatively quick result with a sufficient accuracy qualifies the
FFTW for a further investigation and it is reasonable to consider an implementation of
the FFTW on the TI TMS320C6713 DSP. The use of Windows precompiled libraries
enables to experiment with the FFTW and it has been shown that the FFTW has potential
for an implementation on the target hardware. Since the processor expects an executable
compilation only, the FFTW libraries have to be linked to this executable.

48
A direct implementation fails due to the numerous settings that have to be made when
installing the FFTW on a target system. Thus, an indirection over UNIX has been made
in order to get a feeling for the FFTW, especially its compilation and linking. The choice
of UNIX is due to the fact that the FFTW was developed under this operating system. An
installation works as well as the 8192-point implementation being written under
Windows. The second stage, installing, compiling and linking the FFTW libraries under
Windows succeeds, too. Again, the self coded 8192-point FFTW example works under
this operating system, too.

The last, but most difficult step is the compilation and linking process on the target
hardware (TMSC3206713). After having taken several trials, the FFTW sources could
finally be compiled error free, but the linking of the object files and consequently an
upload into the DSP’s memory failed. The reason for that is the size of the compilation.
Usually, a compiled program for the TMS320C6713 is about 200KB. The actual size of
the unlinked objects for the FFTW to be implemented on the DSP is about 4.9MB, an
increase of demand for memory by the factor 25. That is why, the linker does not allow a
binding the object files into one executable file to be uploaded into the DSP’s memory
and consequently the FFTW could not be implemented on the TI TMS320C6713 DSP
core.

It would have been advantageous, to try the flexibility of the FFTW on the target
hardware, since the TI API implementation of the FFT is on the one hand fast but
restricted and inflexible on the other hand.

49
4.2.2.3 Implementation of the FFT in C

Since the implementation of the FFTW was not successfully applied, the assembly coded
library [24,25] has to be taken for implementing the FFT. For this, previous knowledge of
the FFT as such is pre-requisite.

For a buffer size of N ≥ 32, where N has to be of the power of two, a N-point FFT can be
achieved. The API function DSPF_sp_cfftr2_dit() expects a pointer to an input buffer, a
pointer to an array holding the pre compiled twiddle factors and the number of elements
N as an integer as input parameters.

Since the input data has to be complex, i.e. consisting of interleaved real and imaginary
parts, the buffer containing this data has to have the length of 2 · N. After the execution
of this function, this buffer holds the complex result. The number of twiddle factors is
N/2 as a result of having taken advantage from their redundant calculation. Per definition
of the API, the twiddle factors have to be reordered by bit reversal. Finally, after the
calculation of the FFT, the output data has to be reordered by bit reversal. Both twiddle
factor pre calculation (tw_r2fft.c) and bit reversal (bit_rev.c) can be found in the TI FFT
support files [25].

50
Figure 26: Parallel debugging

Since there was no need to implement the FFT explicitly in another development
environment rather than the Code Composer Studio (CCS), the DFT has been taken as a
reference for the development of the FFT. The approach is, to export the input buffer of
the algorithm in the CSS and to re-import them into the alternative development
environment. Then, a debugging close to real conditions is possible.

Figure 26 shows how the successfully implemented DFT in Microsoft Visual Studio C++
6.0 is taken to debug a FFT in the Code Composer Studio. Since the FFT is a DSP-based
algorithm, the actual results as well as the intermediate values have to be identical. As it
can be seen in figure 26, the magnitudes in both development environments are identical.
Therewith, the results of the FFT are verified and proven and measurements series can be
applied.

51
4.2.3 The Non-Uniform Discrete Fourier Transform (NDFT)

The structure of the Non-Uniform Discrete Fourier is similar to the DFT and its
complexity is N2, as well. The only difference is the fact that the NDFT does not refer to
an equidistant sampled frequency range indexed with k but to an arbitrarily frequency
vector fk as described in section 2.1.5. It is expected that the assessing to this vector
stored in an array causes an additional delay that makes the NDFT a bit slower than the
DFT.

The main issue of the NDFT and the key for its advantage in comparison to the DFT is
the arbitrarily chosen frequency vector whose accuracy is increased, if it is well-
conditioned. For frequencies in the lower range (i.e. 27.5Hz, 29.14Hz, … ), a finer
fragmentation of the frequency vector is required, because the spacing between two
neighboured notes is smaller than for adjoining frequencies in the higher range (i.e. …
3951.07Hz, 4186.01Hz).

The main problem is the fact that there are 88 MIDI notes, a number which differs from
the buffer size N in every case. If the buffer size N was equal to 88, each MIDI note
would correspond to a buffer index, but this is, as mentioned before, not possible. For a
buffer size N less than 88, the accuracy would not be sufficient enough due to the fact
that some of the MIDI notes are simply not assigned to one buffer index. The most
interesting case is, if the buffer size is greater than the number of MIDI notes, is subject
to discussion this section.

The spacings between each frequency point between two MIDI notes are equidistant
though, however dissimilar between each MIDI note pair due to the fact that the MIDI
notes themselves are not equidistant arranged to each other. Taking equation (1) with
nMIDI − 69
f (n MIDI ) = 440 ⋅ 2 12
Hz as a basis, the spacings are calculated in dependence on two
neighboured MIDI notes and the buffer size N.

f (nMIDI + 1) − f (n MIDI )
∆ nMIDI ( N ) = for 21 ≤ nMIDI ≤ 108 (40)
N
88

52
27.5Hz 29.14Hz 30.87Hz 3951.07Hz 4186.01Hz
. . .

...

27.5Hz + 0·∆21 27.5Hz + 1·∆21 27.5Hz + 2·∆21 29.14Hz + 0·∆22

Figure 27: Arbitrarily chosen frequencies for the NDFT

The final structure of the vector holding the arbitrarily chosen frequencies and the
corresponding MIDI notes is shown in figure 27 in principle. Since this vector is
dependent on the buffer size N, it has to be recalculated for each buffer size N.

4.2.4 The Goertzel Algorithm

Before coding the Goertzel algorithm up, it is quite useful to have a closer look at the
Goertzel IIR filter coefficients as they are listed in table 6 in section 2.1.6.1. Since the
filter coefficients b0 = 1 and a2 = -1 remain constant throughout the whole calculation and
hence do not have to be determined at each stage, the filter coefficients b1 and a1 have to
be calculated only for each Goertzel filter. It is useful to separate the complex denotation
of filter coefficient b1 into a real and an imaginary part using the Euler equation as shown
in equations (41) and (42).

2π − j ⋅ 2π ⋅
fk
− j⋅ ⋅k
b1 = −e N
= −e fs
k = 0,1,...,88 (41)

 f   f 
b1 = − cos 2π ⋅ k  + j ⋅ sin  2π ⋅ k  = ℜ(b1 ) + j ⋅ ℑ(b1 ) k = 0,1,...,88 (42)
 fs   fs 

For the sake of completeness, filter coefficient a1 of the recursive section is given as

 2π  (43)
a1 = 2 ⋅ cos ⋅k
 N 

This consideration results in a set of 3 · 88 = 264 pre-calculated filter coefficients to be


set up in a look-up table as shown in principle in table 10.
53
Table 10: Frequencies and filter coefficients for 88 MIDI notes

MIDI note 1 2 … 88
Frequencies 27.5Hz 29.14Hz … 4186.01Hz
ℜ(b1 ) 0.999992 0.999991 … 0.827489
Filter coefficients ℑ(b1 ) 0.003917 0.004149 … 0.561482
a1 1.999985 1.999983 … 1.654978

For the buffer size N, the signal is filtered with respect to the pre-calculated filter
coefficients. Since only the real and imaginary part and their magnitude are of interest
only, a calculation of these intermediate values takes place after having filtered the data.
Different from DTMF systems using 8 frequencies of interest, the maximum number of
the frequencies to be regarded is 88. For reason of saving computation time, the pre-
calculated filter coefficients are read from a two dimensional array goertzel_coeff for
each loop pass. It has been shown that the speedup of the method of pre calculation the
IIR filter coefficients results in a considerable factor of 102.

The actual Goertzel value is obtained with the application of the Goertzel IIR filter by
taking the filter coefficients into account. Again, as considered in section 3.4, the
estimation of the maximum power happens promptly without and is continuously updated
if the maximum is excelled instead of a down streaming scanning of a whole temporary
buffer containing all successively calculated Goertzel values.

All functions (goertzel_one_channel_lookup and goertzel_GetFrequency) realising the


Goertzel algorithm on the TI TMS320C6713, the IIR filter coefficients
(keyboard_notes.h) and the auxiliary program (goertzel_coeff_LUT.c) used for the
generation of the filter coefficients are listed in appendix F.

54
4.3 Comparison of schedulable Buffer Sizes

A noteworthy fact is the actual memory requirement for a buffer size N for each of the
algorithms. This also demonstrates the reason why a maximum buffer size of just 8192
can be applied.

To obtain N data elements, the ping and the pong buffer have to be set up, each of a size
of 2 · N. Due to the codec only applying a stereo input, twice the number of samples has
to be scheduled. In total, for the DFT and the Goertzel algorithm, the actual buffer
requirements are 4 · N.

In particular in the case of the FFT, for the generation of the input buffer for the API
function, another additional buffer is needed. This buffer has the size of 2 · N, because
the input data has to be complex with interleaved real and imaginary part. The twiddle
factors need an extra buffer of the size N/2. In total, 5.5 times more data elements have to
be provided than originally scheduled for a problem size N.

The NDFT has, due to its complexity, similar basic memory requirements of (4 · N) as
the DFT. Additionally, there is a need of N data elements for the pre-calculated arbitrarily
chosen frequency vector.

Table 11 lists the actual buffer size requirements for a problem size N and states which
factor has to be taken into consideration for an implementation of a problem size N for
each algorithm.

Table 11: Actual buffer size requirements for a problem size N


DFT FFT Goertzel NDFT
factor 4 5.5 4 5

55
5. Measurements

5.1 Measurement Setups

The basic measurement setup is depicted in figure 28. In order to obtain distinct signals
consisting of single sinusoids only, a common signal generator is used. For monitoring
reasons its signals are simultaneously displayed with an oscilloscope. Once the signal has
been led into the line input of the Texas Instruments (TI) TMS320C6713 Digital Signal
Processor (DSP) board it is subject to sampling and quantisation before it can be analysed
by one of the to be investigated by one of the to be investigated frequency recognition
algorithms. The development software, naming the Texas Instruments’ Code Composer
Studio is installed on the PC and is used for both coding the algorithms and for storing
the measurement results in a file. A further, more detailed description of the measurement
procedure is given in section 5.2.

Figure 28: Measurement setup for sinusoidal signals

56
Figure 29: Measurement setup for instrumental inputs

Figure 29 illustrates the measurement setup in the way it is used for feeding the
frequency recognition algorithms with instrumental inputs playing musical notes as
further described in section 5.2.2. The signal generator is replaced by the sound card as
an input source playing the selected samples. Again, for monitoring purposes, the input
source is displayed with an oscilloscope.

57
5.2 Analysis of Input Signals

Measurements without any preceding estimation or even without a basic analysis are
useless. In other words, starting a measurement without any kind of expectancy is neither
engineer-like nor scientific. Therefore, this section analyses the input signals’ spectra
versus time, i.e. the spectral behaviour during the duration of the samples. It does not take
into account the spectral resolution. It makes assumptions of the algorithms’ frequency
recognition capability exclusively based on an analysis of the input signals’ spectra and is
therefore a hypothesis. By doing this, a necessary preliminary evaluation of the frequency
recognition algorithms is possible.

Generally, an algorithm, by definition, is supposed to be independent from its input. This


is true for signals with the same structure. Two categories of signals as listed in table 12
are subject to a preliminary analysis to obtain a solid expectancy.

Table 12: Input signal categories


Signal category Signal source
Simple sinusoid Signal generator (figure 28)
Samples of musical instruments using a PC (figure 29)
Complex waveform
String Woodwind Brass

It is presumed that the first category of signals, which consists of a simple sinusoid, are
stable over their whole duration, meaning, a simple maximum power search over the
spectrum will yield the fundamental frequency. That is why, for this type of signal,
frequency recognition is expected to be without complications.

For the second category, signals containing complex waveforms, samples of notes played
by musical instruments are used as an input for the frequency recognition algorithms. The
expectation is that not every sample holds the maximum power on the fundamental
frequency because the signal can no longer be considered to be a simple sinusoid.
Moreover, for some of the notes some of the harmonics actually carry more power.
Additionally, this behaviour changes over time for some of the regarded notes, which
might make frequency recognition more difficult rather than with simple sinusoids. These
assumptions have to be confirmed both by the following spectral examination and
verified by the measurements itself.

58
5.2.1 Sinusoidal Inputs

The bases for the evaluation of the frequency recognition algorithms are the metrics
latency, speedup and accuracy as discussed in section 5.4.2. Latency and speedup can be
deduced from the number of cycles an algorithm needs to estimate a frequency and the
accuracy depends directly on the algorithmic estimation capability from which the
absolute deviation can be calculated.

To find out the best frequency recognition algorithm, at least 10 test series for each buffer
size for 32 ≤ N ≤ 8192 have been applied to each algorithm. The reasons for these
boundaries are as follows. The lower bound 32 ≤ N is a limitation of the implementation
of the FFT API routine (DSDF_sp_cfftr2_dit) from Texas Instruments (TI) [16], whereas
the upper bound is due to internal memory constraints. Furthermore, for a buffer size of
N > 8192, there would be unreasonably high computational costs for the calculation of
direct frequency recognition algorithms such as the DFT and the NDFT, whose costs are
N2. Concluding, the common boundaries for the buffer size, 32 ≤ N ≤ 8192, have been
chosen for all the measurements to be able to compare all the algorithms and should be
sufficient to fulfil the task.

For each algorithm test series, three cases were investigated: the note A4 with 440Hz [6]
(being the note in the centre of the MIDI scale), and two extreme cases: the highest
frequency with 4186.01Hz (note C8) and the lowest one of 27.5Hz (note A0) of the target
frequency range. The reason for these choices is to determine the ability to analyse the
algorithms’ capability to handle the highest frequency, 4186.01Hz and the highest
spectral resolution demand at 27.5Hz, where Rmax = 0.82Hz (section 5.4.1.2).

59
Figures 30, 31 and 32 depict the spectral analysis of frequency vs. time vs. power of a
signal generator outputting a frequency of 440Hz, 4186.01Hz and 27.5Hz respectively.

Figure 30: Spectrum vs. time for a 440Hz input

Figure 31: Spectrum vs. time for a 4186.01Hz input

60
Figure 32: Spectrum vs. time for a 27.5Hz input

From figures 30, 31 and 32, it can be seen that the maximum power is given on the
fundamental frequency as expected. However, there are a number of harmonics along
with the fundamental frequency which should not occur. The reason for this is the fact
that the signal generator does not produce a pure sinusoid exclusively but has a small
amount of harmonic distortion and should be ignored in this case. Additionally, there are
reflections due to a mismatched connection from the signal generator to the audio jack
input of the DSP board. Since the maximum power can be found at 440Hz, 4186.01Hz
and 27.5Hz respectively, these undesired, less powerful frequencies do not carry weight
in terms of frequency recognition. This is a good prerequisite for a solid frequency
recognition capability regardless of the spectral resolution in terms of accuracy and a
reasonable buffer size N.

61
5.2.2 Inputs of Musical Instruments

For signals containing simple sinusoids generated by a signal generator, it is anticipated


that the frequency recognition algorithms should work perfectly if a maximum power
detection is used. Whether they can be applied to signals containing complex waveforms
is subject to a discussion in this section.

To test the frequency detection capabilities of each algorithm, four different instruments
(piano, violin, trumpet and flute) playing three different notes have been taken as an input
according to measurement setup in figure 29. Because not every note of the frequency
range of interest can be subject to an analysis and a subsequent measurement, because of
the range of each instrument, a representative selection has to be made. Thus, all the
selected notes are played by each instrument to ascertain comparability.

When applying instrumental inputs, the frequency recognition capability is initially of


interest only. The buffer size N is dependent on the demand for the accuracy for the notes
C6, C5 and C4 respectively. Equation (44) denotes the coherence between the sampling
rate fs and the demanded accuracy depending on the MIDI note.

fs (44)
N=
accuracy(nMIDI )

Table 13 lists summarizing the constraints of the notes which are subject to further
measurements. They are valid each for piano, violin, trumpet and flute.

Table 13: Constraints and properties of instrument samples


Demanded Lower Upper
Instrument Frequency
accuracy Bound Bound Buffer size N
note [Hz]
[Hz] [Hz] [Hz]
44100 Hz
C6 1046.5 29.37 1017.13 1075.87 N= ≈ 1501.53 ≈ 2048
29.37 Hz
44100 Hz
C5 523.25 14.68 508.57 537.93 N= ≈ 3004.09 ≈ 4096
14.68 Hz
44100 Hz
C4 261.63 7.34 254.29 268.97 N= ≈ 6008.17 ≈ 8192
7.34 Hz
62
5.2.2.1 Note C6 (1046.5Hz) for Piano, Violin, Flute and Trumpet

Figures 33 - 36 depict for each musical instrument the power distribution of the signals’
spectra over the time for note C6 (1046.5Hz). For all instruments playing this note, the
maximum power can actually be found at the fundamental frequency of 1046.5Hz. From
these figures, it can be seen that the piano produces one harmonic, the violin two
harmonics, the flute none and the trumpet one further harmonics. None of them contains
noteworthy power which could disturb the peak detection mechanism of the algorithms.

Figure 33: Spectrum vs. time for a 1046.5Hz input (piano)

Figure 34: Spectrum vs. time for a 1046.5Hz input (violin)

63
Figure 35: Spectrum vs. time for a 1046.5Hz input (flute)

Figure 36: Spectrum vs. time for a 1046.5Hz input (trumpet)

64
5.2.2.2 Note C5 (523.25Hz) for Piano, Violin, Flute and Trumpet

Figures 37 - 40 depict the spectra of a piano, a violin, a flute and a trumpet playing note
C5 (523Hz). Compared to note C6 (1046.5Hz), the total number of harmonics increases,
in specific for the piano there are two, for the violin five, for the flute one and for the
trumpet two further harmonics. Again, which of the natural frequencies, either the
fundamental frequency or one of its harmonics, holds the maximum power, is of interest.

Figure 37: Spectrum vs. time for a 523.25Hz input (piano)

Figure 38: Spectrum vs. time for a 523.25Hz input (violin)

65
Figure 39: Spectrum vs. time for a 523.25Hz input (flute)

From figures 39 - 40, it can be seen that for string-based instruments and for the flute, the
maximum power is held on the fundamental frequency. A maximum power detection
should not be problematic for the frequency recognition algorithms.

In figure 40, however, it can be seen that for a trumpet, that a simple maximum power
detection will fail to establish the fundamental frequency, because the second and third
harmonic with 1046.5Hz and 1567.98Hz respectively carry the maximum power
throughout the whole sample’s duration with a slight advantage for the second harmonic.

Figure 40: Spectrum vs. time for a 523.25Hz input (trumpet)

66
5.2.2.3 Note C4 (261.63Hz) for Piano, Violin, Flute and Trumpet

Figures 41 - 44 depict the spectra of the instruments over time for note C4 (261.63Hz).
As it can be observed from figures 41 - 44, the number of harmonics increases further
compared to note C5 and the signal’s power is more distributed over the spectrum. To
attain solid peak detection, it is sufficient if the fundamental frequency holds the relative
maximum of the spectral power. This condition is fulfilled for the piano and the violin
playing C4 which have one and four harmonics as illustrated in figures 41 and 42.

Figure 41: Spectrum vs. time for a 261.63Hz input (piano)

Figure 42: Spectrum vs. time for a 261.63Hz input (violin)

67
Figure 43: Spectrum vs. time for a 261.63Hz input (flute)

The flute’s spectrum depicted in figure 43 shows that in addition to the fundamental
frequency of 261.63Hz there are six further harmonics. Interesting is the fact, that the
second harmonic with 523.25Hz contains the highest power. Therefore, all frequency
recognition algorithms will most likely estimate this frequency as a result. The trumpet in
figure 44 shows five further considerable harmonics, where the maximum power is
distributed and changes over time between the fourth and sixth harmonic at 1046.5Hz and
1567.98Hz respectively. For the peak detection algorithms it will potentially difficult to
perform accurate peak detection.

Figure 44: Spectrum vs. time for a 261.63Hz input (trumpet)

68
5.3 Prediction of the Algorithms’ Frequency Recognition Capability

Taking simple sinusoids (440Hz, 4186.01Hz and 27.5Hz) all frequency recognition
algorithms have an unambiguous input because the spectral distribution of the signal’s
power remains constant throughout the whole time window and spectrum’s maximum
peak can be found at the fundamental frequency. That is the reason why the chances of
failure are very low using only a simple power detection technique. Measurements on the
algorithms with these sinusoidal inputs and the subsequent analysis with the evaluation
criteria will give certainty whether this prediction is right.

For instruments playing musical notes, it is important to find out whether the maximum
power can actually be found on the fundamental frequency or on one of its harmonics. In
the latter case, investigations have shown that the lower the frequency is the more
harmonics exist. It is clear from figures 33 - 44, that for all analysed musical notes
(1046.5Hz, 523.23Hz and 261.63Hz) for string-based instruments (piano and violin), the
spectral behaviour over time is constant and therefore ideal for frequency recognition. It
can also be seen, that the relative power distribution of the spectrum of these string based
instruments remains stable over time, i.e. the maximum power can always be found on
the fundamental frequency of the note being played. However, the spectrum over time of
woodwind and brass instruments like the flute and the trumpet respectively is not well-
behaved for each of the analysed notes. The trumpet does not have the maximum power
on the fundamental frequency for MIDI note C5. Furthermore, for MIDI note C4, both
the trumpet and the flute will fail according to the preliminary spectral analysis because
the maximum power is not held by the fundamental frequency each. Table 14 lists the
probable frequency recognition capabilities of the investigated algorithms with respect to
the analysed instrumental notes.

Table 14: Probable frequency recognition capability of instruments


C6 C5 C4
(1046.5Hz) (523.25Hz) (261.63Hz)

Piano pass pass pass

Violin pass pass pass

Flute pass pass fail

Trumpet pass fail fail

69
5.4 Evaluation Criteria

In order to find the optimum frequency recognition algorithm, there is a need for a
precedent definition of fixed quantities and performance metrics. The purpose is a
reduction of the number of variables to a reasonable minimum which is then subject to a
further analysis. Finally, this preliminary investigation leads to the conclusion that the
evaluation criteria, in particular the performance metrics, are dependent on the buffer size
N only.

5.4.1 Fixed Quantities

There are a number of fixed quantities which are not subject to a measurement as such
but also important for the evaluation of the algorithms. These considerable quantities are
the sampling rate, the spectral resolution, the minimum buffer size for a sufficient
spectral resolution, the system’s time to settle and the computational costs of the
investigated algorithms.

5.4.1.1 Sampling Rate

The sampling rate is fixed to fs = 44100Hz in order to take into account high frequency
harmonics, since the analysis of frequency recognition algorithms is subject to a further
extension to the whole audible range of 0Hz – 22000Hz. Therefore the sampling rate has
to be greater than twice the maximum frequency that can appear in the expected signal in
order to avoid aliasing according to the Nyquist-Shannon theorem [7,8] as explained in
section 5.4.1.1. Consequently, this major constraint of having a sampling rate of fs =
44100Hz is mandatory for the Generic Musical Instrument System (GMIS), despite of
having a large buffer size N and thus having an increase of complexity, because the
higher the sampling rate, the more sampling points are acquired.

70
5.4.1.2 Spectral Resolution

A fine spectral resolution R is prerequisite for a solid accuracy and is given by the ratio
of the sampling rate fs and the actual buffer size N with

fs
R( f s , N ) = (45)
N

In general, one can say, the higher the buffer size N the better is the spectral resolution R
at a given sampling rate fs. Due to the fact that an increase of the buffer size N
simultaneously causes an increase of computational costs and memory requirements, a
trade-off has to be found between the spectral resolution, R, and the buffer size, N.

When analyzing musical notes, the maximum spectral resolution which has to be
provided, is Rmax = 0.82Hz in order to be able to recognise all frequencies of the whole
target frequency range. The reason for this high resolution is the smallest half of the
MIDI channels, i.e. between MIDI note #21 and #22 with 27.5Hz and 29.14Hz
respectively.

5.4.1.3 Minimum Buffer Size for a sufficient Spectral Resolution

Consequently, the minimum number of samples required for an optimal spectral


resolution is the ratio of the fixed sampling rate fs and the maximum spectral resolution
Rmax and is defined as

fs 44100 Hz
N min = = ≈ 53781 ≈ 216 (46)
Rmax 0.82 Hz

Nmin = 216 is necessary to ascertain a maximum of accuracy when applying a frequency


recognition algorithm, in particular for the DFT and the FFT which frequency range is
equidistant sampled. Anticipating, these two algorithm, DFT and the FFT, will fail in
terms of accuracy because the buffer size of Nmin = 216 is too large and would go beyond
the scope of using internal memory only since additional memory capacities for
interleaved complex data and pre-calculated twiddle factors are required.

71
5.4.1.4 Time to settle

The system’s time to settle tsettle is the time which is needed to make sure that the buffer
completely holds the signal’s samples. This quantity is relevant and subject to further
investigations for unbuffered systems only, but because internal buffers are applied, tsettle
is constant the time required for filling up a buffer of the size N. Let the sampling
frequency be fs = 44100Hz and assuming, there is a buffer of the size N = 44100, it takes
one second to acquire all 441000 samples. Therefore, the time to settle tsettle is defined as

N
t settle =
fs (47)

As the sampling rate fs is fixed to 44100Hz and the buffer size N does not change during
the operating mode, the time to settle tsettle is constant for each buffer size N, too.

5.4.1.5 Computational Costs of Investigated Algorithms

The complexities of the to be investigated algorithms are listed for the buffer size N in
table 15.

Table 15: Fourier transform-based algorithmic complexity

Algorithm Complexity

Discrete Fourier Transform (DFT) N2

Fast Fourier Transform (FFT) N · log2(N)

Goertzel algorithm 88 · N

Non-Uniform Discrete Fourier Transform (NDFT) N2

The question is when the DFT, the NDFT or the Goertzel algorithm would theoretically
be faster than the FFT. Taking the algorithmic complexities in table 15 into account, the
following comparisons of the DFT’s or the NDFT’s complexity can be drawn:

72
N ⋅ log 2 ( N ) ≠ N 2 (48)

log 2 ( N ) ≠ N (49)

N ≠ 2N (50)

Equations (48) – (50) finally prove mathematically, that according to their algorithmic
complexity, the DFT and the NDFT will never be equal to the FFT and hence they will
always be more complex than the FFT for each problem size N.

The same investigation is to be made on the complexities of the Goertzel algorithm and
the FFT.

N ⋅ log 2 ( N ) = 88 ⋅ N (51)

log 2 ( N ) = 88 (52)

N = 288 (53)

The comparison of the complexities of the Goertzel algorithm and the FFT shows, that at
a buffer size of N > 288, the FFT’s algorithmic complexity will be greater than the one of
the Goertzel algorithm, but the buffer size required for this problem is unreasonable high
and furthermore not feasible without massive accessing external memory. This, however,
would mean additional latencies and would be a different kind of problem which cannot
be taken into consideration at this stage.

Theoretically, the number of cycles corresponds directly to the algorithmic complexity,


but there is an additional amount of cycles for pre and post processing of audio data to be
regarded, for instance the generation of interleaved complex data, the calculation of
magnitude, the spectrum’s peak detection and the final evaluation of the most powerful
spectral frequency component given as an index as worked out in section 4.2, depicted in
figure 20. Thus, the overall number of cycles has to be measured and taken into account
when analysing the metrics.

73
5.4.2 Performance Metrics

For the evaluation of a system’s real time characteristics, it is necessary to take the
algorithmic properties into account, i.e. their latency, their speedup and the algorithms’
accuracy. These metrics are subject to be discussed in this section.

It is expected that according to the fixed computational costs of each algorithm (section
5.4.1.5) the number of cycles needed for the calculation of each algorithm, will follow the
same law. Consequently, the tendencies of speedup and latency will remain equal with
each measurement and independent from the input, but due to the fact that the number of
cycles are deduced from the computational cost and are therefore theoretical, they have to
be experimentally proven. Therefore and with respect to the fact that pre and post
processing of the data is not included to the theoretical considerations, there is an extra
need for measuring these metrics.

5.4.2.1 Latency

The latency is the time a signal needs to get from its source to its destination after
processing. In the case of frequency recognition as applied in this project, latency is the
difference in time between playing the note and detecting its frequency or in other words
how long an algorithm needs to output the numerical value of the estimated frequency.
Therefore, for the number of cycles an algorithm takes, the latency is defined as

cycles
lt = (54)
f CPU

with a given central processing unit (CPU) frequency of the TI TMS320C6713 of fCPU =
225MHz [18].

The average in latency ltaverage is the average temporal resolution of a human ear, i.e. the
time that can pass by before the listener realises a delay in playing a note and hearing the
actual sound. It has been shown [27, 28] that on average the latency of the human ear is
ltaverage = 50ms. Consequently, in order to be taken seriously into consideration for
frequency recognition in real time, the algorithms have to terminate their calculations

74
within this time limit, preferably less than that because frequency recognition will
probably not be the only task for the GMIS.

5.4.2.2 Speedup

An important metric for the evaluation of is the speedup according to Amdahl’s Law
[29]. The speedup is the ratio of the number of cycles of an algorithm before and after its
improvement and is described as

cyclesDFT
sp =
cycles (55)

The speedup has to be greater than 1 if the algorithm is to be considered superior to any
of the other investigated algorithms. Due to the fact that the Discrete Fourier Transform
(DFT) is the slowest Fourier transform-based algorithm [13], it is taken as a baseline for
the speedup for all the other algorithms.

5.4.2.3 Accuracy

A measure for the accuracy is the absolute deviation. The absolute deviation of a value in
a set of values is the absolute difference between this value and a nominal. This nominal
can either be a mean of the set of these values or a threshold value, in this case the
expected frequency fep. The value from which the absolute difference is taken is the
estimated frequency fes. Being a measure for accuracy, absolute deviation is defined as

ad = f ep − f es (56)

Due to the fact that the tolerance is the half the difference between two MIDI channels, in
the worse case between MIDI note #21 and #22, the minimum acceptable error equals the
maximum spectral resolution required for accurate frequency recognition, i.e. admin =
Rmax = 0.82Hz.

75
6. Results

For obtaining the results given in this chapter, over 9600 single measurements have been
accomplished. As explained in section 5.2, two different categories of input signals have
been applied.

The first category, input signals consisting of a simple sinusoid, is used to measure
latency and speedup in the first step in order to prove the theoretical complexity
discussed in section 5.4.1.5 and second to show the functionality of the investigated
frequency recognition algorithms, i.e. to prove their frequency recognition capability and
to investigate on their accuracy as derived in section 5.4.2.3.

The second category, instrumental inputs playing musical notes, is taken to judge on the
algorithms’ frequency recognition capability for input signals containing complex
waveforms such as in the case of musical notes. By doing this, it will be demonstrated
that a simple frequency recognition algorithm with simple peak power detection as
performed in the first set of measurements, will not suffice for a musical system as
proposed with the GMIS (section 1.1).

6.1 Frequency Recognition Algorithms analysing simple Sinusoids

6.1.1 Latency

The behaviour of the algorithmic latency depends on their individual complexity as


described in section 5.4.1.5. For the regarded frequencies 27.5Hz, 440Hz and 4189Hz,
the latency is equal as it can be seen in figures 45 - 47 which underlines the preliminary
considerations in section 5.2.1. Therefore, just an analysis of the results concerning the
latency’s tendencies for each algorithm is made, not for each frequency in particular.

A measurement of the latency is not obsolete because the additional number of cycles for
the data’s pre processing for preparation and the post processing for finding the
maximum peak in the spectrum have an influence on the latency, too, and hence have to
be taken into account. The question to be answered is, to what extend the actual latency
differs from the average latency of the human ear ltaverage = 50ms.
76
Figures 45 - 47 show the four algorithms’ latency versus the buffer size N for different
inputs containing simple sinusoids of 440Hz, 4186.01Hz and 27.5Hz respectively. The
algorithms with the maximum latency for the whole range of N, with 32 ≤ N ≤ 8192, are
the DFT and the NDFT with a narrow difference to the advantage of the DFT as
expected. This slight difference is due to the fact that the NDFT has to read the vector
with the arbitrarily chosen frequencies whereas the DFT simply uses the equidistant
spectral index k for the computation of the spectrum. According to their equal structure,
the tendency of their latencies is equal, too. As predicted the algorithmic complexity is
for both the DFT and the NDFT N2. The Goertzel algorithm has a smaller latency than
the DFT and NDFT but is, as expected, still slower than the FFT. Unlike the FFT, the
Goertzel algorithm’s latency increases with 88·N. Clearly, but also expected, the FFT is
the algorithm with the least latency. It has a logarithmic increase according to its
complexity N·log2(N).

1.00E+02

1.00E+01

1.00E+00
Latency (s)

1.00E-01 FFT
Goertzel
DFT
1.00E-02 NDFT

1.00E-03

1.00E-04

1.00E-05
10 100 1000 10000
Buffer Size N

Figure 45: Latency vs. Buffer size for a 440Hz input

77
1.00E+02

1.00E+01

1.00E+00
Latency (s)

1.00E-01 FFT
Goertzel
DFT
1.00E-02 NDFT

1.00E-03

1.00E-04

1.00E-05
10 100 1000 10000
Buffer Size N

Figure 46: Latency vs. Buffer size for a 4186.01Hz input


1.00E+02

1.00E+01

1.00E+00
Latency (s)

1.00E-01 FFT
Goertzel
DFT
1.00E-02 NDFT

1.00E-03

1.00E-04

1.00E-05
10 100 1000 10000
Buffer Size N

Figure 47: Latency vs. Buffer size for a 27.5Hz input

Regarding the algorithmic latency with respect to ltaverage, table 16 lists the maximum
buffer size N which still can be used that the latency is not bigger than 50ms. The FFT
and the Goertzel algorithm are valid within a latency of 50ms for the maximum regarded
buffer size of N = 8192. In contrast to this, the DFT and the NDFT are restricted to a
buffer size N = 256 and N = 128 respectively, which are both insufficient in turn for a
solid spectral resolution.

Table 16: Maximum buffer size N for a latency less than 50ms
FFT Goertzel DFT NDFT
N 8192 8192 256 128

78
6.1.2 Speedup

Figures 48 - 50 show the speedup with respect to the buffer size N for 440Hz, 4186.01Hz
and 27.5Hz. Again as expected, since the speedup is also directly linked with the number
of cycles, the three graphs are fairly equal for each input frequency.

Taking the DFT as a baseline, just the NDFT is slightly slower which is due to
implemental reasons, i.e. the reading of the vector of the arbitrary chosen frequencies
takes more time than just simply referring to a loop index, as explained in section 4.2.3.

The Goertzel algorithm with a complexity of 88·N is dramatically faster than the DFT
and the NDFT which computational costs are N2, but is still more slowly than the FFT
with a complexity of N·log2(N), again as expected.

1.00E+04

1.00E+03

1.00E+02
FFT
Speedup

Goertzel
DFT
1.00E+01 NDFT

1.00E+00

1.00E-01
10 100 1000 10000
Buffer Size N

Figure 48: Speedup vs. Buffer size for a 440Hz input

79
1.00E+04

1.00E+03

1.00E+02
FFT
Speedup

Goertzel
DFT
1.00E+01 NDFT

1.00E+00

1.00E-01
10 100 1000 10000
Buffer Size N

Figure 49: Speedup vs. Buffer size for a 4186.01Hz input

1.00E+04

1.00E+03

1.00E+02
FFT
Speedup

Goertzel
DFT
1.00E+01 NDFT

1.00E+00

1.00E-01
10 100 1000 10000
Buffer Size N

Figure 50: Speedup vs. Buffer size for a 27.5Hz input

The analysis of the speedup again, proves, the predictions of the algorithmic complexity
made in section 5.4.1.5. What is more, this interpretation gives evidence that on the one
hand there is an absolute influence of the audio data’s pre and post processing but on the
other hand the tendencies of the speedup remain as predicted. However, it has been
shown in figure 48 - 50 that the total calculation time of the pre and post processing has
to be taken into consideration when evaluating the average latency of the human ear.

80
6.1.3 Accuracy

In order to estimate which is the fastest algorithm for frequency recognition in musical
systems, the investigation on latency and speedup are adequate. The question may arise
why can the fastest algorithm, the FFT, not simply be taken for frequency recognition?
The answer is that, the less time an algorithm needs to fulfil its purpose the better it is,
but the it still has to be accurate enough to meet the requirements.

Thus, the accuracy of each algorithm’s frequency recognition capability has to be


analysed, too, because a fast but inaccurate algorithm is of no use. As defined in section
5.4.2.3, a measure for accuracy is the absolute deviation of the estimated frequency from
the expected frequency, i.e. the absolute difference between these both frequencies. An
important characteristic for the evaluation of the frequency recognition capability is the
knowledge of the minimal spectral resolution for each of the regarded frequency given in
table 22 in appendix A.

The first estimation of the algorithms’ capability to apply accurate frequency recognition
is the analysis of the estimated frequency versus the buffer size N for an input of 440Hz
as depicted in figure 51. The minimal spectral resolution for this frequency, according to
table 22, 12.35Hz, i.e. half the MIDI channel between 440Hz (MIDI note 69) and
415.30Hz (MIDI note 68). From figure 51, it can be seen that all algorithms provide for
an acceptable result in terms of meeting the expected frequency N ≥ 1024.

1.00E+03

9.00E+02

8.00E+02
Estimated Frequency (Hz)

7.00E+02

6.00E+02
FFT
Goertzel
5.00E+02
DFT
4.00E+02 NDFT

3.00E+02

2.00E+02

1.00E+02

0.00E+00
10 100 1000 10000
Buffer Size N

Figure 51: Estimated frequency vs. Buffer size for a 440Hz input
81
600

Absolute deviation from nominal value (Hz)


500

400

FFT
Goertzel
300
DFT
NDFT

200

100

0
10 100 1000 10000
Buffer Size N

Figure 52: Absolute deviation vs. Buffer size for a 440Hz input

A closer look at the absolute deviation from the expected frequency at figure 52 gives
more detailed information about the algorithms’ accuracy. Regarding the fact that a
minimum accuracy of 12.35Hz is required, all algorithm meet this condition at a buffer
size of N ≥ 1024, whereas the DFT and the Goertzel algorithm are more accurate below
this buffer size at N ≥ 256 and N ≥ 128 respectively and provide a good enough lock as
listed in table 17.

Table 17: Minimum buffer size for a sufficient accuracy for 440Hz
FFT Goertzel DFT NDFT
N 1024 128 256 1024

82
4.30E+03

4.20E+03

Estimated Frequency (Hz) 4.10E+03

4.00E+03

FFT
3.90E+03
Goertzel
DFT
3.80E+03
NDFT

3.70E+03

3.60E+03

3.50E+03

3.40E+03
10 100 1000 10000
Buffer Size N

Figure 53: Estimated frequency vs. Buffer size for a 4186.01Hz input
750
700
Absolute deviation from nominal value (Hz)

650
600
550
500
450
FFT
400 Goertzel
350 DFT
300 NDFT

250
200
150
100
50
0
10 100 1000 10000
Buffer Size N

Figure 54: Absolute deviation vs. Buffer size for a 4186.01Hz input

The potential of frequency recognition of all algorithms for an input of 4186.01Hz is


depicted in figure 53. At a buffer size of N ≥ 2048, all algorithms are well behaved.
Based on figure 54 showing the absolute deviation against N and considering the required
accuracy of 117.47Hz (half the channel between 3951.07Hz and 4186.01Hz), table 18
lists the minimum buffer size N which can be used for a sufficient accuracy. N = 256 is
satisfactory for all algorithms whereas the Goertzel algorithm is even better at N = 128.

Table 18: Minimum buffer size for a sufficient accuracy for 4186.01Hz
FFT Goertzel DFT NDFT
N 256 128 256 256

83
7.00E+02

6.00E+02

Estimated Frequency (Hz)


5.00E+02

4.00E+02 FFT
Goertzel
DFT
3.00E+02 NDFT

2.00E+02

1.00E+02

0.00E+00
10 100 1000 10000
Buffer Size N

Figure 55: Estimated frequency vs. Buffer size for a 27.5Hz input
650
600
Absolute deviation from nominal value (Hz)

550

500
450
400
FFT
350 Goertzel
DFT
300
NDFT

250
200
150
100
50

0
10 100 1000 10000
Buffer Size N

Figure 56: Absolute deviation vs. Buffer size for a 27.5Hz input
For an input of 27.5Hz, a more detailed analysis of the accuracy is mandatory due to a
limited tolerance of 0.82Hz (half the spacing between 27.5Hz and 29.14Hz). For a buffer
size of N ≥ 4096 all algorithms are in a reasonable range of accuracy. Consequently, the
absolute deviation from the expected frequency in figure 56 shows that a buffer size of N
≤ 8192 is neither adequate for the FFT and the DFT nor for the Goertzel algorithm,
whereas NDFT is accurate enough at a buffer size of N ≥ 4096, as listed in table 19.

Table 19: Minimum buffer size for a sufficient accuracy for 27.5Hz
FFT Goertzel DFT NDFT
N > 8192 > 8192 4096 4096

84
6.1.4 Comparison of the Investigated Metrics

The latency and speedup metrics have been measured not only to confirm the theoretical
predictions made in section 5.4 but also to investigate the effect of the pre and post
processing of the data such as transforming the audio data into interleaved complex
values for the FFT or finding the most powerful spectral component after transforming
the time signal into the frequency domain and then calculating its magnitude as described
in section 4.3. This pre and post processing is observed as an offset and does not interfere
with the algorithmic tendencies. The tendencies for the latency and speedup for all the
frequencies are congruent for all sinusoidal input frequencies because the algorithms are
independent from the input, a proof of the integrity of all algorithms, which have to be
independent from their input by definition.

From the results presented, it can be seen that the DFT and the NDFT yield the highest
latency due to their equal structure. The NDFT is slightly slower, the speedup with
respect to the DFT is 0.933 on average which is due to the additional reading of the
vector with the arbitrarily chosen frequencies. The Goertzel algorithm is considerably
faster than the DFT and NDFT but definitively slower than the FFT. Its tendency of
latency and speedup is due to its algorithmic complexity of 88·N. The fastest frequency
recognition algorithm is clearly the FFT with a complexity of N·log2(N).

In general, the higher the frequency in a musical system is, the higher is the absolute
tolerance, too, due the non-uniformity of the frequency spacings between neighboured
notes. Therefore, the demand for accuracy is higher regarding lower frequencies. Going
into detail, the input of 27.5Hz has to be considered, which is with a demand for accuracy
of 0.82Hz the most sensitive case. Table 20 shows the minimum demanded buffer sizes N
and their latencies and speedups with respect to this accuracy.

Table 20: Comparing latency and speedup for an input of 27.5Hz


FFT Goertzel DFT NDFT
N > 8192 > 8192 > 8192 4096
Latency [s] > 5.70·10-3 > 43.60·10-3 > 50.20 13.40
Speedup > 8.83·10+3 > 1.15·10+3 1.00 0.93

85
The FFT and the Goertzel algorithm have the best speedup with 8.83·10+3 or 1.15·10+3
respectively, but since both algorithm could not meet the demanded accuracy of 0.82Hz,
a higher spectral resolution in connection to a greater buffer size of Nmin = 216 is required
as worked out in section 5.4.2.3. The DFT is far too slow and inaccurate and is therefore
as expected not to be taken into account for a frequency recognition at all. The NDFT has
an adequate accuracy at a buffer size of N = 4096 but is 13.4s / 0.005s = 268 times too
slow for the average latency of the human ear.

When speaking of accuracy, it is useful to find out the minimum buffer size that is
possible to obtain a sufficient accuracy as summed up in table 21.

Table 21: Comparing minimum buffer sizes for a sufficient accuracy


Frequency FFT Goertzel DFT NDFT
440Hz 1024 128 256 1024
4186.01Hz 256 128 256 256
27.5Hz >8192 >8192 >8192 4096

Inputs of 440Hz and 4186.01Hz are not critical, because their demands for accuracy are
117.47Hz and 12.35Hz respectively and are easier to handle by the system. For these
frequency inputs all frequency recognition algorithms are good enough for a reasonable
buffer size, but as the FFT the fastest algorithm as shown with the latency and speedup, it
is preferable for these frequencies.

The most interesting case is the frequency input of 27.5Hz, where an accuracy of 0.82Hz
is demanded. It has been clearly shown that the FFT, the DFT and the Goertzel algorithm
fail in terms of accuracy. For these two algorithms, a buffer size of N > 8192 is necessary
to meet the constraints. The NDFT, however, is accurate enough for the demanded
spectral resolution of 0.82Hz but is far too slow and beyond the maximum allowed
latency of 50ms.

To summarise, none of the investigated frequency recognition algorithms meet the


constraints of being both accurate and fast enough at the same time for input signals
consisting of simple sinusoids.

86
6.2 Frequency Recognition Algorithms analysing Musical Notes

For signals containing simple unique sinusoids frequency recognition algorithms might
work as it has been shown with the NDFT. Due to the fact that signal generator supports
clear sinusoids which do not change their spectrum over time, frequency recognition is
possible with the constraints as discussed in section 1.1.

The question is whether the frequency recognition algorithms are able to cope with
instrumental inputs. As analysed in section 5.2.1, it has been analytically shown that the
spectrum for a single note over time can join the maximum power on one of their
harmonics rather than on the fundamental frequency, depending on the instrument’s
character. These theoretical assumptions are subject to investigations by interpreting the
measurements (listed in appendix C) in this chapter.

The algorithms’ frequency recognition capabilities are going to be analysed only. The
metrics latency and speedup of each algorithm have already been studied and practically
proven in section 6.1.1 and 6.1.2 respectively. That is why, just the estimated frequency
over time is acquired.

6.2.1 Note C6 (1046.5Hz) for Piano, Violin, Flute and Trumpet

According to table 22, the demanded accuracy for an input of 1046.5Hz is 29.37Hz. In
other words, the maximum upper bound of 1075.87Hz and the minimum lower bound of
1017.13Hz must not be exceeded, in order to ascertain correct frequency recognition for
this note. Analyses from section 5.2.2.1 predict that for a 1046.5Hz input, all the regarded
instruments supply a spectrum which is definite enough for accurate frequency
recognition.

Figure 57 - 58 depict the estimated frequencies over time for an 1046.5Hz input played
by the two string based instruments piano and violin respectively. Since the estimated
frequency is within the boundaries throughout the whole sample’s duration, all
investigated frequency recognition algorithms meet the restrictions for all applied
instrumental inputs.

87
1080.00

1070.00
Estimated frequency [Hz]

1060.00

1050.00 FFT
Goertzel
DFT
1040.00 NDFT

1030.00

1020.00

1010.00
0.00 0.10 0.20 0.30 0.40 0.50 0.60 0.70 0.80 0.90 1.00
t [s]

Figure 57: Estimated frequency vs. time for a 1046.5Hz input (piano)

In particular, for both figure 57 and 58, the Goertzel algorithm is the most accurate
algorithm and estimates 1046.5Hz constantly during the whole sample’s duration. The
FFT is the frequency recognition algorithm with the nearest close accuracy with an
estimated frequency of 1033.99Hz for every moment. The DFT and the NDFT meet the
constraints in terms of accuracy, too. What is interesting is that neither algorithms are
well behaved meaning that the estimated frequency changes during the time. The DFT
fluctuates more than the NDFT, a fact which is due to the equidistant frequency
evaluation which is less fine than the non-uniform frequency evaluation of the NDFT.

1080.00

1070.00
Estimated frequency [Hz]

1060.00

1050.00 FFT
Goertzel
DFT
1040.00 NDFT

1030.00

1020.00

1010.00
0.00 0.50 1.00 1.50 2.00 2.50 3.00
t [s]

Figure 58: Estimated frequency vs. time for a 1046.5Hz input (violin)
88
1110.00

1100.00

1090.00
Estimated frequency [Hz]
1080.00

1070.00
FFT
Goertzel
1060.00
DFT
1050.00 NDFT

1040.00

1030.00

1020.00

1010.00
0.00 0.50 1.00 1.50 2.00 2.50 3.00
t [s]

Figure 59: Estimated frequency vs. time for a 1046.5Hz input (flute)

Regarding figure 59 and 60, both the DFT and the NDFT show a similar behaviour like
for the string based of figure 57 and 58. Both algorithms are accurate enough for meeting
the restrictions but they are fluctuating throughout the whole sample’s duration for both
figure 59 and 60 whereas the DFT appears more stable than the NDFT. Again, the FFT
supplies an accurate frequency estimation within the limits, but is subject to variation for
a violin. The only algorithm, which is unreliable in terms of frequency recognition for
woodwind and brass instruments is the Goertzel algorithm.

1110.00

1100.00

1090.00
Estimated frequency [Hz]

1080.00

1070.00
FFT
Goertzel
1060.00
DFT
1050.00 NDFT

1040.00

1030.00

1020.00

1010.00
0.00 1.00 2.00 3.00 4.00 5.00 6.00 7.00
t [s]

Figure 60: Estimated frequency vs. time for a 1046.5Hz input (trumpet)

89
6.2.2 Note C5 (523.25Hz) for Piano, Violin, Flute and Trumpet

For a string based instrumental input of 523.25Hz all algorithms succeed in estimating
the played note, as shown is figures 61 and 62. Again, the Goertzel algorithm is the most
accurate and hits exactly the expected frequency of 523.25Hz. The FFT is similar to the
previous section the next close frequency recognition algorithm and estimates constantly
517.0Hz over the whole samples’ duration and hence meets the given constraints. As
expected, the DFT and the NDFT fluctuate but are is still in between the upper and lower
bounds of 508.57Hz and 537.93Hz respectively.

540.00

535.00
Estimated frequency [Hz]

530.00

FFT
Goertzel
525.00
DFT
NDFT

520.00

515.00

510.00
0.00 0.20 0.40 0.60 0.80 1.00 1.20 1.40 1.60
t [s]

Figure 61: Estimated frequency vs. time for a 523.25Hz input (piano)

540.00

535.00
Estimated frequency [Hz]

530.00

FFT
Goertzel
525.00
DFT
NDFT

520.00

515.00

510.00
0.00 0.50 1.00 1.50 2.00 2.50
t [s]

Figure 62: Estimated frequency vs. time for a 523.25Hz input (violin)
90
Regarding the measurement results for the flute and the trumpet, a more specific
evaluation is required. Figure 63 shows the estimation capabilities of the four algorithms
for a flute playing MIDI note C5. The DFT, the FFT and the NDFT are vacillating but are
within the desired absolute tolerance of 14.68Hz, meaning that the estimated frequency
does not cross the upper and lower limits of 508.57Hz and 537.93Hz respectively at any
time. In specific, the FFT is the least fluctuating algorithm. In contrast to these three
algorithms, the Goertzel algorithm fails in terms of accuracy.

560.00

550.00
Estimated frequency [Hz]

540.00

530.00 FFT
Goertzel
DFT
520.00 NDFT

510.00

500.00

490.00
0.00 0.50 1.00 1.50 2.00 2.50 3.00
t [s]

Figure 63: Estimated frequency vs. time for a 523.25Hz input (flute)

91
Figure 64 depicts the frequency recognition results a trumpet playing the MIDI note C5 at
523.25Hz. As seen in section 5.2.2.2, the maximal power is not joined at the fundamental
frequency at all but on its second and third harmonics of 1046.5Hz and 1567.98Hz
respectively. According to this preliminary analysis the behaviour of the algorithms as
seen in figure 64 can be explained. For all algorithms, the estimated frequency wobbles
between these two harmonics. Consequently, for a trumpet playing MIDI note C5 it is
impossible to estimate the expected frequency of 523.25Hz regardless what algorithm is
being applied.

1600.00

1500.00
Estimated frequency [Hz]

1400.00

FFT
Goertzel
1300.00
DFT
NDFT

1200.00

1100.00

1000.00
0.00 1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00
t [s]

Figure 64: Estimated frequency vs. time for a 523.25Hz input (trumpet)

92
6.2.3 Note C4 (261.63Hz) for Piano, Violin, Flute and Trumpet

For a string based input of a piano and a violin playing note C4 (261.63Hz) the DFT, the
FFT and the NDFT meet the limits given by the absolute tolerance of 7.34Hz. The DFT
varies within the compulsory boundaries of 254.29Hz and 268.97Hz respectively, and so
does the NDFT but more modest than the DFT. The FFT is not fluctuating at all and stays
constant at an estimated frequency of 258.5Hz. However, the Goertzel algorithm does not
fulfil the required constraints at each moment and is therefore not reliable for recognising
the input’s frequency for these two instruments.

280.00

275.00
Estimated frequency [Hz]

270.00
FFT
Goertzel
DFT
265.00 NDFT

260.00

255.00
0.00 0.50 1.00 1.50 2.00 2.50
t [s]

Figure 65: Estimated frequency vs. time for a 261.63Hz input (piano)
280.00

275.00
Estimated frequency [Hz]

270.00
FFT
Goertzel
DFT
265.00 NDFT

260.00

255.00
0.00 0.50 1.00 1.50 2.00 2.50 3.00
t [s]

Figure 66: Estimated frequency vs. time for a 261.63Hz input (violin)
93
Since the maximum power is not united on the fundamental frequency of the instrumental
input of a trumpet playing the note C4 (261.63Hz) but on their second harmonic at
523.25Hz, all frequency recognition algorithms estimate the frequency within the
constraints of this frequency input correctly. Except for the Goertzel algorithm which
performs constant frequency estimation, the DFT, the FFT and the NDFT vary within the
constraints of 523.25Hz, which are 508.57Hz and 537.93Hz respectively.

530.00

528.00

526.00
Estimated frequency [Hz]

524.00

522.00
FFT
Goertzel
520.00
DFT
518.00 NDFT

516.00

514.00

512.00

510.00
0.00 0.50 1.00 1.50 2.00 2.50 3.00
t [s]

Figure 67: Estimated frequency vs. time for a 261.63Hz input (flute)

94
1600.00

1500.00

1400.00
Estimated frequency [Hz]

FFT
Goertzel
1300.00
DFT
NDFT

1200.00

1100.00

1000.00
0.00 1.00 2.00 3.00 4.00 5.00 6.00 7.00
t [s]

Figure 68: Estimated frequency vs. time for a 261.63Hz input (trumpet)

For the note C4 (261.63Hz) played by a trumpet as shown in figure 68, the maximum
spectral distribution of the power changes between the fourth (1046.5Hz) and sixth
harmonic (1569.98Hz), a huge difference to the instrumental input of note C4 which
fundamental frequency is at 261.63Hz. All the algorithms estimate these both overtones
at 1046.5Hz and 1569.98Hz respectively because of the reasons stated above. Hence and
to anticipate at this stage, a simple application of the frequency recognition algorithms is
not sufficient when playing note C6 with a trumpet.

6.2.4 Comparison of Frequency Recognition Capability for Musical Notes

Generally, the forecasted behaviour in section 5.2.2 has been confirmed by applying
instruments playing musical notes to the frequency recognition algorithms. As predicted,
a frequency analysis of instrument based inputs needs to be regarded individually for
each note. The investigated musical instruments, the piano, violin, flute and trumpet
differ in the spectral distribution of their power and for some of the regarded notes, this
power distribution even changes over time.

Going into detail, the DFT, the FFT and the NDFT are able to estimate the expected
frequency within the given constraints for note C6 for each instrument; for note C5 for all
instruments except the trumpet and for C4 for string based instruments only, i.e. the piano
and the violin.
95
Also, as expected, all algorithms fail in terms of estimating the fundamental frequency
for the trumpet playing note C5 and even for both flute and trumpet producing note C4
due to the fact that the maximum power for the notes played by these instruments is
joined at their harmonics as shown in section 5.2.2.3. In particular, note C5 (523.25Hz)
played by a trumpet, holds its maximum power on its second harmonic 1046.5Hz as
analytical shown and experimental verified. In specific, for note C4 (261.63Hz) played
by a flute, the maximum power can be found at the second harmonic at 523.25Hz, the
reason why the peak detection mechanism of all algorithms estimates this frequency. For
a trumpet playing note C4, it has been theoretically and experimentally shown that it is
even more difficult to find the correct expected frequency because the maximum power is
present at both the fourth and sixth harmonic of 1046.5Hz and 1569.98Hz respectively.

The exception is the Goertzel algorithm. It identifies the correct frequency of the piano
and violin for the notes C6 and C5 on the one hand, but does not confirm the expected
results of estimating flute and trumpet playing note C6, the flute producing C5 and the
piano and the violin playing note C4 on the other hand. Taking this behaviour of the
Goertzel algorithm for analysing instrumental inputs and the interpretation of the results
for sinusoidal signals in section 6.1 into account, it has been shown that although the
Goertzel algorithm is a well-proven technique for estimating simple signals with clear
single sinusoids in DTMF systems, it definitely fails for signals with more complex
waveforms such as those produced by musical instruments.

Regarding the algorithms’ frequency recognition capability only, it has been uniquely
shown in section 6.1, that frequency recognition algorithms estimate frequencies of
signals containing a simple sinusoid in most of the measured cases without
complications, whereas the frequency recognition capability of each algorithm varies due
to each individual nature. However, when analysing instruments playing musical notes, it
has to be taken into account that the lower the frequency is, the higher is the number of
harmonics As shown in section 6.2. As long as the maximum power is at the fundamental
frequency, the peak detection algorithm estimates the correct frequency as it is the case
with the string based instruments piano and violin. If the maximum spectral power is on
one of the harmonics as been shown for note C5 played by the trumpet and for note C4
produced by trumpet and flute, a valid frequency estimation as implemented with the four
algorithms, is not possible. Consequently, it can be clearly stated that an exclusive
application of frequency recognition algorithms is insufficient for a definite frequency
recognition of musical notes.
96
7. Conclusions and Future Work

This dissertation details the theory behind a novel Generic Musical Instrument System
(GMIS) and provides an analysis of the possibilities to adapt the advantageous techniques
of Dual-Tone Multi-Frequency (DTMF) systems to musical systems such as the GMIS.

Four different Fourier transform-based frequency recognition algorithms have been


analysed: the Discrete Fourier Transform (DFT) as a baseline for the evaluation of all
algorithms, the Fast Fourier Transform (FFT) which is used in most of the engineering
applications, the Goertzel algorithm and the Non-Uniform Discrete Fourier Transform
(NDFT) which are both successfully applied to DTMF systems.

All algorithms have been analysed with respect to the metrics latency, speedup, accuracy
and their frequency recognition capabilities both to signals containing simple sinusoids
and to musical notes played by instruments, i.e. a piano, a violin, a flute and a trumpet.

7.1 Frequency Recognition Algorithms analysing Simple Sinusoids

For input signals containing simple sinusoids, the DFT and the NDFT are far too slow
due to their complexity of N2. In contrast to them, the FFT is, as expected, clearly the
fastest Fourier transform-based algorithm, followed by the Goertzel algorithm. Both
algorithms are fast enough to undercut the average latency of a human ear of 50ms.

The question is, why can the fastest algorithm, the FFT, not be taken to recognise
frequencies in real time and with respect to the constraints of the GMIS? To find the
answer to this question, the accuracy has to be taken into account because a fast but
inaccurate algorithm is of no use.

For frequency inputs with lower demands on the spectral resolution, i.e. for inputs of
440Hz and 4186.01Hz, all analysed frequency recognition algorithms are accurate
enough for a reasonable buffer size of N ≥ 1024 and N ≥ 256 respectively. For a 27.5Hz
input, however, the DFT, the FFT and the Goertzel algorithm fail as they do not meet the
necessary accuracy of 0.82Hz. The only exception is the NDFT which provides a

97
sufficient accuracy for a problem size of N ≥ 4096, but is slower than the allowed latency
of 50ms.

Thus, the conclusion for the four investigated Fourier transform-based frequency
recognition algorithms is that none of them can be assigned to musical systems such as
the GMIS in real time, Consequently, for future work on Fourier transform-based
algorithms, a Non-Uniform Fast Fourier Transform (NFFT) could be subject to a further
analysis to combine the accuracy of the NDFT and the speed of the FFT in conjunction
with windowing for accuracy reasons.

7.2 Frequency Recognition Algorithms analysing Musical Notes

The theoretical and experimental investigations in section 5.2.2 and 6.2 on the spectra of
musical notes played by a piano, a violin, a flute and a trumpet respectively, have shown
that each note played by a different instrument has its individual character. The
assumptions made in section 5.3 based on an analysis of spectra vs. time vs. amplitude
could be confirmed in most of the cases.

In specific, the DFT, the FFT and the NDFT estimate the correct frequencies for all
instruments playing note C6 and C5 except for a trumpet playing note C5. For note C4,
only the sting-based instruments succeed. This behaviour is due to the fact that the
maximum spectral power is held by the fundamental frequency.

Generally, the analysis and observation show that the lower the frequency is the higher is
the number of harmonics. This is not critical in these cases, if the maximum spectral
power is actually on the fundamental frequency. If the maximum spectral power is with
one of the harmonics, the peak detection algorithm will estimate this frequency. This is
the case for the flute playing note C4 and the trumpet playing note C4 and C5.

It has been worked out, that the Goertzel algorithm estimates the correct frequency of
note C6 played by the piano and the violin, but it fails for all other analysed musical notes
and does not estimate the frequencies as predicted in section 5.2.2. Thus, though the
Goertzel algorithm is a well-proven frequency estimation technique in DTMF systems
and succeeds in finding the correct frequency when analysing simple sinusoids, it is
absolutely unreliable in terms of frequency recognition for musical notes. That is why,
98
this algorithm cannot be considered as a candidate for frequency recognition of complex
waveforms as it is required for musical systems such as the GMIS.

To summarise, since it cannot be guaranteed that the spectral power is held by the
fundamental frequency on every note and therefore a peak detection algorithm detects
one of their harmonics holding this power instead, an exclusive application of Fourier
transform-based algorithms is definitely not sufficient enough in order to ascertain
correct frequency recognition. Thus, for future work, additional mechanisms have to be
considered, such as neural network or adaptive filter based instrument recognition.

7.3 Alternatives

Investigations on Fourier transform-based frequency recognition algorithms analysing


simple sinusoidal signals have shown that the considered algorithms fail either in terms
of calculation speed (DFT and NDFT) or in terms of accuracy (DFT, FFT and the
Goertzel algorithm). Therefore, following the avenue of Fourier transform-based
frequency recognition algorithms, further research could be done on a Non-Uniform Fast
Fourier Transformation (NFFT).

It has been shown that the frequency recognition capability of the investigated Fourier
transform-based algorithms is not satisfactorily enough according to the constraints of the
GMIS. Thus, frequency recognition algorithms using spectral power estimation could be
subject to continuative research. Two representatives of this algorithm category are the
Normalised Direct Frequency Estimation Technique (NDFET) [30] and the MUltiple
Signal Classification (MUSIC) algorithm [31].

The Normalised Direct Frequency Estimation Technique (NDFET) is an iterative


adaptive filter, based on the Least Mean Square (LMS) algorithm [32] and is used in
DTMF systems. By estimating an error from the adaptive filter output and the reference
signal, the filter coefficients are re-calculated. If the error is within the given bounds, the
estimated frequency can be considered as successfully determined. This algorithm could
be a promising approach to estimate a signal’s frequency within the real time constraints
of the GMIS.

99
The other proposed frequency recognition algorithm, the MUltiple SIgnal Classification
(MUSIC) algorithm, is a power spectral estimation method [31] which is used for radar
application in GHz frequency ranges and works even under a low signal-to-noise-ratio
(SNR). Further investigations on this method should ascertain whether this algorithm is
applicable to the audible range of a human being.

However, in long terms, the outlook is that an exclusive application of frequency


recognition algorithms is not enough as the spectra of instruments playing musical notes
are individual and it has been shown that the maximum spectral power is not necessarily
on the fundamental frequency for all musical notes. Thus, additional mechanisms such as
instrument recognition have to be taken into consideration for future work, which could
be achieved by the use of algorithms based on neural networks or adaptive filtering.

100
References

[1] ITU Blue Book, Recommendation Q.24: Multi-Frequency Push-Button Signal Reception, Geneva,
1989
[2] MIDI detailed specification, The International MIDI Association, http://www.midi.org

[3] P. White, “Basic MIDI”, MPG Books Ltd, Bodmin, 1999, ISBN: 1 86074 262 9

[4] R. Dobson, “A dictionary of Electronic and Computer Music Technology”, Oxford University
Press, 1992
[5] J. Backus, “The acoustical foundations of music”, Latimer Trend & Co. Ltd. Whitstable, 1970

[6] International Standards Organisation (ISO), “Acoustics - Standard tuning frequency (Standard
musical pitch)”, ISO 16:1975, 1975
[7] H. Nyquist, "Certain topics in telegraph transmission theory", Trans. AIEE, vol. 47, pp. 617-644,
Apr. 1928
[8] C. E. Shannon, "Communication in the presence of noise", Proc. Institute of Radio Engineers, vol.
37, no.1, pp. 10-21, Jan. 1949
[9] Red Book, latest version May 1999, http://www.licensing.philips.com/information/cd/audio/

[10] E. C. Ifeacher, B. W. Jervis, “Digital Signal Processing: A Practical Approach”, Addison-Wesley,


ISBN 0-201-54413-X
[11] W.W. Rouse Ball, “A short account of the history of mathematics”, 4th edition, Macmillan and Co.,
Ltd., 1908
[12] J. Fourier, "Théorie analytique de la chaleur", Editions Jaques Gabbay, reprint 1988, ISBN 2-87647-
046-2
[13] E. O. Brigham, “The Fast Fourier Transform and its applications”, Prentice Hall, 1988

[14] S. Bagchi, S. Mitra, “The Non-Uniform Discrete Fourier Transform and its Applications in Signal
Processing”, Kluwer Academic Publishers, ISBN 0-7923-8281-1
[15] A. V. Oppenheim, R. W. Schafer, "Digital Signal Processing", Prentice-Hall, 1985

[16] W. W. Smith, J. M. Smith, "Handbook of Real-Time Fast Fourier Transforms", IEEE Press, 1995

[17] F. J. Harris, "On the use of Windows for Harmonic Analysis with the Discrete Fourier Transform",
Proceedings of the IEEE, Vol. 66, No. 1, 1978
[18] Texas Instruments, "Datasheet, TMS320C6713, TMS320C6713B Floating-Point DSPs"
(tms320c6713), http://focus.ti.com/docs/prod/folders/print/tms320c6713.html
[19] Texas Instruments, "TMS320C6000 Chip Support Library API Reference Guide" (spru401i),
http://focus.ti.com/docs/toolsw/folders/print/sprc090.html
[20] Texas Instruments, "TLV320AIC23 Data Manual" (tlv320aic23),
http://focus.ti.com/docs/prod/folders/print/tlv320aic23.html
101
[21] Texas Instruments, "TMS320c6416/C6713 DSK One-Day Workshop", Rev. 3.1, August 2003

[22] Texas Instruments, "TMS320C67x FastRTS Library Programmer's Reference" (spru100a),


http://focus.ti.com/docs/toolsw/folders/print/sprc090.html
[23] Massachusetts Institute of Technology (MIT), "Fastest Fourier Transform in the West (FFTW)",
http://www.fftw.org/, May 2004
[24] Texas Instruments, "TMS320c62x/C67x Programmer's Guide" (sprc198),
http://focus.ti.com/docs/toolsw/folders/print/sprc198.html
[25] Texas Instruments, "TMS320C67x DSP Library Programmer’s Reference Guide" (spru657),
http://focus.ti.com/lit/ug/spru657/spru657.pdf
[26] Texas Instruments, "TMS320C67x Digital Signal Processing Library (DSPLIB)" (sprc121),
http://focus.ti.com/docs/toolsw/folders/print/sprc121.html
[27] C. Roads, “The Computer Music Tutorial”, 2nd ed., Massachusetts Institute of Technology, 1996

[28] U. Zölzer (editor), “DAFX: Digital Audio Effects”, John Wiley and Sons, Ltd, April 2003, ISBN 0
471 49087 4
[29] J. L. Hennessy, D. A. Patterson, “Computer Architecture A Quantitative Approach”, 2nd ed.,
Morgan Kaufmann Publishers, Inc., 1996
[30] J. Y. Cheung, “A direct adaptive frequency estimation technique”, Midwest Symposium on Circuits
and Systems, pp. 804 – 807, 1987.
[31] T. Iwata, Y. Goto, H. Susaki, “Application of the multiple signal classification (MUSIC) method for
one-pulse burst-echo Doppler sonar data”, Measurement, Science and Technology, 2001
[32] B. Widrow, S. D. Stearns, "Adaptive Signal Processing", Prentice-Hall, 1985

102
Appendix A: MIDI Numbers and Corresponding Frequencies

Table 22: MIDI numbers and corresponding frequencies


MIDI Frequency Absolute MIDI Frequency Absolute
Note Note
number [Hz] Tolerance [Hz] number [Hz] Tolerance [Hz]
21 A0 27.50 - 65 F4 349.23 9.80
22 A0# 29.14 0.82 66 F4# 369.99 10.38
23 B0 30.87 0.87 67 G4 392.00 11.00
24 C1 32.70 0.92 68 G4# 415.30 11.65
25 C1# 34.65 0.97 69 A4 440.00 12.35
26 D1 36.71 1.03 70 A4# 466.16 13.08
27 D1# 38.89 1.09 71 B4 493.88 13.86
28 E1 41.20 1.16 72 C5 523.25 14.68
29 F1 43.65 1.23 73 C5# 554.37 15.56
30 F1# 46.25 1.30 74 D5 587.33 16.48
31 G1 49.00 1.38 75 D5# 622.25 17.46
32 G1# 51.91 1.46 76 E5 659.26 18.50
33 A1 55.00 1.54 77 F5 698.46 19.60
34 A1# 58.27 1.64 78 F5# 739.99 20.77
35 B1 61.74 1.73 79 G5 783.99 22.00
36 C2 65.41 1.84 80 G5# 830.61 23.31
37 C2# 69.30 1.94 81 A5 880.00 24.70
38 D2 73.42 2.06 82 A5# 932.33 26.16
39 D2# 77.78 2.18 83 B5 987.77 27.72
40 E2 82.41 2.31 84 C6 1046.50 29.37
41 F2 87.31 2.45 85 C6# 1108.73 31.11
42 F2# 92.50 2.60 86 D6 1174.66 32.96
43 G2 98.00 2.75 87 D6# 1244.51 34.92
44 G2# 103.83 2.91 88 E6 1318.51 37.00
45 A2 110.00 3.09 89 F6 1396.91 39.20
46 A2# 116.54 3.27 90 F6# 1479.98 41.53
47 B2 123.47 3.46 91 G6 1567.98 44.00
48 C3 130.81 3.67 92 G6# 1661.22 46.62
49 C3# 138.59 3.89 93 A6 1760.00 49.39
50 D3 146.83 4.12 94 A6# 1864.66 52.33
51 D3# 155.56 4.37 95 B6 1975.53 55.44
52 E3 164.81 4.63 96 C7 2093.00 58.74
53 F3 174.61 4.90 97 C7# 2217.46 62.23
54 F3# 185.00 5.19 98 D7 2349.32 65.93
55 G3 196.00 5.50 99 D7# 2489.02 69.85
56 G3# 207.65 5.83 100 E7 2637.02 74.00
57 A3 220.00 6.17 101 F7 2793.83 78.40
58 A3# 233.08 6.54 102 F7# 2959.96 83.06
59 B3 246.94 6.93 103 G7 3135.96 88.00
60 C4 261.63 7.34 104 G7# 3322.44 93.24
61 C4# 277.18 7.78 105 A7 3520.00 98.78
62 D4 293.66 8.24 106 A7# 3729.31 104.66
63 D4# 311.13 8.73 107 B7 3951.07 110.88
64 E4 329.63 9.25 108 C8 4186.01 117.47

103
Appendix B: Measurement Results for Sinusoidal Inputs

Table 23: Measurement results for a sinusoidal input of 440Hz


Average estimated frequency [Hz] Average cycles
N FFT Goertzel DFT NDFT N FFT Goertzel DFT NDFT
32 2.76E+02 9.66E+02 1.38E+02 2.15E+02 32 4.64E+03 8.54E+04 1.87E+05 2.01E+05
64 6.89E+02 6.12E+02 4.83E+02 3.09E+02 64 9.13E+03 1.22E+05 7.18E+05 7.69E+05
128 3.45E+02 4.36E+02 3.10E+02 4.20E+02 128 1.83E+04 1.96E+05 2.81E+06 3.01E+06
256 3.45E+02 4.50E+02 4.31E+02 4.27E+02 256 3.67E+04 3.43E+05 1.11E+07 1.19E+07
512 4.83E+02 4.28E+02 4.39E+02 4.23E+02 512 7.37E+04 6.37E+05 4.41E+07 4.73E+07
1024 4.31E+02 4.33E+02 4.44E+02 4.37E+02 1024 1.50E+05 1.23E+06 1.76E+08 1.89E+08
2048 4.31E+02 4.46E+02 4.31E+02 4.42E+02 2048 3.14E+05 2.49E+06 7.05E+08 7.55E+08
4096 4.31E+02 4.40E+02 4.37E+02 4.41E+02 4096 6.36E+05 4.93E+06 2.82E+09 3.02E+09
8192 4.42E+02 4.38E+02 4.39E+02 4.39E+02 8192 1.28E+06 9.80E+06 1.13E+10 1.21E+10

Latency [s] f_CPU[Hz] 2.25E+08 Speedup


N FFT Goertzel DFT NDFT N FFT Goertzel DFT NDFT
32 2.06E-05 3.80E-04 8.31E-04 8.93E-04 32 4.03E+01 2.19E+00 1.00E+00 9.30E-01
64 4.06E-05 5.42E-04 3.19E-03 3.42E-03 64 7.86E+01 5.89E+00 1.00E+00 9.34E-01
128 8.13E-05 8.71E-04 1.25E-02 1.34E-02 128 1.54E+02 1.43E+01 1.00E+00 9.34E-01
256 1.63E-04 1.52E-03 4.93E-02 5.29E-02 256 3.02E+02 3.24E+01 1.00E+00 9.33E-01
512 3.28E-04 2.83E-03 1.96E-01 2.10E-01 512 5.98E+02 6.92E+01 1.00E+00 9.32E-01
1024 6.67E-04 5.47E-03 7.82E-01 8.40E-01 1024 1.17E+03 1.43E+02 1.00E+00 9.31E-01
2048 1.40E-03 1.11E-02 3.13E+00 3.36E+00 2048 2.25E+03 2.83E+02 1.00E+00 9.34E-01
4096 2.83E-03 2.19E-02 1.25E+01 1.34E+01 4096 4.43E+03 5.72E+02 1.00E+00 9.34E-01
8192 5.69E-03 4.36E-02 5.02E+01 5.38E+01 8192 8.83E+03 1.15E+03 1.00E+00 9.34E-01

Absolute deviation [Hz] f_signal [Hz] 440


N FFT Goertzel DFT NDFT
32 1.64E+02 5.26E+02 3.02E+02 2.25E+02
64 2.49E+02 1.72E+02 4.30E+01 1.31E+02
128 9.50E+01 4.00E+00 1.30E+02 2.00E+01
256 9.50E+01 1.00E+01 9.00E+00 1.30E+01
Demand for spectral resolution: 12.35Hz
512 4.30E+01 1.20E+01 1.00E+00 1.70E+01
1024 9.00E+00 7.00E+00 4.00E+00 3.00E+00
2048 9.00E+00 6.00E+00 9.00E+00 2.00E+00
4096 9.00E+00 0.00E+00 3.00E+00 1.00E+00
8192 2.00E+00 2.00E+00 1.00E+00 1.00E+00

104
Table 24: Measurement results for a sinusoidal input of 4186.01Hz
Average estimated frequency [Hz] Average cycles
N FFT Goertzel DFT NDFT N FFT Goertzel DFT NDFT
32 3.58E+03 3.46E+03 3.86E+03 3.62E+03 32 4.64E+03 8.58E+04 1.87E+05 2.01E+05
64 4.14E+03 3.91E+03 3.72E+03 3.75E+03 64 9.13E+03 1.22E+05 7.18E+05 7.69E+05
128 3.79E+03 4.07E+03 3.72E+03 3.72E+03 128 1.83E+04 1.96E+05 2.81E+06 3.01E+06
256 4.14E+03 4.16E+03 4.19E+03 4.21E+03 256 3.66E+04 3.43E+05 1.11E+07 1.19E+07
512 4.14E+03 4.16E+03 4.20E+03 4.18E+03 512 7.37E+04 6.37E+05 4.41E+07 4.73E+07
1024 4.22E+03 4.19E+03 4.18E+03 4.18E+03 1024 1.51E+05 1.23E+06 1.76E+08 1.89E+08
2048 4.18E+03 4.19E+03 4.19E+03 4.19E+03 2048 3.14E+05 2.49E+06 7.05E+08 7.55E+08
4096 4.18E+03 4.19E+03 4.19E+03 4.19E+03 4096 6.36E+05 4.93E+06 2.82E+09 3.02E+09
8192 4.19E+03 4.19E+03 4.19E+03 4.19E+03 8192 1.28E+06 9.80E+06 1.13E+10 1.21E+10

Latency [s] f_CPU[Hz] 2.25E+08 Speedup


N FFT Goertzel DFT NDFT N FFT Goertzel DFT NDFT
32 2.06E-05 3.81E-04 8.31E-04 8.93E-04 32 4.03E+01 2.18E+00 1.00E+00 9.30E-01
64 4.06E-05 5.42E-04 3.19E-03 3.42E-03 64 7.86E+01 5.89E+00 1.00E+00 9.34E-01
128 8.13E-05 8.71E-04 1.25E-02 1.34E-02 128 1.54E+02 1.43E+01 1.00E+00 9.34E-01
256 1.63E-04 1.52E-03 4.93E-02 5.29E-02 256 3.03E+02 3.24E+01 1.00E+00 9.33E-01
512 3.28E-04 2.83E-03 1.96E-01 2.10E-01 512 5.98E+02 6.92E+01 1.00E+00 9.32E-01
1024 6.71E-04 5.47E-03 7.82E-01 8.40E-01 1024 1.17E+03 1.43E+02 1.00E+00 9.31E-01
2048 1.40E-03 1.11E-02 3.13E+00 3.36E+00 2048 2.25E+03 2.83E+02 1.00E+00 9.34E-01
4096 2.83E-03 2.19E-02 1.25E+01 1.34E+01 4096 4.43E+03 5.72E+02 1.00E+00 9.34E-01
8192 5.69E-03 4.36E-02 5.02E+01 5.38E+01 8192 8.83E+03 1.15E+03 1.00E+00 9.34E-01

Absolute deviation [Hz] f_signal [Hz] 4186.01


N FFT Goertzel DFT NDFT
32 6.06E+02 7.26E+02 3.26E+02 5.66E+02
64 4.60E+01 2.76E+02 4.66E+02 4.36E+02
128 3.96E+02 1.16E+02 4.66E+02 4.66E+02
256 4.60E+01 2.60E+01 3.99E+00 2.40E+01
Demand for spectral resolution: 117.47Hz
512 4.60E+01 2.60E+01 1.40E+01 6.01E+00
1024 3.40E+01 3.99E+00 6.01E+00 6.01E+00
2048 6.01E+00 3.99E+00 3.99E+00 3.99E+00
4096 6.01E+00 3.99E+00 3.99E+00 3.99E+00
8192 3.99E+00 3.99E+00 3.99E+00 3.99E+00

105
Table 25: Measurement results for a sinusoidal input of 27.5Hz
Average estimated frequency [Hz] Average cycles
N FFT Goertzel DFT NDFT N FFT Goertzel DFT NDFT
32 5.51E+02 6.46E+02 1.38E+02 5.67E+02 32 4.45E+03 8.54E+04 1.87E+05 2.01E+05
64 1.38E+02 3.09E+02 2.07E+02 1.20E+02 64 9.13E+03 1.22E+05 7.18E+05 7.69E+05
128 0.00E+00 1.38E+02 0.00E+00 6.76E+01 128 1.83E+04 1.95E+05 2.81E+06 3.01E+06
256 3.45E+01 1.06E+02 5.17E+01 6.92E+01 256 3.66E+04 3.43E+05 1.11E+07 1.19E+07
512 1.72E+01 5.57E+01 3.45E+01 7.20E+01 512 7.37E+04 6.37E+05 4.41E+07 4.73E+07
1024 1.72E+01 3.45E+01 3.02E+01 3.46E+01 1024 1.51E+05 1.23E+06 1.76E+08 1.89E+08
2048 2.15E+01 3.23E+01 2.15E+01 3.23E+01 2048 3.14E+05 2.49E+06 7.05E+08 7.55E+08
4096 2.15E+01 3.05E+01 3.02E+01 2.78E+01 4096 6.36E+05 4.93E+06 2.82E+09 3.02E+09
8192 2.91E+01 2.93E+01 2.85E+01 2.80E+01 8192 1.28E+06 9.80E+06 1.13E+10 1.21E+10

Latency [s] f_CPU[Hz] 2.25E+08 Speedup


N FFT Goertzel DFT NDFT N FFT Goertzel DFT NDFT
32 1.98E-05 3.80E-04 8.31E-04 8.93E-04 32 4.20E+01 2.19E+00 1.00E+00 9.30E-01
64 4.06E-05 5.42E-04 3.19E-03 3.42E-03 64 7.86E+01 5.89E+00 1.00E+00 9.34E-01
128 8.13E-05 8.67E-04 1.25E-02 1.34E-02 128 1.54E+02 1.44E+01 1.00E+00 9.34E-01
256 1.63E-04 1.52E-03 4.93E-02 5.29E-02 256 3.03E+02 3.24E+01 1.00E+00 9.33E-01
512 3.28E-04 2.83E-03 1.96E-01 2.10E-01 512 5.98E+02 6.92E+01 1.00E+00 9.32E-01
1024 6.71E-04 5.47E-03 7.82E-01 8.40E-01 1024 1.17E+03 1.43E+02 1.00E+00 9.31E-01
2048 1.40E-03 1.11E-02 3.13E+00 3.36E+00 2048 2.25E+03 2.83E+02 1.00E+00 9.34E-01
4096 2.83E-03 2.19E-02 1.25E+01 1.34E+01 4096 4.43E+03 5.72E+02 1.00E+00 9.34E-01
8192 5.69E-03 4.36E-02 5.02E+01 5.38E+01 8192 8.83E+03 1.15E+03 1.00E+00 9.34E-01

Absolute deviation [Hz] f_signal [Hz] 27.5


N FFT Goertzel DFT NDFT
32 5.24E+02 6.19E+02 1.11E+02 5.40E+02
64 1.11E+02 2.82E+02 1.80E+02 9.25E+01
128 2.75E+01 1.11E+02 2.75E+01 4.01E+01
256 7.00E+00 7.85E+01 2.42E+01 4.17E+01
Demand for spectral resolution: 0.82Hz
512 1.03E+01 2.82E+01 7.00E+00 4.45E+01
1024 1.03E+01 7.00E+00 2.70E+00 7.10E+00
2048 6.00E+00 4.80E+00 6.00E+00 4.80E+00
4096 6.00E+00 3.00E+00 2.70E+00 3.00E-01
8192 1.60E+00 1.80E+00 1.00E+00 5.00E-01

106
Appendix C: Measurement Results for Inputs of Musical Notes

Table 26: Estimated frequencies for instrumental inputs of 1046.5Hz


Flute C6 Estimated frequency [Hz] Piano C6 Estimated frequency [Hz]
t [s] FFT Goertzel DFT NDFT t [s] FFT Goertzel DFT NDFT
0.00 1033.99 1108.73 1069.02 1069.13 0.00 1033.99 1046.50 1033.99 1046.50
0.24 1033.99 1046.50 1033.99 1031.82 0.11 1033.99 1046.50 1069.02 1063.47
0.48 1069.02 1046.50 1033.99 1052.16 0.22 1033.99 1046.50 1033.99 1046.50
0.71 1033.99 1046.50 1033.99 1022.03 0.33 1033.99 1046.50 1033.99 1046.50
0.95 1033.99 1108.73 1033.99 1063.47 0.44 1033.99 1046.50 1033.99 1052.16
1.19 1033.99 1046.50 1033.99 1022.03 0.56 1033.99 1046.50 1069.02 1057.82
1.43 1069.02 1046.50 1069.02 1063.47 0.67 1033.99 1046.50 1069.02 1052.16
1.67 1069.02 1108.73 1033.99 1063.47 0.78 1033.99 1046.50 1033.99 1046.50
1.90 1069.02 1046.50 1033.99 1041.61 0.89 1033.99 1046.50 1033.99 1052.16
2.14 1069.02 1046.50 1052.13 1057.82 1.00 1033.99 1046.50 1069.02 1046.50
2.38 1033.99 1046.50 1069.02 1041.61
2.62 1033.99 1108.73 1033.99 1069.13
2.86 1033.99 1046.50 1069.02 1041.61 Trumpet C6 Estimated frequency [Hz]
3.09 1033.99 1046.50 1069.02 1041.61 t [s] FFT Goertzel DFT NDFT
3.33 1033.99 1046.50 1033.99 1046.50 0.00 1033.99 1046.50 1033.99 1041.61
0.44 1033.99 1046.50 1069.02 1036.71
Violin C6 Estimated frequency [Hz] 0.87 1033.99 1046.50 1069.02 1074.79
t [s] FFT Goertzel DFT NDFT 1.31 1033.99 1046.50 1033.99 1074.79
0.00 1033.99 1046.50 1033.99 1036.71 1.74 1033.99 1046.50 1033.99 1069.13
0.26 1033.99 1046.50 1069.02 1036.71 2.18 1033.99 1046.50 1033.99 1057.82
0.51 1033.99 1046.50 1033.99 1026.92 2.62 1033.99 1046.50 1033.99 1052.16
0.77 1033.99 1046.50 1033.99 1022.03 3.05 1033.99 1046.50 1033.99 1052.16
1.03 1033.99 1046.50 1069.02 1022.03 3.49 1033.99 1046.50 1033.99 1041.61
1.28 1033.99 1046.50 1069.02 1052.16 3.92 1033.99 1046.50 1033.99 1046.50
1.54 1033.99 1046.50 1033.99 1052.16 4.36 1033.99 1046.50 1033.99 1046.50
1.80 1033.99 1046.50 1069.02 1046.50 4.80 1033.99 1046.50 1033.99 1046.50
2.05 1033.99 1046.50 1033.99 1036.71 5.23 1033.99 1108.73 1033.99 1046.50
2.31 1033.99 1046.50 1033.99 1052.16 5.67 1033.99 1046.50 1033.99 1046.50
2.56 1033.99 1046.50 1033.99 1041.61 6.10 1033.99 1046.50 1033.99 1046.50
2.82 1033.99 1046.50 1069.02 1041.61 6.54 1033.99 1046.50 1069.02 1046.50
3.08 1033.99 1046.50 1069.02 1041.61 6.98 1033.99 1046.50 1033.99 1074.79
3.33 1033.99 1046.50 1033.99 1036.71 7.41 1033.99 1046.50 1033.99 1069.13

107
Table 27: Estimated frequencies for instrumental inputs of 523.25Hz
Flute C5 Estimated frequency [Hz] Piano C5 Estimated frequency [Hz]
t [s] FFT Goertzel DFT NDFT t [s] FFT Goertzel DFT NDFT
0.00 517.00 523.25 517.00 537.51 0.00 517.00 523.25 517.00 533.62
0.24 517.00 523.25 517.00 514.31 0.20 517.00 523.25 517.00 529.73
0.48 517.00 523.25 517.00 528.44 0.40 517.00 523.25 532.63 523.25
0.71 517.00 523.25 517.00 520.70 0.60 517.00 523.25 532.63 524.55
0.95 517.00 493.88 517.00 524.55 0.80 517.00 523.25 517.00 523.25
1.19 517.00 554.37 517.00 525.84 1.00 517.00 523.25 517.00 523.25
1.43 517.00 554.37 532.63 528.44 1.19 517.00 523.25 517.00 516.87
1.67 517.00 493.88 532.63 532.33 1.39 517.00 523.25 517.00 531.03
1.90 517.00 523.25 517.00 531.03 1.59 517.00 523.25 532.63 525.84
2.14 517.00 523.25 517.00 528.44 1.79 517.00 523.25 517.00 524.55
2.38 517.00 523.25 517.00 521.97
2.62 517.00 523.25 517.00 527.14
2.86 517.00 523.25 532.63 528.44 Trumpet C5 Estimated frequency [Hz]
3.09 532.63 523.25 517.00 524.55 t [s] FFT Goertzel DFT NDFT
3.33 532.63 523.25 517.00 529.73 0.00 1572.53 1046.50 1572.53 1044.06
0.51 1572.53 1046.50 1572.53 1567.98
Violin C5 Estimated frequency [Hz] 1.02 1572.53 1567.98 1572.53 1039.16
t [s] FFT Goertzel DFT NDFT 1.52 1572.53 1567.98 1572.53 1049.21
0.00 517.00 523.25 517.00 533.62 2.03 1572.53 1046.50 1572.53 1049.21
0.21 517.00 523.25 517.00 516.87 2.54 1572.53 1567.98 1033.99 1046.50
0.42 517.00 523.25 517.00 528.44 3.05 1572.53 1567.98 1572.53 1564.32
0.63 517.00 523.25 532.63 525.84 3.56 1572.53 1046.50 1572.53 1041.61
0.84 517.00 523.25 517.00 527.14 4.06 1572.53 1567.98 1572.53 1041.61
1.06 517.00 523.25 517.00 528.44 4.57 1055.53 1046.50 1572.53 1049.21
1.27 517.00 523.25 517.00 533.62 5.08 1572.53 1046.50 1572.53 1046.50
1.48 517.00 523.25 532.63 516.87 5.59 1055.53 1046.50 1055.53 1049.21
1.69 517.00 523.25 532.63 513.04 6.10 1572.53 1046.50 1572.53 1046.50
1.90 517.00 523.25 517.00 527.14 6.60 1572.53 1567.98 1572.53 1041.61
2.11 517.00 523.25 517.00 520.70 7.11 1572.53 1046.50 1572.53 1039.16
2.32 517.00 523.25 517.00 513.04 7.62 1055.53 1046.50 1572.53 1041.61
2.53 517.00 523.25 532.63 525.84 8.13 1572.53 1046.50 1055.53 1046.50
2.74 517.00 523.25 532.63 527.14 8.64 1572.53 1046.50 1572.53 1046.50

108
Table 28: Estimated frequencies for instrumental inputs of 261.63Hz
Flute C4 Estimated frequency [Hz] Piano C4 Estimated frequency [Hz]
t [s] FFT Goertzel DFT NDFT t [s] FFT Goertzel DFT NDFT
0.00 527.77 523.25 517.00 517.51 0.00 258.50 261.63 258.50 261.63
0.24 527.77 523.25 527.77 521.97 0.30 258.50 261.63 267.12 256.94
0.47 517.00 523.25 527.77 527.22 0.60 258.50 277.18 258.50 256.31
0.71 527.77 523.25 527.77 523.91 0.90 258.50 261.63 256.74 258.19
0.94 527.77 523.25 527.77 526.56 1.20 258.50 277.18 267.12 258.19
1.18 517.00 523.25 527.77 521.97 1.50 258.50 261.63 258.50 256.31
1.41 517.00 523.25 517.00 526.56 1.80 258.50 277.18 258.50 256.31
1.65 527.77 523.25 527.77 525.90 2.10 258.50 261.63 256.74 262.64
1.88 527.77 523.25 517.00 525.90 2.40 258.50 261.63 258.50 262.64
2.12 527.77 523.25 527.77 520.70 2.70 258.50 261.63 258.50 264.67
2.35 517.00 523.25 527.77 518.14
2.59 527.77 523.25 527.77 520.70
2.82 527.77 523.25 517.00 525.90 Trumpet C4 Estimated frequency [Hz]
3.06 517.00 523.25 527.77 521.97 t [s] FFT Goertzel DFT NDFT
3.29 527.77 523.25 527.77 517.51 0.00 1055.53 1046.50 1044.76 1042.75
0.46 1572.53 1046.50 1572.53 1046.50
Violin C4 Estimated frequency [Hz] 0.92 1572.53 1567.98 1044.76 1574.06
t [s] FFT Goertzel DFT NDFT 1.38 1044.76 1108.73 1044.76 1578.12
0.00 258.50 261.63 258.50 262.98 1.84 1044.76 1046.50 1572.53 1045.25
0.27 258.50 261.63 267.12 256.94 2.30 1572.53 1046.50 1044.76 1046.50
0.54 258.50 261.63 256.74 261.00 2.75 1044.76 1046.50 1572.53 1574.06
0.81 258.50 261.63 258.50 262.30 3.21 1044.76 1567.98 1044.76 1046.50
1.07 258.50 261.63 258.50 256.31 3.67 1044.76 1567.98 1044.76 1046.50
1.34 258.50 261.63 256.74 264.67 4.13 1044.76 1046.50 1044.76 1045.25
1.61 258.50 261.63 258.50 262.30 4.59 1572.53 1046.50 1044.76 1047.86
1.88 258.50 261.63 267.12 261.31 5.05 1044.76 1567.98 1044.76 1046.50
2.15 258.50 261.63 258.50 260.38 5.51 1044.76 1046.50 1044.76 1047.86
2.42 258.50 261.63 267.12 264.67 5.97 1044.76 1046.50 1572.53 1045.25
2.69 258.50 277.18 258.50 263.32 6.43 1044.76 1567.98 1044.76 1042.75
2.95 267.12 277.18 256.74 256.31 6.89 1044.76 1046.50 1044.76 1046.50
3.22 258.50 261.63 258.50 261.00 7.34 1044.76 1046.50 1044.76 1046.50
3.49 258.50 261.63 256.74 262.30 7.80 1044.76 1046.50 1044.76 1045.25

109
Appendix D: MatLab Script and C Source Code for the DFT
Table 29: MatLab script demonstrating the DFT with leakage effect
function dft_sinusoid_leakage(f_signal, f_sample, window_width)

%%%%%%%%%%%%%%%%%%%%%% amplitude over time %%%%%%%%%%%%%%%%%%%%


t_max = window_width / f_signal; % to obtain the period
t = 0 : t_max / f_sample : t_max; % t = {0;T}, delta t = 1/f_sample for f_signal = 1 Hz
y = sin(2 * pi * f_signal * t);

%%%%%%%%%%%%%%%%%%%%%% amplitude over samples %%%%%%%%%%%%%%%%%


Omega = 2 * pi * (f_signal / f_sample); % normed frequency
N = window_width * (f_sample / f_signal)% Omega * n = w * t => n = t * f_sample
n = 0 : (N - 1); % if window_width is not an integer, there is leakage
x = sin(Omega* n); % the sampled signal

%%%%%%%%%%%%%%%%%%%%%% magnitude over samples %%%%%%%%%%%%%%%%%


X = dft(x); % the signal's spectrum
Re = real(X);
Im = imag(X);
mag = abs(X); % the magnitude

%%%%%%%%%%%%%%%%%%%%%% magnitude over frequency %%%%%%%%%%%%%%%


[max_mag,max_index] = max(mag(1 : N / 2)); % find the maximum peak in the spectrum
f_max = (f_sample / N) * max_index % evaluating the frequency range
f = (f_sample / N) * n;

figure('Name','DFT - a single sinusoid and its spectrum','NumberTitle','off');

left = 0.085;
height = 0.40;
width = 0.40;
bottom = 0.085;
bottom_factor = 2.2;

% the signal's plot for a better overview


subplot('Position',[left (bottom_factor * bottom + height) width height]); plot(t,y);
grid on;
xlabel('\bf t in s \rightarrow'); ylabel('\bf x(t) in V \rightarrow');
axis([min(t) max(t) min(y) max(y)]);

% the plot of sampled signal's evaluated spectrum


subplot('Position',[(left + width + left) (bottom_factor * bottom + height) width
height]); semilogy(f,mag); grid on;
xlabel('\bf f in Hz \rightarrow'); ylabel('\bf |Mag| in dB \rightarrow');
axis([0 f_sample/2 min(mag) max(mag)]);

% the plot of sampled signal's real part of the evaluated spectrum


subplot('Position',[left bottom width height]); plot(f,Re); grid on;
xlabel('\bf f in Hz \rightarrow'); ylabel('\bf Im\{X(f)\} in dB \rightarrow');
axis([0 f_sample/2 min(Re) max(Re)]);

% the plot of sampled signal's imaginary part of the evaluated spectrum


subplot('Position',[(left + width + left) bottom width height]); plot(f,Im); grid on;
xlabel('\bf f in Hz \rightarrow'); ylabel('\bf Im\{X(f)\} in dB \rightarrow');
axis([0 f_sample/2 min(Im) max(Im)]);

function X = dft(x)

N = length(x); % get the number of samples


X = zeros(1,N); % define the spectrum's length = length of sampled signal
K = 2 * pi / N; % calculate this constant once only

for k = 1:N
for n = 1:N
X(k) = X(k) + x(n) * exp(-j * K * k * n);
end
end

110
Table 30: Implentation of the DFT for the DSP in C

float DFT_mono_GetFrequency(Int16 *x, int length, float f_sample)


{
float K = divsp(TWO_TIMES_PI,length);

int k = 0;
int n = 0;

float X_Real = 0.0;//you do not need a buffer for X_Real,


float X_Imaginary = 0.0;//X_Imaginary, X_Mag, because you can
float X_Mag = 0.0;//calculate the frequency on the fly

float maximum_magnitude = 0;
int maximum_magnitude_frequency_index = 0;

for (k = 0; k < length; k++)


{
for (n = 0; n < length; n++)
{//mono, one channel only using
X_Real += x[2 * n] * (float) cossp(K*k*n);
X_Imaginary -= x[2 * n] * (float) sinsp(K*k*n);
//optimised triangular functions
}

X_Mag = (float) sqrtsp(powsp(X_Real,2) + powsp(X_Imaginary,2));

if (maximum_magnitude < X_Mag && k < length/2)


{
maximum_magnitude = X_Mag;
maximum_magnitude_frequency_index = k;
}

X_Real = 0.0;//reset to zero, because of +=


X_Imaginary = 0.0;//reset to zero, because of -=
}

return f_sample * maximum_magnitude_frequency_index / length;


}

111
Appendix E: MatLab Script and C Source Code for the FFTW
and the FFT

Table 31: MatLab script analysing wave files using the FFT
% Marc Bartels 2004; marc.bart@web.de; crami@web.de
function fft_wave_file_save_for_c(input_file_name,output_file_name)
% input_file_name = to be analysed wave file (name.wav)
% output_file_name = any name (e.g. name.txt or name.dat)

clc % clear the screen

[x, f_sample, nbits] = wavread(input_file_name); % x equals the signal

clear nbits; % not needed at the moment

%------- normal ----------------

file_id = fopen(output_file_name,'w');

fprintf(file_id,'%f ',x);

fclose(file_id);

N = length(x) % number of samples

n = 0 : (N-1); % t = {0;T}, delta t = 1/f_sample for f_signal = 1 Hz

t = n / f_sample; % denorming, to find out the signals length in time

X = fft(x); % the signal's spectrum via a DFT

Re = real(X);
Im = imag(X);

mag = abs(X); % the magnitude

%%%%%%%%%%%%%%%%%%%%%% magnitude over frequency %%%%%%%%%%%%%%%

[max_mag,max_index] = max(mag(1 : N / 2)); % find the maximum peak in the spectrum

f_max = (f_sample / N) * max_index % evaluating the frequency range

f = (f_sample / N) * n;

figure('Name','FFT - spectral analysis of wave files - original time


signal','NumberTitle','off');

% the signal's plot for a better overview


plot(t,x); grid on;
xlabel('\bf t in s \rightarrow'); ylabel('\bf x(t) in V \rightarrow');
axis([min(t) max(t) min(x) max(x)]);

figure('Name','FFT - spectral analysis of wave files - evaluated


spectrum','NumberTitle','off');

% the plot of sampled signal's evaluated spectrum


semilogy(f,mag); grid on;
xlabel('\bf f in Hz \rightarrow'); ylabel('\bf |Mag| in dB \rightarrow');
axis([0 f_sample/2 min(mag) max(mag)]);

112
Table 32: Implementation of an 8192-point FFTW in C
#include <stdio.h>
#include <fftw3.h>
#include <math.h>

#define N 8192

#include "data.h" //includes fftw_complex input[N];

fftw_complex output[N];
float X_Mag[N];

void main()
{
fftw_plan p;

int size_of_memory = sizeof(fftw_complex) * N;

fftw_complex *in = fftw_malloc(size_of_memory);


fftw_complex *out = fftw_malloc(size_of_memory);

char *filename = NULL;


FILE *fid = NULL;

int i = 0;
int j = 0;

float f_sample = 44100; //Hz


float maximum_magnitude = 0;
float maximum_frequency = 0;
int maximum_magnitude_frequency_index = 0;

in = input;
out = output;

p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

fftw_execute(p);

fftw_destroy_plan(p);
fftw_free(in);
fftw_free(out);

printf("\nHaving applied the FFTW with %d sampling points.\n",N);

fid = fopen("magnitude.txt","w");

for (i = 0; i < N; i++)


{
X_Mag[i] = (float) sqrt(pow(out[0][0],2) + pow(out[0][1],2));

if (maximum_magnitude < X_Mag[i] && i < N/2)


{
maximum_magnitude = X_Mag[i];
maximum_magnitude_frequency_index = i;
}

fprintf(fid,"%f ",X_Mag[i]);
out++;
}

maximum_frequency = f_sample * maximum_magnitude_frequency_index / N;

printf("\nThe maximum frequency is %f\n\n\n",maximum_frequency);

fclose(fid);
}

113
Table 33: Generation of 8192 complex data elements for the FFTW in C
#include <stdio.h>
#include <math.h>

#define N 8192

float x[N];

void main()
{

//////// declare and define /////////


float f_signal = 0.0;

int i = 0;
char *filename = "input_sinusoid_1kHz.txt";
FILE *file = fopen(filename,"r");

//////// read data from file /////////

printf("read data\n");

for (i = 0; i < N; i++)


{
fscanf(file,"%f ",&x[i]);
}

fclose(file);

filename = "data.h";
file = fopen(filename,"w");

//////// read data from file /////////

fprintf(file,"fftw_complex input[N] = {\\\n");

for (i = 0; i < N; i++)


{
fprintf(file,"%f,0,",x[i]);
fprintf(file,"\\\n");
}

fprintf(file,"};");//don't forget to delete the last character!!!

fclose(file);
}

114
Table 34: Generation of complex interleaved data for the FFT in C
void createComplexTimeSignal(Int16 *StereoBuffer, float *x_complex, int channel_length)
{
Int16 i = 0;

for(i = 0; i < channel_length; i++)


{
x_complex[2 * i] = (float) StereoBuffer[2 * i];//the left channel caries
the mono signal
x_complex[2 * i + 1] = 0.0;// the right channel is the imaginary part
}
}

Table 35: Calculating magnitude and maximum spectral power in C


float Mag_GetFrequency(float *x, int length, float f_sample)
{

int k = 0;

float X_Mag = 0.0;//calculate the frequency on the fly

float maximum_magnitude = 0;
int maximum_magnitude_frequency_index = 0;

for (k = 0; k < length/2; k++)


{
X_Mag = sqrtsp(powsp(x[2 * k],2) + powsp(x[2 * k + 1],2));

if (maximum_magnitude < X_Mag && k < length/4)


{
maximum_magnitude = X_Mag;
maximum_magnitude_frequency_index = k;
}
}

return f_sample * maximum_magnitude_frequency_index / length; //in this order,


otherwise data loss;
}

Table 36: Generation of twiddle factors for in C (TI FFT support files)
/* ======================================================================== */
/* TEXAS INSTRUMENTS, INC. */
/* */
/* NAME */
/* tw_r2fft */
/* */
/* USAGE */
/* This is a stand-alone program intended to generate twiddle-factor */
/* arrays for the DSPF_sp_cfftr2_dit FFT library routine. It is called*/
/* as follows: */
/* */
/* tw_r2fft N > outputfile.c */
/* */
/* The argument 'N' specifies the size of the FFT. This value */
/* must be a power of 2. */
/* */
/* This program will generate the twiddle factor array 'w', */
/* bit-reverse and output the result to the display. Redirect the */
/* output to a file as shown above. */
/* */
/* DESCRIPTION */
/* This program contains the twiddle-factor generation routine */
/* that is described within the source code for the DSPLIB */
/* FFT function DSPF_sp_cfftr2_dit. It does not produce appropriate */
/* twiddle-factor arrays for the other FFT implementations. */
/* */
/* Please consult the specific FFT that you are using for details. */
/* */
/* The final twiddle-factor array generated by the routine will */
/* be 2 * N elements long. */
/* */
/* NOTES */
/* The code below may be adapted to run directly on the target, */
/* rather than running as a separate program running off-line. */
/* Such adaptation is not recommended for time-critical applications. */
/* To adapt this program, remove the 'usage' and 'main' functions, */
/* and call 'gen_twiddle' directly. */
/* */

115
/* ------------------------------------------------------------------------ */
/* Copyright (c) 2003 Texas Instruments, Incorporated. */
/* All Rights Reserved. */
/* ======================================================================== */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#ifndef PI
# ifdef M_PI
# define PI M_PI
# else
# define PI 3.14159265358979323846
# endif
#endif

/* ======================================================================== */
/* */
/* TEXAS INSTRUMENTS, INC. */
/* */
/* NAME */
/* bit_rev */
/* */
/* USAGE */
/* This function has the prototype: */
/* */
/* void bit_rev(float *x, int n); */
/* */
/* x : Array to be bit-reversed. */
/* n : Number of complex array elements to bit-reverse. */
/* */
/* DESCRIPTION */
/* This routine bit reverses the floating point array x which */
/* is considered to be an array of complex numbers with the even */
/* numbered elements being thr real parts of the complex numbers */
/* while the odd numbered elements being the imaginary parts of the */
/* complex numbers. This function is made use of in sp_icfftr2_dif */
/* to bit-reverse the twiddle factor array generated using */
/* tw_genr2fft.c. */
/* ======================================================================== */

void bit_rev(float* x, int n)


{
int i, j, k;
float rtemp, itemp;

j = 0;
for(i=1; i < (n-1); i++)
{
k = n >> 1;
while(k <= j)
{
j -= k;
k >>= 1;
}
j += k;
if(i < j)
{
rtemp = x[j*2];
x[j*2] = x[i*2];
x[i*2] = rtemp;
itemp = x[j*2+1];
x[j*2+1] = x[i*2+1];
x[i*2+1] = itemp;
}
}
}

/* ======================================================================== */
/* GEN_TWIDDLE -- Generate twiddle factors for TI's custom FFTs. */
/* */
/* USAGE */
/* This routine is called as follows: */
/* */
/* int tw_r2fft (float *w, int n) */
/* */
/* float *w Pointer to twiddle-factor array */
/* int n Size of FFT */
/* */

116
/* The routine will generate the twiddle-factors directly into the */
/* array you specify. The array needs to be N elements long. */
/* ======================================================================== */

int gen_twiddle(float *w, int n)


{
double delta = 2 * PI / n;
int i;
for(i = 0; i < n/2; i++)
{
w[2 * i + 1] = sin(i * delta);
w[2 * i] = cos(i * delta);
}

return n;
}

/* ======================================================================== */
/* USAGE -- Print usage information and optionally an error message. */
/* ======================================================================== */
void usage(char *error)
{
fprintf(stderr,
" \n"
"USAGE \n"
" This is a stand-alone program intended to generate twiddle-factor \n"
" arrays for the DSP_radix2 library routine. It is called as follows:\n"
" \n"
" tw_r2fft N > outputfile.c \n"
" \n"
" The argument 'N' specifies the size of the FFT. This value \n"
" must be a power of 2. \n"
" \n"
" This program will generate the twiddle factor array 'w' and \n"
" output the result to the display. Redirect the output to \n"
" a file as shown above. \n"
" \n");

if (error)
fprintf(stderr, "ERROR: %s\n", error);

exit(1);
}

/* ======================================================================== */
/* MAIN -- Where the action happens. */
/* ======================================================================== */
int main(int argc, char *argv[])
{
int i, n = -1, size, is_pow_2;
float *w;
char *s;
char buf[80];

/* -------------------------------------------------------------------- */
/* Parse the arguments. */
/* -------------------------------------------------------------------- */
if (argc < 2) { usage(NULL); }

while (argc-->1)
{
if (!isdigit(argv[1][0]) || sscanf(argv[1], "%d", &n) != 1)
{
sprintf(buf, "Unrecognized argument: %-.32s\n",
argv[1][0]);
usage(buf);
}

if (n < 8 || n > 16384)


usage("FFT size must be between 8 and 16384 points.");

for (i = 2; i < 24; i++)


if ((1 << i) == n) break;

is_pow_2 = !(i & 1);

if (i >= 24)
{
usage("FFT size must be a power of 2\n");
exit(1);

117
}
}

if (n == -1)
usage("Must specify FFT size.");

/* -------------------------------------------------------------------- */
/* Allocate memory for the FFT twiddle factors. */
/* -------------------------------------------------------------------- */
w = calloc(2 * sizeof(float), n);
if (!w)
{
fprintf(stderr, "ERROR: Unable to allocate memory for "
"twiddle factors\n");
exit(1);
}

/* -------------------------------------------------------------------- */
/* Generate the twiddle-factor array. */
/* -------------------------------------------------------------------- */
size = gen_twiddle(w, n);
bit_rev(w, n>>1);

/* -------------------------------------------------------------------- */
/* Print out the resulting twiddle factors. */
/* -------------------------------------------------------------------- */

printf(
"/* -------------------------------------------------------------------- */\n"
"/* Automatically generated twiddle-factor array. */\n"
"/* Number of points: %-5d */\n"
"/* Appropriate FFTs: DSPF_sp_cfftr2_dit, DSPF_sp_icfftr2_dif */\n"
"/* Required alignment: 8 byte (word) */\n"
"/* -------------------------------------------------------------------- */\n"
"/* NOTE: It is suggested that this array be aligned in a different */\n"
"/* starting bank than the actual FFT data, to reduce bank conflicts. */\n"
"/* This can be achieved by using the DATA_MEM_BANK pragma. Please */\n"
"/* see the TMS320C6000 Optimizing C Compiler Reference (SPRU187E) */\n"
"/* for details on \"#pragma DATA_MEM_BANK\". */\n"
"/* -------------------------------------------------------------------- */\n"
"\n"
"#pragma DATA_ALIGN(w, 8); /* Remove this if using DATA_MEM_BANK */\n"
"\n", n);

printf("const float w[2 * %d] =\n{", size / 2);


for (i = 0; i < size; i++)
{
printf("%s%c%f",
i == 0 ? "\n " : (i & 7) == 0 ? ",\n " : ", ",
w[i] < 0 ? '-' : ' ', fabs(w[i]));
}
printf("\n};\n");

return 0;
}

118
Table 37: Bit reversal in C (TI FFT support files)
/* ======================================================================== */
/* */
/* TEXAS INSTRUMENTS, INC. */
/* */
/* NAME */
/* bit_rev */
/* */
/* USAGE */
/* This function has the prototype: */
/* */
/* void bit_rev(float *x, int n); */
/* */
/* x : Array to be bit-reversed. */
/* n : Number of complex array elements to bit-reverse. */
/* */
/* DESCRIPTION */
/* This routine bit reverses the floating point array x which */
/* is considered to be an array of complex numbers with the even */
/* numbered elements being thr real parts of the complex numbers */
/* while the odd numbered elements being the imaginary parts of the */
/* complex numbers. This function is made use of in sp_icfftr2_dif */
/* to bit-reverse the twiddle factor array generated using */
/* tw_genr2fft.c. */
/* ======================================================================== */

void bit_rev(float* x, int n)


{
int i, j, k;
float rtemp, itemp;

j = 0;
for(i=1; i < (n-1); i++)
{
k = n >> 1;
while(k <= j)
{
j -= k;
k >>= 1;
}
j += k;
if(i < j)
{
rtemp = x[j*2];
x[j*2] = x[i*2];
x[i*2] = rtemp;
itemp = x[j*2+1];
x[j*2+1] = x[i*2+1];
x[i*2+1] = itemp;
}
}
}

119
Appendix F: C Source Code for the Goertzel Algorithm

Table 38: Implementation of the Goertzel IIR filter for the DSP in C
float goertzel_one_channel_lookup(Int16 *x, int length, float b1_real, float b1_imag,
float a1)
{
float q[] = {0.0,0.0,0.0}; //initial settings of the delays

/*coefficients:
B = [b0,b1] = [1,-exp(-j*omega_k)] = [1,-cos(omega_k) + j*sin(omega_k)] =
[b0,b1_real + j*b1_imag];
A = [a1,a2] = [2*cos(omega_k),-1]
*/

float y_real = 0;
float x_imag = 0;

int n = 0;

///////////////////////////////////////

for (n = 0; n < length; n++)


{
q[0] = a1 * q[1] - q[2] + x[2 * n];//!!! mono: one channel (left) only
q[2] = q[1];
q[1] = q[0];
}

y_real = q[0] - b1_real * q[1];


y_imag = b1_imag * q[1];

///////////////////////////////////////

return sqrtsp(powsp(y_real,2) + powsp(x_imag,2));


}

Table 39: Goertzel filter bench, peak detection and evaluation in C


float goertzel_GetFrequency(Int16 *xBuffer, int x_length)
{
int i = 0;
float goertzel_value = 0.0;
float max = 0.0;
float f_signal_temp = 0.0;

float b1_real = 0.0;


float b1_imag = 0.0;
float a1 = 0.0;

for (i = 0; i < iMaxNotes; i++)


{ //for computational reasons, the "minus" can be found in the equation
b1_real = (float) goertzel_coeff[i][0];
b1_imag = (float) goertzel_coeff[i][1];
a1 = (float) goertzel_coeff[i][2];

goertzel_value = goertzel_one_channel_lookup(xBuffer,x_length,b1_real,b1_imag,a1);
if (max < goertzel_value)
{
max = goertzel_value;
f_signal_temp = (float) keyboard_notes[i];
}
}
return f_signal_temp;
}

120
Table 40: Pre-calculated Goertzel filter coefficients
double goertzel_coeff[MAX_MIDI_NOTES][MAX_NO_OF_COEFF] = {\
0.999992,0.003917,1.999985,\ 0.998763,0.049717,1.997527,\
0.999991,0.004149,1.999983,\ 0.998612,0.052671,1.997224,\
0.999990,0.004396,1.999981,\ 0.998442,0.055799,1.996884,\
0.999989,0.004658,1.999978,\ 0.998251,0.059114,1.996503,\
0.999988,0.004935,1.999976,\ 0.998037,0.062624,1.996074,\
0.999986,0.005228,1.999973,\ 0.997797,0.066343,1.995594,\
0.999985,0.005539,1.999969,\ 0.997527,0.070281,1.995054,\
0.999983,0.005868,1.999966,\ 0.997225,0.074453,1.994449,\
0.999981,0.006217,1.999961,\ 0.996885,0.078871,1.993770,\
0.999978,0.006587,1.999957,\ 0.996504,0.083551,1.993007,\
0.999976,0.006978,1.999951,\ 0.996076,0.088506,1.992151,\
0.999973,0.007393,1.999945,\ 0.995595,0.093754,1.991191,\
0.999969,0.007833,1.999939,\ 0.995056,0.099311,1.990113,\
0.999966,0.008299,1.999931,\ 0.994452,0.105195,1.988903,\
0.999961,0.008792,1.999923,\ 0.993773,0.111425,1.987546,\
0.999957,0.009315,1.999913,\ 0.993011,0.118020,1.986022,\
0.999951,0.009869,1.999903,\ 0.992156,0.125003,1.984313,\
0.999945,0.010456,1.999891,\ 0.991197,0.132393,1.982395,\
0.999939,0.011078,1.999877,\ 0.990121,0.140215,1.980242,\
0.999931,0.011736,1.999862,\ 0.988914,0.148493,1.977827,\
0.999923,0.012434,1.999845,\ 0.987559,0.157251,1.975117,\
0.999913,0.013173,1.999826,\ 0.986039,0.166517,1.972077,\
0.999903,0.013957,1.999805,\ 0.984333,0.176317,1.968667,\
0.999891,0.014786,1.999781,\ 0.982420,0.186682,1.964841,\
0.999877,0.015666,1.999755,\ 0.980275,0.197640,1.960549,\
0.999862,0.016597,1.999725,\ 0.977868,0.209223,1.955736,\
0.999845,0.017584,1.999691,\ 0.975169,0.221462,1.950338,\
0.999826,0.018629,1.999653,\ 0.972142,0.234391,1.944285,\
0.999805,0.019737,1.999610,\ 0.968749,0.248044,1.937497,\
0.999781,0.020910,1.999563,\ 0.964944,0.262455,1.929888,\
0.999755,0.022154,1.999509,\ 0.960679,0.277660,1.921359,\
0.999725,0.023471,1.999449,\ 0.955900,0.293693,1.911800,\
0.999691,0.024866,1.999382,\ 0.950544,0.310589,1.901088,\
0.999653,0.026344,1.999306,\ 0.944544,0.328384,1.889089,\
0.999610,0.027911,1.999221,\ 0.937824,0.347110,1.875649,\
0.999563,0.029570,1.999125,\ 0.930300,0.366800,1.860600,\
0.999509,0.031327,1.999018,\ 0.921877,0.387483,1.843754,\
0.999449,0.033190,1.998898,\ 0.912452,0.409184,1.824904,\
0.999382,0.035162,1.998763,\ 0.901909,0.431926,1.803818,\
0.999306,0.037252,1.998612,\ 0.890121,0.455723,1.780243,\
0.999221,0.039466,1.998442,\ 0.876948,0.480585,1.753896,\
0.999125,0.041812,1.998251,\ 0.862234,0.506510,1.724469,\
0.999018,0.044297,1.998037,\ 0.845810,0.533484,1.691620,\
0.998898,0.046929,1.997797,\ 0.827489,0.561482,1.654978
};

Table 41: Keyboard frequencies (keyboard_notes.h)


double keyboard_notes[] = {
27.500000,29.135235,30.867706,32.703196,34.647829,36.708096,38.890873,41.203445,
43.653529,46.249303,48.999429,51.913087,55.000000,58.270470,61.735413,65.406391,
69.295658,73.416192,77.781746,82.406889,87.307058,92.498606,97.998859,103.826174,
110.000000,116.540940,123.470825,130.812783,138.591315,146.832384,155.563492,164.813778,
174.614116,184.997211,195.997718,207.652349,220.000000,233.081881,246.941651,261.625565,
277.182631,293.664768,311.126984,329.627557,349.228231,369.994423,391.995436,415.304698,
440.000000,466.163762,493.883301,523.251131,554.365262,587.329536,622.253967,659.255114,
698.456463,739.988845,783.990872,830.609395,880.000000,932.327523,987.766603,1046.502261,
1108.730524,1174.659072,1244.507935,1318.510228,1396.912926,1479.977691,1567.981744,1661.218790,
1760.000000,1864.655046,1975.533205,2093.004522,2217.461048,2349.318143,2489.015870,2637.020455,
2793.825851,2959.955382,3135.963488,3322.437581,3520.000000,3729.310092,3951.066410,4186.009045
};

int iMaxNotes = sizeof(keyboard_notes) / sizeof(double);

121
Table 42: Generation of Goertzel filter coefficients in C
#include <stdio.h>
#include <math.h>

#include "keyboard_notes.h"

#define MAX_MIDI_NOTES 88
#define MAX_NO_OF_COEFF 3

#define TWO_TIMES_PI 6.283185 //float (single) precision


#define SAMPLE_FREQUENCY 44100.0

float goertzel_LUT[MAX_MIDI_NOTES][MAX_NO_OF_COEFF];

void main(void)
{
int i = 0;
int j = 0;

float omega = 0.0;


float frequency = 0.0;

FILE *fid = fopen("goertzel_coeff.h","w");

///////// create coefficients /////////

for (i = 0; i < MAX_MIDI_NOTES; i++)


{
frequency = (float) keyboard_notes[i];// wobbling through the frequency space
omega = (float) TWO_TIMES_PI * frequency / SAMPLE_FREQUENCY; //normed frequency

goertzel_LUT[i][0] = (float) cos(omega); //b1_real


goertzel_LUT[i][1] = (float) sin(omega); //b1_imag
goertzel_LUT[i][2] = 2 * (float) goertzel_LUT[i][0]; //a1
}

///////// print coefficients /////////

printf("Midi_No\tFrequency\tb1_re\t\tb1_im\t\ta1\n");

for (i = 0; i < MAX_MIDI_NOTES; i++)


{
frequency = (float) keyboard_notes[i];// wobbling through the frequency space

printf("%d\t%f\t",i + 21,frequency);

for (j = 0; j < MAX_NO_OF_COEFF; j++)


{
printf("%f\t",goertzel_LUT[i][j]);
}
printf("\n");
}

///////// save coefficients /////////

fprintf(fid,"float goertzel_coeff[][] = {\\\n");

for (i = 0; i < MAX_MIDI_NOTES; i++)


{
for (j = 0; j < MAX_NO_OF_COEFF; j++)
{
fprintf(fid,"%f,",goertzel_LUT[i][j]);
}
fprintf(fid,"\\\n");
}

fprintf(fid,"};\n"); //!!! don't forget to delete the last two characters!!!

fclose(fid);

///////// that's it /////////

printf("\n\n\n\n... file has been written ...\n\n\n");


}

122
Appendix E: C Source Code for the NDFT
Table 43: Implementation of the NDFT in C
float NDFT_mono_GetFrequency(Int16 *x, int length, float f_sample)
{
float K = divsp(TWO_TIMES_PI,f_sample);
//for computational reasons, K could be calculated outside

int k = 0;
int n = 0;

float X_Real = 0.0;//you do not need a buffer for X_Real,


float X_Imaginary = 0.0;//X_Imaginary, X_Mag, because you can
float X_Mag = 0.0;//calculate the frequency on the fly

float maximum_magnitude = 0;
int maximum_magnitude_frequency_index = 0;

for (k = 0; k < length; k++)


{
for (n = 0; n < length; n++)
{//mono, one channel only using
X_Real += x[2 * n] * (float) cossp(K*frequency_space[k]*n);
X_Imaginary -= x[2 * n] * (float) sinsp(K*frequency_space[k]*n);
//optimized triangular functions
}

X_Mag = (float) sqrtsp(powsp(X_Real,2) + powsp(X_Imaginary,2));

if (maximum_magnitude < X_Mag)


//!!! the whole length of arbitrary frequency space !!!
{
maximum_magnitude = X_Mag;
maximum_magnitude_frequency_index = k;
}

X_Real = 0.0;//reset to zero, because of +=


X_Imaginary = 0.0;//reset to zero, because of -=
}

return frequency_space[maximum_magnitude_frequency_index];
}

123
Table 44: Generation of the arbitrarily chosen frequency vector in C
#include <stdio.h>
#include <math.h>

#define N 1024
#define MAX_MIDI 88
#define filename "NDFT_N_1024_keyboard.h"
//don't forget to change this, too, otherwise it will be overwritten

float X[N];
float frequency(int midi);

void main(void)
{
FILE *fid = NULL;

int j = 0;
int i = 0;
int k = 0;

int end = 0;
int start = 0;
int gap_start_end = 0;

float current_midi = 0.0;


float next_midi = 0.0;
float delta_midi_note = 0.0;
float delta_points = 0;

end = (int) floor(i * N/88);


X[end] = frequency(21); // the beginning is an exception

for (i = 0; i < MAX_MIDI; i++)


{
start = (int) ceil(i * N/88);
end = (int) floor((i + 1) * N/88);
gap_start_end = end - start;

current_midi = frequency(i + 21);


next_midi = frequency(i + 22);
delta_midi_note = next_midi - current_midi;
delta_points = delta_midi_note / gap_start_end;

for (k = 0; k < gap_start_end; k++)


{
X[k + start] = current_midi + k * delta_points;
}

printf("%d\t%d\t%d\t%d\n",i,start,end,gap_start_end);
}

X[N-1] = frequency(108); //the end is an exception, too

fid = fopen(filename,"w");

fprintf(fid,"float frequency_space[N/2] = {\\\n");//N/2 for ping pong

for (i = 0;i < (N-1);i++)


{
fprintf(fid,"%f,\\\n",X[i]);
printf("%d\t%f\n",i,X[i]);
}

printf("%d\t%f\n",N-1,X[N-1]);

fprintf(fid,"%f\\\n",X[N-1]);
fprintf(fid,"};\n");

fclose(fid);

printf("\n\n ... have written to file ... \n");


}

///////////////////////////////////////////////////////

float frequency(int midi)


{
return (float) (440 * pow(2,(float)(midi-69)/12));
}

124
Table 45: Arbitrarily chosen frequency vector (problem size N = 1024)
float frequency_space[N/2] = {\
27.500000,\ 97.998856,\ 349.228241,\ 1244.507935,\
27.648657,\ 98.528610,\ 351.116089,\ 1251.235474,\
27.797316,\ 99.058365,\ 353.003906,\ 1257.962891,\
27.945972,\ 99.588127,\ 354.891754,\ 1264.690430,\
28.094631,\ 100.117882,\ 356.779572,\ 1271.417847,\
28.243288,\ 100.647636,\ 358.667419,\ 1278.145386,\
28.391947,\ 101.177391,\ 360.555237,\ 1284.872803,\
28.540604,\ 101.707146,\ 362.443085,\ 1291.600342,\
28.689262,\ 102.236908,\ 364.330933,\ 1298.327759,\
28.837919,\ 102.766663,\ 366.218750,\ 1305.055298,\
28.986578,\ 103.296417,\ 368.106598,\ 1311.782715,\
29.135235,\ 103.826172,\ 369.994415,\ 1318.510254,\
29.279608,\ 104.340660,\ 371.827820,\ 1325.043823,\
29.423981,\ 104.855141,\ 373.661255,\ 1331.577393,\
29.568354,\ 105.369629,\ 375.494659,\ 1338.110962,\
29.712725,\ 105.884117,\ 377.328094,\ 1344.644531,\
29.857098,\ 106.398598,\ 379.161499,\ 1351.177979,\
30.001471,\ 106.913086,\ 380.994934,\ 1357.711548,\
30.145844,\ 107.427574,\ 382.828339,\ 1364.245117,\
30.290216,\ 107.942055,\ 384.661774,\ 1370.778687,\
30.434589,\ 108.456543,\ 386.495178,\ 1377.312256,\
30.578960,\ 108.971031,\ 388.328613,\ 1383.845825,\
30.723333,\ 109.485512,\ 390.162018,\ 1390.379395,\
30.867706,\ 110.000000,\ 391.995422,\ 1396.912964,\
31.034569,\ 110.594627,\ 394.114441,\ 1404.464355,\
31.201431,\ 111.189262,\ 396.233459,\ 1412.015625,\
31.368294,\ 111.783890,\ 398.352509,\ 1419.567017,\
31.535156,\ 112.378525,\ 400.471527,\ 1427.118286,\
31.702019,\ 112.973152,\ 402.590546,\ 1434.669678,\
31.868883,\ 113.567787,\ 404.709564,\ 1442.220947,\
32.035744,\ 114.162415,\ 406.828583,\ 1449.772339,\
32.202606,\ 114.757050,\ 408.947632,\ 1457.323730,\
32.369469,\ 115.351677,\ 411.066650,\ 1464.875000,\
32.536331,\ 115.946312,\ 413.185669,\ 1472.426392,\
32.703197,\ 116.540939,\ 415.304688,\ 1479.977661,\
32.865250,\ 117.118431,\ 417.362640,\ 1487.311279,\
33.027302,\ 117.695923,\ 419.420563,\ 1494.645020,\
33.189354,\ 118.273415,\ 421.478516,\ 1501.978638,\
33.351406,\ 118.850899,\ 423.536469,\ 1509.312378,\
33.513462,\ 119.428391,\ 425.594391,\ 1516.645996,\
33.675514,\ 120.005882,\ 427.652344,\ 1523.979736,\
33.837566,\ 120.583374,\ 429.710297,\ 1531.313354,\
33.999619,\ 121.160866,\ 431.768219,\ 1538.647095,\
34.161671,\ 121.738358,\ 433.826172,\ 1545.980713,\
34.323723,\ 122.315842,\ 435.884125,\ 1553.314453,\
34.485775,\ 122.893333,\ 437.942047,\ 1560.648071,\
34.647827,\ 123.470825,\ 440.000000,\ 1567.981689,\
34.819515,\ 124.082657,\ 442.180328,\ 1575.751465,\
34.991207,\ 124.694489,\ 444.360626,\ 1583.521240,\
35.162895,\ 125.306313,\ 446.540955,\ 1591.291016,\
35.334583,\ 125.918144,\ 448.721252,\ 1599.060669,\
35.506271,\ 126.529976,\ 450.901581,\ 1606.830444,\
35.677963,\ 127.141808,\ 453.081879,\ 1614.600220,\
35.849651,\ 127.753632,\ 455.262207,\ 1622.369995,\
36.021339,\ 128.365463,\ 457.442505,\ 1630.139771,\
36.193027,\ 128.977295,\ 459.622833,\ 1637.909546,\
36.364719,\ 129.589127,\ 461.803131,\ 1645.679321,\
36.536407,\ 130.200958,\ 463.983459,\ 1653.448975,\
36.708096,\ 130.812790,\ 466.163757,\ 1661.218750,\
36.906528,\ 131.519928,\ 468.683716,\ 1670.198853,\
37.104965,\ 132.227066,\ 471.203674,\ 1679.178955,\
37.303398,\ 132.934204,\ 473.723633,\ 1688.159058,\
37.501831,\ 133.641342,\ 476.243591,\ 1697.139160,\
37.700268,\ 134.348480,\ 478.763550,\ 1706.119263,\
37.898701,\ 135.055618,\ 481.283508,\ 1715.099487,\
38.097137,\ 135.762756,\ 483.803467,\ 1724.079590,\
38.295570,\ 136.469894,\ 486.323425,\ 1733.059692,\
38.494003,\ 137.177032,\ 488.843384,\ 1742.039795,\
38.692440,\ 137.884171,\ 491.363342,\ 1751.019897,\
38.890873,\ 138.591309,\ 493.883301,\ 1760.000000,\
39.083588,\ 139.278061,\ 496.330627,\ 1768.721313,\
39.276302,\ 139.964828,\ 498.777954,\ 1777.442505,\
39.469017,\ 140.651581,\ 501.225250,\ 1786.163818,\
39.661732,\ 141.338333,\ 503.672577,\ 1794.885010,\
39.854446,\ 142.025085,\ 506.119904,\ 1803.606323,\
40.047157,\ 142.711853,\ 508.567230,\ 1812.327515,\
125
40.239872,\ 143.398605,\ 511.014526,\ 1821.048828,\
40.432587,\ 144.085358,\ 513.461853,\ 1829.770020,\
40.625301,\ 144.772110,\ 515.909180,\ 1838.491333,\
40.818016,\ 145.458878,\ 518.356506,\ 1847.212524,\
41.010731,\ 146.145630,\ 520.803833,\ 1855.933838,\
41.203445,\ 146.832382,\ 523.251160,\ 1864.655029,\
41.407619,\ 147.559967,\ 525.843994,\ 1873.894897,\
41.611794,\ 148.287567,\ 528.436829,\ 1883.134766,\
41.815968,\ 149.015167,\ 531.029663,\ 1892.374634,\
42.020142,\ 149.742752,\ 533.622498,\ 1901.614380,\
42.224312,\ 150.470337,\ 536.215393,\ 1910.854248,\
42.428486,\ 151.197937,\ 538.808228,\ 1920.094116,\
42.632660,\ 151.925537,\ 541.401062,\ 1929.333984,\
42.836834,\ 152.653122,\ 543.993896,\ 1938.573853,\
43.041008,\ 153.380707,\ 546.586731,\ 1947.813721,\
43.245182,\ 154.108307,\ 549.179565,\ 1957.053467,\
43.449356,\ 154.835907,\ 551.772400,\ 1966.293335,\
43.653530,\ 155.563492,\ 554.365234,\ 1975.533203,\
43.889511,\ 156.404434,\ 557.362000,\ 1986.212402,\
44.125488,\ 157.245361,\ 560.358765,\ 1996.891602,\
44.361469,\ 158.086304,\ 563.355469,\ 2007.570801,\
44.597446,\ 158.927231,\ 566.352234,\ 2018.250000,\
44.833427,\ 159.768173,\ 569.348999,\ 2028.929199,\
45.069405,\ 160.609100,\ 572.345764,\ 2039.608521,\
45.305386,\ 161.450043,\ 575.342529,\ 2050.287598,\
45.541367,\ 162.290970,\ 578.339294,\ 2060.966797,\
45.777344,\ 163.131912,\ 581.335999,\ 2071.645996,\
46.013325,\ 163.972839,\ 584.332764,\ 2082.325195,\
46.249302,\ 164.813782,\ 587.329529,\ 2093.004639,\
46.478477,\ 165.630478,\ 590.239868,\ 2103.375977,\
46.707657,\ 166.447174,\ 593.150269,\ 2113.747314,\
46.936832,\ 167.263870,\ 596.060669,\ 2124.118652,\
47.166012,\ 168.080566,\ 598.971008,\ 2134.489990,\
47.395187,\ 168.897247,\ 601.881348,\ 2144.861572,\
47.624367,\ 169.713943,\ 604.791748,\ 2155.232910,\
47.853542,\ 170.530640,\ 607.702148,\ 2165.604248,\
48.082722,\ 171.347336,\ 610.612488,\ 2175.975586,\
48.311897,\ 172.164032,\ 613.522827,\ 2186.346924,\
48.541077,\ 172.980728,\ 616.433228,\ 2196.718262,\
48.770252,\ 173.797424,\ 619.343628,\ 2207.089600,\
48.999428,\ 174.614120,\ 622.253967,\ 2217.460938,\
49.242233,\ 175.479385,\ 625.337402,\ 2228.448975,\
49.485039,\ 176.344635,\ 628.420837,\ 2239.437256,\
49.727844,\ 177.209900,\ 631.504272,\ 2250.425293,\
49.970646,\ 178.075150,\ 634.587708,\ 2261.413330,\
50.213451,\ 178.940414,\ 637.671143,\ 2272.401367,\
50.456257,\ 179.805664,\ 640.754517,\ 2283.389648,\
50.699062,\ 180.670929,\ 643.837952,\ 2294.377686,\
50.941868,\ 181.536179,\ 646.921387,\ 2305.365723,\
51.184673,\ 182.401443,\ 650.004822,\ 2316.353760,\
51.427479,\ 183.266693,\ 653.088257,\ 2327.342041,\
51.670280,\ 184.131958,\ 656.171692,\ 2338.330078,\
51.913086,\ 184.997208,\ 659.255127,\ 2349.318115,\
52.193714,\ 185.997253,\ 662.818909,\ 2362.017822,\
52.474342,\ 186.997299,\ 666.382629,\ 2374.717773,\
52.754971,\ 187.997345,\ 669.946411,\ 2387.417480,\
53.035599,\ 188.997391,\ 673.510132,\ 2400.117188,\
53.316227,\ 189.997437,\ 677.073914,\ 2412.817139,\
53.596859,\ 190.997482,\ 680.637695,\ 2425.516846,\
53.877487,\ 191.997528,\ 684.201416,\ 2438.216797,\
54.158115,\ 192.997574,\ 687.765198,\ 2450.916504,\
54.438744,\ 193.997620,\ 691.328918,\ 2463.616211,\
54.719372,\ 194.997665,\ 694.892700,\ 2476.316162,\
55.000000,\ 195.997711,\ 698.456482,\ 2489.015869,\
55.272541,\ 196.968933,\ 701.917542,\ 2501.349609,\
55.545078,\ 197.940155,\ 705.378540,\ 2513.683350,\
55.817619,\ 198.911377,\ 708.839600,\ 2526.017090,\
56.090157,\ 199.882584,\ 712.300598,\ 2538.350830,\
56.362698,\ 200.853806,\ 715.761658,\ 2550.684570,\
56.635235,\ 201.825027,\ 719.222656,\ 2563.018066,\
56.907776,\ 202.796249,\ 722.683716,\ 2575.351807,\
57.180313,\ 203.767471,\ 726.144714,\ 2587.685547,\
57.452854,\ 204.738693,\ 729.605774,\ 2600.019287,\
57.725391,\ 205.709915,\ 733.066772,\ 2612.353027,\
57.997932,\ 206.681122,\ 736.527832,\ 2624.686768,\
58.270470,\ 207.652344,\ 739.988831,\ 2637.020508,\
58.585464,\ 208.774857,\ 743.989014,\ 2651.275635,\
58.900459,\ 209.897369,\ 747.989197,\ 2665.530518,\
59.215454,\ 211.019882,\ 751.989380,\ 2679.785645,\
59.530449,\ 212.142395,\ 755.989563,\ 2694.040527,\
59.845444,\ 213.264908,\ 759.989746,\ 2708.295654,\

126
60.160439,\ 214.387436,\ 763.989929,\ 2722.550781,\
60.475433,\ 215.509949,\ 767.990112,\ 2736.805664,\
60.790428,\ 216.632462,\ 771.990295,\ 2751.060791,\
61.105423,\ 217.754974,\ 775.990479,\ 2765.315674,\
61.420418,\ 218.877487,\ 779.990662,\ 2779.570801,\
61.735413,\ 220.000000,\ 783.990845,\ 2793.825928,\
62.041328,\ 221.090164,\ 787.875732,\ 2807.670166,\
62.347244,\ 222.180313,\ 791.760620,\ 2821.514160,\
62.653156,\ 223.270477,\ 795.645508,\ 2835.358398,\
62.959072,\ 224.360626,\ 799.530334,\ 2849.202393,\
63.264988,\ 225.450790,\ 803.415222,\ 2863.046631,\
63.570904,\ 226.540939,\ 807.300110,\ 2876.890625,\
63.876816,\ 227.631104,\ 811.184998,\ 2890.734863,\
64.182732,\ 228.721252,\ 815.069885,\ 2904.578857,\
64.488647,\ 229.811417,\ 818.954773,\ 2918.423096,\
64.794563,\ 230.901566,\ 822.839661,\ 2932.267090,\
65.100479,\ 231.991730,\ 826.724487,\ 2946.111328,\
65.406395,\ 233.081879,\ 830.609375,\ 2959.955322,\
65.730499,\ 234.236862,\ 834.725281,\ 2974.622559,\
66.054604,\ 235.391846,\ 838.841125,\ 2989.290039,\
66.378708,\ 236.546829,\ 842.957031,\ 3003.957275,\
66.702812,\ 237.701797,\ 847.072937,\ 3018.624756,\
67.026924,\ 238.856781,\ 851.188782,\ 3033.291992,\
67.351028,\ 240.011765,\ 855.304688,\ 3047.959473,\
67.675133,\ 241.166748,\ 859.420593,\ 3062.626709,\
67.999237,\ 242.321732,\ 863.536438,\ 3077.294189,\
68.323341,\ 243.476715,\ 867.652344,\ 3091.961426,\
68.647446,\ 244.631683,\ 871.768250,\ 3106.628906,\
68.971550,\ 245.786667,\ 875.884094,\ 3121.296143,\
69.295654,\ 246.941650,\ 880.000000,\ 3135.963379,\
69.670250,\ 248.276550,\ 884.757019,\ 3152.915527,\
70.044846,\ 249.611450,\ 889.514099,\ 3169.867676,\
70.419434,\ 250.946350,\ 894.271118,\ 3186.820068,\
70.794029,\ 252.281250,\ 899.028198,\ 3203.772217,\
71.168625,\ 253.616150,\ 903.785217,\ 3220.724365,\
71.543221,\ 254.951065,\ 908.542297,\ 3237.676514,\
71.917816,\ 256.285950,\ 913.299316,\ 3254.628662,\
72.292412,\ 257.620850,\ 918.056396,\ 3271.581055,\
72.667000,\ 258.955750,\ 922.813416,\ 3288.533203,\
73.041595,\ 260.290649,\ 927.570496,\ 3305.485352,\
73.416191,\ 261.625580,\ 932.327515,\ 3322.437500,\
73.779984,\ 262.921997,\ 936.947449,\ 3338.901123,\
74.143784,\ 264.218414,\ 941.567383,\ 3355.364502,\
74.507584,\ 265.514832,\ 946.187317,\ 3371.828125,\
74.871376,\ 266.811249,\ 950.807190,\ 3388.291748,\
75.235168,\ 268.107697,\ 955.427124,\ 3404.755127,\
75.598969,\ 269.404114,\ 960.047058,\ 3421.218750,\
75.962769,\ 270.700531,\ 964.666992,\ 3437.682373,\
76.326561,\ 271.996948,\ 969.286926,\ 3454.145752,\
76.690353,\ 273.293365,\ 973.906860,\ 3470.609375,\
77.054153,\ 274.589783,\ 978.526733,\ 3487.072998,\
77.417953,\ 275.886200,\ 983.146667,\ 3503.536377,\
77.781746,\ 277.182617,\ 987.766602,\ 3520.000000,\
78.167175,\ 278.556122,\ 992.661255,\ 3537.442627,\
78.552605,\ 279.929657,\ 997.555908,\ 3554.885010,\
78.938034,\ 281.303162,\ 1002.450500,\ 3572.327637,\
79.323463,\ 282.676666,\ 1007.345154,\ 3589.770020,\
79.708893,\ 284.050171,\ 1012.239807,\ 3607.212646,\
80.094315,\ 285.423706,\ 1017.134460,\ 3624.655029,\
80.479744,\ 286.797211,\ 1022.029053,\ 3642.097656,\
80.865173,\ 288.170715,\ 1026.923706,\ 3659.540039,\
81.250603,\ 289.544220,\ 1031.818359,\ 3676.982666,\
81.636032,\ 290.917755,\ 1036.713013,\ 3694.425049,\
82.021461,\ 292.291260,\ 1041.607666,\ 3711.867676,\
82.406891,\ 293.664764,\ 1046.502319,\ 3729.310059,\
82.852364,\ 295.252228,\ 1052.159424,\ 3749.469727,\
83.297829,\ 296.839722,\ 1057.816528,\ 3769.629395,\
83.743301,\ 298.427185,\ 1063.473633,\ 3789.789063,\
84.188766,\ 300.014648,\ 1069.130737,\ 3809.948730,\
84.634239,\ 301.602142,\ 1074.787842,\ 3830.108398,\
85.079712,\ 303.189606,\ 1080.444946,\ 3850.268066,\
85.525177,\ 304.777100,\ 1086.102051,\ 3870.427734,\
85.970650,\ 306.364563,\ 1091.759155,\ 3890.587402,\
86.416115,\ 307.952026,\ 1097.416260,\ 3910.747070,\
86.861588,\ 309.539520,\ 1103.073364,\ 3930.906738,\
87.307060,\ 311.126984,\ 1108.730469,\ 3951.066406,\
87.739693,\ 312.668701,\ 1114.224487,\ 3970.645020,\
88.172318,\ 314.210419,\ 1119.718628,\ 3990.223633,\
88.604950,\ 315.752136,\ 1125.212646,\ 4009.802002,\
89.037575,\ 317.293854,\ 1130.706665,\ 4029.380615,\
89.470207,\ 318.835571,\ 1136.200684,\ 4048.959229,\

127
89.902832,\ 320.377258,\ 1141.694824,\ 4068.537842,\
90.335464,\ 321.918976,\ 1147.188843,\ 4088.116211,\
90.768089,\ 323.460693,\ 1152.682861,\ 4107.694824,\
91.200722,\ 325.002411,\ 1158.176880,\ 4127.273438,\
91.633347,\ 326.544128,\ 1163.671021,\ 4146.852051,\
92.065979,\ 328.085846,\ 1169.165039,\ 4166.430664,\
92.498604,\ 329.627563,\ 1174.659058,\ 4186.009277,\
92.956955,\ 331.260956,\ 1180.479736,\ 4206.751953,\
93.415314,\ 332.894348,\ 1186.300537,\ 4227.494629,\
93.873665,\ 334.527740,\ 1192.121338,\ 4248.237305,\
94.332024,\ 336.161133,\ 1197.942017,\ 4268.979980,\
94.790375,\ 337.794495,\ 1203.762695,\ 4289.723145,\
95.248734,\ 339.427887,\ 1209.583496,\ 4310.465820,\
95.707085,\ 341.061279,\ 1215.404297,\ 4331.208496,\
96.165443,\ 342.694672,\ 1221.224976,\ 4351.951172,\
96.623795,\ 344.328064,\ 1227.045654,\ 4372.693848,\
97.082153,\ 345.961456,\ 1232.866455,\ 4393.436523,\
97.540504,\ 347.594849,\ 1238.687256,\ 4186.009277
};

128
Appendix I: Academic Paper, published at the 8th IEEE ISCE,
September 2004

129
130
131
132
133

You might also like