• No results found

Design and implementation of a guitar tuner for a mobile phone

N/A
N/A
Protected

Academic year: 2021

Share "Design and implementation of a guitar tuner for a mobile phone"

Copied!
28
0
0

Loading.... (view fulltext now)

Full text

(1)2002:215 CIV. MASTER’S THESIS. Design and Implementation of a Guitar Tuner for a Mobile Phone. HENRIK AHLM MATHIAS JEPPSSON. MASTER OF SCIENCE PROGRAMME Department of Computer Science and Electrical Engineering Division of Computer Engineering 2002:215 CIV • ISSN: 1402 - 1617 • ISRN: LTU - EX - - 02/215 - - SE.

(2) Design and implementation of a guitar tuner for a mobile phone.. Henrik Ahlm henahl-6@sm.luth.se. Mathias Jeppsson matjep-6@sm.luth.se. June 5, 2002.

(3) 2(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. Abstract. The intention of this thesis is to investigate the possibility to implement a guitar tuner, using only an ordinary mobile phone as a platform. Samples are read from the microphone already located in the mobile, then processed using available resources and nally the result is presented on the display. Although the outcome of the thesis can be seen as a success, there is room for improvements and alternative solutions..

(4) 3(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. Preface This thesis is part of the Master of science education we began in the spring of 1997, at Luleå University of Technology (LTU). The thesis has been supervised by Per Lindgren, at the computer science and electrical engineering department (EISLAB), and Andreas Göransson, at Sony Ericsson. Little did we know that we would nish our education in the far south of Sweden, more than 1500 km away from our university, but it has been an interesting journey from the beginning to the end. Even though there has been a great many people involved, giving us a helping hand or an encouraging word when needed, there are those that has shouldered more responsibility than they had to. We especially want to show our gratitude towards Andreas Göransson, our tutor at Sony Ericsson, and Daniel Linåker, without whom we would not have enjoyed our time at Sony Ericsson as much as we did. Henrik Ahlm & Mathias Jeppsson Lund, Sweden February 2002.

(5) 4(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. Contents 1. Introduction. 2. Background. 3. Method. 4. Result and discussion. 23. 5. Conclusions. 24. 6. Future work. 25. 1.1 Problem description . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Problem analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3 System description . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1 2.2 2.3 2.4 2.5. Electronic tuners . . . . . . . . . . Musical notes . . . . . . . . . . . . Tones and overtones . . . . . . . . Pulse Code Modulation . . . . . . Floating- vs. xed-point numerics .. 3.1 Environment . . . . . . . . . . . . 3.2 Frequency-tracking loops . . . . . . 3.2.1 Quadricorrelator . . . . . . 3.2.2 Balanced Quadricorrelator . 3.3 Sine wave generation . . . . . . . . 3.4 Simulation . . . . . . . . . . . . . . 3.4.1 Floating-point precision . . 3.4.2 Fixed-point precision . . . . 3.5 Implementation . . . . . . . . . . .. A Glossary. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. 5. 5 5 5. 7. 7 7 8 9 9. 11. 11 11 12 13 14 15 16 18 20. 26.

(6) 5(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 1 Introduction To make an instrument sing in a fashion that brings pleasure to the ear, not only demand a person skilled in playing it, but also someone that knows how to tune it to perfection. Thus, an artist playing an instrument that is not tuned according to the audience, will never be able to really catch the attention of people that are listening, and the guitar is no exception from this rule. However, there is more than one method available when a guitar needs to be tuned. As mentioned, there are many ways to tune a guitar, by ear alone or by using some kind of instrument that will help the musician on the way. The instrument may be something as simple as a tuning-fork, that provide a reference frequency, or as complicated, from the constructions point of view, as an electronic device. Even though the rst method may be preferred by some musicians, the second one has become increasingly popular with the introduction of low cost guitar tuners. Besides, trying to tune a guitar with only experience as a helping hand, is not even an option for everyone, in particular those that recently picked up an interest in playing the guitar.. 1.1 Problem description The goal of this thesis is to utilise the resources of an ordinary mobile phone to construct a guitar tuner. The tuner is to keep the user continuously updated about changes in the tone he or she is playing (i.e. continuously updating the display). Once the tuner indicate that the plucked string has been tuned, the tone played has to correspond to the correct tone, plus a reasonable error limit. The error tolerance is to be decided by the limitations of the human ear. In other words, as long as the deviation is within the error limits, a person tuning his guitar should agree that his instrument is tuned.. 1.2 Problem analysis The rst step is to nd a suitable algorithm and run simulations to verify assumptions made while selecting this particular algorithm. After a thorough verication, an implementation in a real mobile phone will follow. The rst problem presenting itself, when it comes to implementation, is sampling and temporary storage of the signal (the sound of the guitar string). Finally, the algorithm will be implemented to verify whether the mobile phone can cope with all the calculations necessary to keep the display continuosly updated, or at least the feeling that it is, with relevant information for the user.. 1.3 System description In general, all electronic tuning devices share the same basics, namely a microphone to pick up the sound of the instrument, a core that can map the sound to useful information, and some mean of presenting the result to the user. In a mobile phone you have everything needed to make a guitar tuner. The microphone to use is the same one that the user usually speaks into, the core consist of the chipset and software in the mobile, and the display can be used to present the result to the user..

(7) 6(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. -. Microphone. Reference. +. CORE DISPLAY. Figure 1: A simplied system overview.. Even though the whole system is fairly complicated, it can be simplied into three basic elements, as can be seen in gure 1. While the microphone and the display is hardware only, the core consists of both hardware and software. This thesis is concentrated around the software in the core, and more specicly the software needed to solve the problems described in section 1.1..

(8) 7(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 2 Background This section contains information that will aid in understanding the thesis as a whole. A short introduction to electronic tuners is rst presented, followed by some general theory about music and sound. A few notes on how to make the implementation more ecient is also included.. 2.1 Electronic tuners Electronic tuners provide an easy way of tuning an instrument to a desired pitch. They commonly come in two dierent shapes, called chromatic and guitar. The chromatic tuner is a general purpose tuner, able to tune any tone, while the guitar tuner is only able to tune the basic tones of a guitar or bass. This thesis is aimed at the latter, even though the methods should be suitable for both kinds of tuners.. 2.2 Musical notes. The modern western musical scale consists of 12 tones, denoted A, A# , B , C , C # , D, D# , E , F , F # , G and G# . These 12 tones form an octave. The tones in the succeeding octave have double frequency relative to the tones in the preceding octave. That is, if A has a frequency of 110 Hz, A in succeeding octave has a frequency of 220 Hz. The tones are related by, f. = fbase  2tones=12. (2.1). where f is the frequency of interest, fbase is the base frequency, generally 440Hz and tones the number of tones relative to base. Hence, if the base is an A, with frequency 440Hz, D in the same octave, will have the frequency of  5=12  : Hz. The strings on a guitar, going from bottom upwards are E , B , G, D, A and E . E is referred to as the rst string, B as the second string and so on..  440 2. 587 3. String E (1st) B (2nd) G (3rd) D (4th) A (5th) E (6th). Frequency 329.6 Hz 246.9 Hz 196.0 Hz 146.8 Hz 110.0 Hz 82.4 Hz. Table 1: Fundamental frequencies for the 6 guitar strings. Table 1 shows the fundamental frequencies of the 6 guitar strings. It can be seen that the rst string has a frequency four times the sixth string, consequently the rst string is two octaves higher than the sixth. Since, frequency changes are less noticeable in higher frequencies and more noticeable in lower frequencies, hertz is not always a preferable unit to describe dierences. Instead the unit cent are used, which better corresponds to the human ear. The intervals between two adjacent tones are divided into 100 equally sized cents. This means that a cent is equivalent to approximately 0.25 Hz at 440 Hz and 0.5 Hz at 880 Hz..

(9) 8(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. Figure 2: Fundamental frequency.. Figure 3: Second overtone.. 2.3 Tones and overtones A musical instrument does not produce sound waves of a single frequency. A note from a guitar is a superposition of a fundamental frequency and overtones, where the overtones are related to the fundamental frequency by integer factor. The fundamental frequency is the lowest tone and is vibrating between the end points with only one arc, as shown in gure 2. The rst and second overtones has frequencies twice and three times, compared to the fundamental frequency, respectively. The second overtone is shown in gure 3. Thus, a note from a guitar can be modeled by,. ()=. y t. X1. k. =1. (2. ). ak cos kf0 t. (2.2). where f0 is the fundamental frequency and ak is the amplitude of the kth harmonics. Figure 4, shows a Fast Fourier Transform (FFT) of a guitar string, where the fundamental frequency is found slightly below 200Hz and the overtones at regular intervals by integer factor. 1.4. 1.2. 1. 0.8. 0.6. 0.4. 0.2. 0. 0. 100. 200. 300. 400. 500 600 frequency (Hz). 700. Figure 4: FFT of guitar string.. 800. 900. 1000.

(10) 9(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 2.4 Pulse Code Modulation. a). time. Amplitude. Amplitude. Amplitude. One of the most common methods of encoding an analog audio signal into a digital form is called pulse-code modulation [4], abbreviated PCM. The signal is rst sampled into a discrete form called pulse-amplitude modulation, or PAM, where each sample represents the amplitude of the signal at the time of sampling. Each sample is then quantized and encoded into an n-bit digital signal. Figure 5 illustrate the dierent stages in the processing of a 4-bit code.. time. b). 0011 0100 0100 0011 0001 0001 0010. time. c). Figure 5: a) An analog signal, b) The signal represented in PAM, c) The resulting PCM encoded signal.. 2.5 Floating- vs. xed-point numerics On a computer, a fractional number is represented using a pair of integers named mantissa (m) and exponent (e). The mantissa carries the numeric information of the number, and the exponent contains information about where to place the decimal point. The fraction can then be found with the following formula: m. 2. e. (2.3). If the exponent is variable, the number is said to be a oating-point number. With this representation, a wide range of numbers can be represented, from the very small to the very large, with very good precision. If the exponent is xed, i.e. known at compile time, it is said to be a xed-point number. While oating-point numbers oers a wider range and better precision, it lacks the computational speed that can be achieved when using xed-point arithmetics. Fixed-point numbers are easy to represent, using only an ordinary integer to store the mantissa while keeping the exponent in mind when making necessary calculations. Assuming that all numbers used will be represented in the same format (having the same exponent), the only operations that need any special attention are those that may change the exponent of the result. Thus, most operations can be used with either no or slight changes to them. For instance, performing an addition (or subtraction) does not change the exponent and therefore the ordinary operation for addition can be used. A general mathematical example follows: m1.  2 e + m2  2 e = (m1 + m2 )  2. e. (2.4). However, when multiplying two xed-point numbers, the exponent of the result will dier from the factors involved in the multiplication. m1.  2 e  m2  2 e = (m1  m2 )  2 2e. (2.5).

(11) 10(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. This pose only a slight problem since the result can be rewritten in the following manner:. (m1  m2)  2. 2e = (m1  m2  2. e. )2. e. (2.6). Thus, another simple multiplication of the resulting mantissa will make sure that the exponent of the result remains the same as the factors involved. This leaves us with a normal multiplication followed by an arithmetic shift, a fairly simple operation even when the whole is being considered. Division is done in a similar fashion. The multiplication (shift), done to convert the result to have the same exponent as the factors, has to be performed before the division of the mantissas. This is in order to not lose precision. Overow can be the cause of errors if one does not take heed, so it is important to choose exponents that are suitable for the application being considered. To gain more insight on the topic, please refer to [1]..

(12) 11(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 3 Method This section holds a description of the methods used to examine the possibilities of implementing a guitar tuner in a mobile. To begin with, algorithms suitable for solving the problem is introduced. At the end, an implementation scheme for a specic mobile phone model is presented.. 3.1 Environment Having a noisy environment naturally aects the performance of an algorithm whose output depends on sound. Even though the inuence from noise can be reduced with the use of lters, the application may still be susceptible to noise and produce an unwanted output. Thus, avoiding an environment with noise, especially that which resembles the wanted signal, is encouraged.. 3.2 Frequency-tracking loops Frequency tracking loops are frequently utilised in communication systems, e.g. in digital data receivers, as frequency acquisition or as carrier frequency control. A general frequency-tracking loop, shown in gure 6, is a composition of a frequency dierence detector (FDD), loop lter (LF) and a sinusoidal generator. The FDD is the fundamental part in the frequency-tracking loop and its appearance varies depending on the application. The FDD compares the input signal and the signal generated by the sinusoidal generator and outputs the frequency dierence. The LF works as a low-pass lter, averaging out instantaneous phase errors in the loop. The sinusoidal generator generates a signal of frequency depending on the input from the LF. Thus, after a time of operation the error will reach zero and the sinusoidal generator will generate a frequency equal to the input signal.. Input Signal. Sine generator. FDD. Error. LF. Control signal. Figure 6: General frequency tracking loop. In this thesis the frequency-tracking loop will have a rather dierent area of use. The loop will function as a guitar tuner and will have a somewhat dierent appearance. The input signal is represented by the reference signal, with wanted frequency. The sinusoidal generator is represented by the guitar.

(13) 12(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. string and the error produced by FDD is displayed for the user. The user apply this information to the guitar by tightening or loosening the guitar strings. The following two sections will describe the theory behind two frequencies dierence detectors. The Quadricorrelator, section 3.2.1, and the Balanced Quadricorrelator, section 3.2.2. The former provides an output with two components, a useful DC part and an unwanted AC part. The latter provides a satisfactory result, with only a DC component. The Quadricorrelator was not used because of its weakness. However, with the Quadracorrelator in mind, the understanding of the Balanced Quadricorrelator, is straightforward. 3.2.1. Quadricorrelator. The Quadricorrelator is shown in gure 7. It consists of multipliers, low-pass lters and a dierentiator. The input signal, xin n , is the sampled signal from the guitar string. The two sinusoidal, !0 n and !0 n , are generated signals, where !0 is the desired radian frequency. Multiplication will produce signals with sum and dierence frequency of the input signal and the generated signals. The low-pass lters will suppress the sum frequency and let the dierence frequency pass. Notice that the low-pass lters will give an approximation of the range of operation for the FDD. If the dierence frequency fall outside the passband of the low-pass lters, the dierence frequency will also be suppressed. However, dening a broader passband will allow more noise and signal of higher frequencies to pass. The output of one low-pass lter is dierentiated to alter the phase. Further the outputs are nally multiplied.. cos(. Multiplicator. x. x. in. [n]. Low Pass Filter. LPF. [] ). sin(. ). Differentiator. y [n] I. d/dt. cos(w 0 n ) x. x. LPF. y. out. [n]. y [n] Q. - sin(w 0 n). Figure 7: Quadricorrelator. Below calculations for the Quadricorrelator are presented. For simplicity, gains are omitted in the equations, but are included in [2]. Let the input signal be: xin n !in n in (3.1). [ ] = cos(. + ). where !in and in is the radian frequency and an arbitrary phase angle, respectively of the input signal. As stated in section 2.3, tones from guitars are a composition of several frequencies. However, section 3.4 will show that, if the.

(14) 13(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. passband of the low-pass lters are dened correctly, the products generated by the overtones will be suppressed. Consequently, the lter outputs are calculated to be:. [ ] = cos(!n + in) yQ [n] = sin(!n + in ). (3.2) (3.3). yI n.  =. where ! !in !0 and !0 is the radian frequency of the generated signal. After dierention and multiplication, the output of the nal multiplier is:. [ ] = ! 12 [1 cos(2!n + 2in)]. (3.4). yout n. The product consists of two parts, one DC part proportional to the frequency dierence, and one AC part with double frequency compared to the frequency dierence. For this thesis, only the DC component is of interest. Thus, an algorithm with only this output would be desirable. 3.2.2. Balanced Quadricorrelator. In this section the Balanced Quadricorrelator is described, as will be shown, this frequency dierence detector output only consists of a DC part. Multiplicator. x. x. in. [n]. Low Pass Filter. LPF. Differentiator. y. [n ] I1. d/dt. x. y. [n]. I2. cos(w 0 n ). + +. y. out. [n]. x. LPF. y. d/dt Q1. x. [n ]. y. Q2. [n]. - sin(w 0 n). Figure 8: Balanced Quadricorrelator. The Balanced Quadricorrelator, is shown in gure 8. One multiplication, one dierention and one subtraction is added to the Quadricorrelator to form the Balanced Quadricorrelator. With the Quadricorrelator in mind, the analysis of the Balanced Quadricorrelator is straightforward. The output of the two nal multipliers are:. [ ] = ! 12 [1 cos(2!n + 2in)] 1 yQ2 [n] = ! [1 + cos(2!n + 2in )] 2. yI 2 n. (3.5) (3.6). Notice the similarities with the Quadricorrelator, in the previous section. The output signal of the Quadricorrelator and yI 2 are identical. However, the.

(15) 14(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. Balanced Quadricorrelator also have the signal, yQ2 , with identical AC component, but opposite DC sign. Thus, if xin , dened in section 3.2.1, is applied to the Balanced Quadricorrelator the output is: yout. = !. (3.7). The AC part has vanished. The AC part of yI 2 and yQ2 cancels out each other and the DC parts adds together. Furthermore, the phase in does not aect the output.. 3.3 Sine wave generation To rid the application from a possible bottleneck, occurring when producing the sine and cosine values with the functions provided by standard libraries, other methods have to be considered. The simplest solution is the use of a lookup-table, generating all the necessary values and store them in a simple data structure for easy and fast access. Unfortunately, the resources available in a mobile phone are quite limited, not only when speed is considered, but also resources like RAM and Flash Memory 1 . When these constraints are taken into account, the lookup-table is no longer an overall ideal solution, and instead we will consider the digital sinusoidal oscillator [3]. It is not as fast as the lookup-table, but require a very limited amount of Flash Memory. A sin w 0 d [ n ]. y[n]. +. z. y[ n - 1]. -a. 1. +. z -a. 2. -1. -1. y[ n - 2]. Figure 9: A typical 2nd order IIR lter that can be used for sine wave generation. The digital sinusoidal oscillator is implemented using an IIR lter. Placing the poles on the unit circle of the Argand diagram will make the output oscillate. Figure 9 depicts a typical implementation of a 2nd order IIR lter. This lter has the transfer function:. ( ) = 1 + a1z b10 + a2z 2 (3.8) Setting a1 = 2r  cos!o , a2 = 1 and b0 = A  sin!o will place the poles on H z. the unit circle, and the system will have the unit sample response. ( ) = A  sin(n + 1)!0  u(n). h n. (3.9). With this scheme, it is only necessary to calculate the value of sine once with the provided function. The necessary values will instead be provided through 1A. form of nonvolatile memory. Sometimes referred to as Flash RAM..

(16) 15(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. the use of the digital sinusoidal oscillator, using the xed-point format instead of the slower oating-point, thus making this part of the application more ecient.. 3.4 Simulation This section describes the simulations made to obtain knowledge about the FDDs. The simulations were made in MATLAB, which provides an easy and fast way to examine the algorithms. The understanding gained, were applied in the implementations of the FDD in the mobile phone. The rst part discusses the Quadricorrelator and examines the output from this FDD. Next, the Balanced Quadricorrelator are discussed with oating-point precision. Both ideal environment and a real environment with noise and overtones are covered. Finally, the Balanced Quadricorrelator are discussed with xed-point precision. Also here, both ideal and real environments are covered. −4. −3. 1. x 10. 5. 4.5. 0.8. 0.6. 4. 0.4. 3.5. 3 Amplitude. Amplitude. 0.2. 0. 2.5. −0.2. 2. −0.4. 1.5. −0.6. 1. −0.8. 0.5. −1. x 10. 0. 0.05. 0.1. 0.15. 0.2. 0.25 Time (s). 0.3. 0.35. 0.4. 0.45. 0.5. 0. 0. 10. 20. 30. 40. 50 60 frequency (Hz). 70. 80. 90. 100. Figure 10: Output from the Quadricorrelator, with 440 Hz as reference frequency and 445 Hz sinusoidal input. Figure 10, shows the output of the Quadricorrelator, with reference frequency set to 440 Hz and a 445 Hz sinusoidal input. The plots illustrate the outputs in the time domain (left plot) and the frequency domain (right plot), respectively. During these simulations no noise or overtones were applied. As stated in section 3.2.1, the output has a negativ DC level, depending on the frequency dierence and an AC signal, with ! frequency. The AC part is undesirable for a guitar tuner. Thus, a FDD without an AC part would be preferable. The Balanced Quadricorrelator, described in section 3.2.2, does not contain an AC signal. The output, shown in gure 11, should only consist of a DC signal. However, due to non-ideal operators some ripple appears. The reason for this is, that the low-pass lters do not suppress higher frequency suciently and the direntiators do not operate perfectly. The conditions for this plot are ideal, no noise and no overtones are present. Interesting parts of gure 11, are the unwanted ripple and the time in which the system stabilises to a certain level. A low degree of ripple is desirable to obtain accuracy and a faster system is desirable to acquire faster response time during tuning. Further, the working area of the FDD is of interest. That is, which certain level of dierence the FDD loses the possibility to detect the dierence. To obtain an FDD, which have suitable properties in these elds,. 2.

(17) 16(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. −3. 1. x 10. 0.8. 0.6. 0.4. Amplitude. 0.2. 0. −0.2. −0.4. −0.6. −0.8. −1. 0. 0.05. 0.1. 0.15. 0.2. Time (s). Figure 11: Output from the Balanced Quadricorrelator, with 440 Hz as reference frequency and 445 Hz sinusoidal input. dierent low-pass lters in the Balanced Quadricorrelator are examined. Simulations in both ideal and non-ideal conditions are made. First, in oating-point precision, to acquire knowledge about the FDDs behaviour in general. Later, in xed-point precision, to acquire knowledge about its behaviour in the mobile phone, specically. 3.4.1. Floating-point precision. This section only consider the balanced quadricorrelator since the non balanced version was never part of the implementation. −4. 1. −4. x 10. x 10 2. 0 −1. 0. −2 −2. Amplitude. Amplitude. −3 −4 −5. −4. −6 −6 −7. −8. −8 −10 −9 −10. 0. 0.05. 0.1. 0.15 Time (s). 0.2. 0.25. 0. 0.05. 0.1. 0.15. 0.2. 0.25. Time (s). Figure 12: Balanced Quadricorrelator performance in non-noisy and noisy environments, with the low-pass lters set to 5 Hz cut-o frequency. The input signal frequencies range from 440 Hz to 445 Hz, with 1 Hz incrementation, and the reference frequency set to 440 Hz. Notice that the dierent bias levels on the output corresponds to the frequency dierences between the input and reference signals..

(18) 17(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. Figure 12 to 14, show the performance of the Balanced Quadricorrelator in ideal and non-ideal environments, with dierent lter parameter settings. The rst plot in each gure shows the performance in ideal environments. In the second plot, noise and 10 overtones are added to the insignal to simulate a realistic input. In gure 12, low-pass lters with cut-o frequencies at 5 Hz are used. The low-pass lters in gures 13 and 14 utilise 10 Hz and 20 Hz cut-o frequency, respectively. The plots in gure 12, illustrates the performance of the FDD in non-noisy and noisy environments, with 5 Hz as cut-o frequency. The impact from noise and overtones are obvious. The output is more unstable, than the non-noisy plot. In addition, more ripple is introduced, in the plot. −4. −4. x 10. x 10 2. 0. 0 −2. −2. Amplitude. Amplitude. −4. −6. −4. −6 −8 −8. −10. −10. 0. 0.05. 0.1. 0.15 Time (s). 0.2. 0.25. 0. 0.05. 0.1. 0.15. 0.2. 0.25. Time (s). Figure 13: Balanced Quadricorrelator performance in non-noisy and noisy environments, with the low-pass lters set to 10 Hz cut-o frequency. The input signal frequencies range from 440 Hz to 445 Hz, with 1 Hz incrementation, and the reference frequency set to 440 Hz. Notice that the dierent bias levels on the output corresponds to the frequency dierences between the input and reference signals. The plots in gure 13, illustrates the performance of the FDD, with 10 Hz cut-o frequency. Compare the non-noisy plots in gures 12 and 13. Notice, that the time for the FDD to stabilise on a given level is shorter. Thus, a higher cut-o frequency gives a faster FDD. However, in noisy environment the FDD, with 10 Hz cut-o frequency, is uctuating more than in non-noisy environment. The plots in gure 14, illustrates the performance of the FDD, with 20 Hz cut-o frequency. The non-noisy plot stabilises faster to a given level. The noisy plot, however, is uctuating even more. Hence, with a faster FDD, accuracy is lost. This is, with lower cut-o frequency in lters, higher frequency signals and noise are suppressed and the output varies less. However, the inertia in the low-pass lters results in inertia in the FDD. And higher cut-o frequency in lters, results in lower inertia, but also a more uctuating output, when more noise and higher frequencies are allowed in the passband..

(19) 18(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. −4. Reference. −4. x 10. x 10 2. 0. 0 −2. −2. Amplitude. Amplitude. −4. −6. −4. −6 −8 −8. −10. −10. 0. 0.05. 0.1. 0.15. 0.2. 0.25. 0. 0.05. 0.1. Time (s). 0.15. 0.2. 0.25. Time (s). Figure 14: Balanced Quadricorrelator performance in non-noisy and noisy environments, with the low-pass lters set to 20 Hz cut-o frequency. The input signal frequencies range from 440 Hz to 445 Hz, with 1 Hz incrementation, and the reference frequency set to 440 Hz. Notice that the dierent bias levels on the output corresponds to the frequency dierences between the input and reference signals. 3.4.2. Fixed-point precision. Generally, oating-point calculations, are relatively slow. Thus, often xedpoint calculations are used, when processing large amount of data. Although precision are lost, xed-point are preferrable, due to speed gained during calculations. Fixed-point numerics are described in section 2.5. 0.2. 0. 0. −0.2. −0.2. −0.4. −0.4 Amplitude. Amplitude. 0.2. −0.6. −0.8. −0.6. −0.8. −1. −1. −1.2. −1.2. −1.4. −1.4 0. 0.05. 0.1. 0.15. 0.2. 0.25 Time (s). 0.3. 0.35. 0.4. 0.45. 0.5. 0. 0.05. 0.1. 0.15. 0.2. 0.25 Time (s). 0.3. 0.35. 0.4. 0.45. 0.5. Figure 15: Balanced Quadricorrelator performance in non-noisy and noisy environments, with the low-pass lters set to 5 Hz cut-o frequency. The input signal frequencies range from 440 Hz to 445 Hz, with 1 Hz incrementation, and the reference frequency set to 440 Hz. Notice that the dierent bias levels on the output corresponds to the frequency dierences between the input and reference signals. This section describes simulations with xed-point, done to acquire knowledge about the algorithms performance in a mobile phone. Figure 15 to 17, show the performance of the Balanced Quadricorrelator in ideal and non ideal environments, with dierent lter parameter settings. The rst plot in each.

(20) 19(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. gure shows the performance in ideal environments. In the second plot, noise and 10 overtones are added to the insignal to simulate a realistic input. 0.05 0.05. 0 0. −0.05. Amplitude. −0.05. −0.1 −0.1. −0.15 −0.15. −0.2 −0.2. −0.25 −0.25. 0. 0.05. 0.1. 0.15. 0.2. 0.25 Time (s). 0.3. 0.35. 0.4. 0.45. 0.5 0. 0.05. 0.1. 0.15. 0.2. 0.25. 0.3. 0.35. 0.4. 0.45. 0.5. Figure 16: Balanced Quadricorrelator performance in non-noisy and noisy environments, with the low-pass lters set to 10 Hz cut-o frequency. The input signal frequencies range from 440 Hz to 445 Hz, with 1 Hz incrementation, and the reference frequency set to 440 Hz. Notice that the dierent bias levels on the output corresponds to the frequency dierences between the input and reference signals. During xed-point simulations, intense ripple are introduced caused by the inferior precision. Hence, an additional low-pass lter is appended to deal with this problem. This solution slows down the FDD, but is needed to obtain acceptable output. Figure 15, shows the performance of the FDD with 5 Hz cut-o frequency in the low-pass lters. This system is unstable and starts to oscillate in both environments. No eorts were made to analyse this. 0.05 0.05. 0 0. −0.05 −0.05. −0.1. Amplitude. −0.1. −0.15 −0.15. −0.2 −0.2. −0.25 −0.25. −0.3 −0.3. −0.35 −0.35. −0.4. 0. 0.05. 0.1. 0.15. 0.2. 0.25 Time (s). 0.3. 0.35. 0.4. 0.45. 0.5. −0.4. 0. 0.05. 0.1. 0.15. 0.2. 0.25. 0.3. 0.35. 0.4. 0.45. 0.5. Figure 17: Balanced Quadricorrelator performance in non-noisy and noisy environments, with the low-pass lters set to 20 Hz cut-o frequency. The input signal frequencies range from 440 Hz to 445 Hz, with 1 Hz incrementation, and the reference frequency set to 440 Hz. Notice that the dierent bias levels on the output corresponds to the frequency dierences between the input and reference signals. Figure 16, shows the performance of the FDD with 10 Hz cut-o frequency.

(21) 20(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. in low-pass lters. The plot has angularities, due to xed-point precision. The dierence between the two plots are small, except from the initial phase. The plot with noise has an incorrect minor peak in the beginning, caused by the overtones. However, nally it gets similar behaviour to the non-noise plot. Figure 17, shows the performance of the FDD with 20 Hz cut-o frequency in low-pass lters. The initial peak in this plot does not have the same magnitude as the previous plot. The above simulations show that, dierences of 1 Hz between reference frequency and input frequency can be detected, theoretically. The nal low-pass lter, added to deal with the ripple, has a negative impact on the performance of the FDD, by slowing down the operation. Nevertheless, the lter is needed to obtain an acceptable output quality with xed-point calculations. Further empirical analysis of the algorithm were made in the mobile phone to obtain knowledge of performance in real-life conditions. These were done, by basically tuning a guitar with dierent lter parameters.. 3.5 Implementation This section describe the implementation derived from the methods discussed in previous sections. Whereas the methods are general and suitable for any system, the implementation described here will be aimed at a specic platform, namely Sony Ericsson's T68. The goal has been to utilise as much of the resources available, to shorten delays between updates of the display, without tampering with the ordinary functionality of the mobile phone. The C programming language has consistently been used for the implementation, even though the possibilities of assembly programming has been considered.. Figure 18: The user interface of the tuner application..

(22) 21(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. User interface. When the tuner application has been selected, the display will present the graphical user interface (GUI), found in gure 18, to the user. The joystick is used for selecting the tone the user wish to tune, and the one currently selected is displayed at the bottom of the display. When a string is being plucked, the hand (in the future referred to as tone-hand) will indicate whether the tone is of higher, lower or the same frequency as the selected tone. Thus, the tone-hand tells the user if the string needs to be tightened or loosened. Unless the string needs no adjustment, the procedure is repeated until the tone-hand indicate that the string has been tuned. How it works. This particular model of mobile phone has two processors available, one AVR2 that can be seen as the main processor, and one ARM7 3 that in this application is used as a co-processor. The workload of processing the samples is divided between the two processors. The AVR-processor deals with sampling, precalculations of the samples and updating the GUI, while the ARM processor is used for most of the signal processing. Figure 19 illustrate the implementation in general, while gure 20 hold a detailed view of the processes involved.. 2 ARM. 3. -. +. 4. AVR. DISPLAY 1. Microphone Figure 19: An overview of the implementation scheme. The sampling process, located in the AVR and driven by interrupts, is responsible for fetching and storing blocks of samples. The microphone interface deliver 16-bits PCM-samples, and a shared buer is used to forward the data to the sending process. Data in the buer is protected from being prematurely read or overwritten, i.e. overwritten before it has been read, using a counting semaphore. When data is available in the buer, the sending process is signaled and allowed to read a block of data, normalize the samples, and send it to the ARM. The tuning process perform all necessary calculations (section 3.2.2) 2 AVR. is a microprocessor built by Atmel.. For more information, please consult their. webpage at http://www.atmel.com. 3 The. ARM processors are developed by Advanced Risc Machines. More information about. the processors can be found at http://www.arm.com.

(23) 22(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. needed to decide the deviation from the reference frequency, i.e. the frequency of the tone looked after, and then sends the result back to the AVR. When receiving a result from the ARM, the MMI process updates the display to notify the user about possible changes. AVR. ARM MMI Process. Sample Buffer. Data. Sampling Process. Tuning Process. Sending Process. Figure 20: Schematic view of the processes involved.. Volume threshold. To make the application less susceptible to update the display when noise is the only sound being received, a volume threshold is set. Hence, unless the sample volume reach the specied threshold, no samples will be sent to the ARM and no update of the display is made. Hardware limitations. One of the hardware limitations is that lters will suppress all frequencies below 300 Hz and above 3.4 kHz. Since almost all of the strings on a tuned guitar produce tones with a lower frequency than 300 Hz, this pose a serious limitation to the application. However, with the use of overtones (section 2.3), it is still possible to tune all the strings on the guitar. Another limitation is the processing power. Even though the use of xedpoint arithmetics (section 2.5) remedy this problem partially, it is still not possible to process all the incoming samples. Instead, a subset of the samples are used in order to produce a smooth and continuos updating scheme for the tonehand. The buer, seen in gure 20, is used to get as long continuos signal as possible, something that is desirable when trying to decide the current tone..

(24) 23(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 4 Result and discussion The accuracy of the tuner is quite dicult to determine, but with the help of a PC tuner application4 and a commercial tuning device5 , an estimation has been made. On average, the deviation from the desired tone is less than + cent (for the denition of cent, see section 2.2). This is comparable to the guitar tuners that emerged early on the market, but a musician with a good ear would probably be able to notice the deviation. Currently, the implementation is unable to handle incoming calls. Due to lack of time, this shortcoming was given low priority and was never really looked into. However, only minor modications are probably needed to be able to handle this. Even though the specication for the thesis clearly stated that this was not a requirement, it would still have been desirable to handle calls.. 3. 4 AP Guitar Tuner 1.02 by Audio Phonics. 5 Matrix SR-4000 Auto Chromatic Tuner..

(25) 24(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 5 Conclusions The hardware suppresses frequencies outside 300 Hz and 3.4 kHz, so frequencies below 300 Hz can not be used. It would be preferable with hardware that does not suppress lower frequencies though a majority of the fundamental frequencies on a guitar are below 300 Hz. However, it is possible to use the overtones of the strings. The implementation is not as robust and easy to use as is desired. So additional work is needed for the tuner to become a commercial product. This is discussed further in section 6. More processing power are needed. If the application where implemented in the T68, the DSP would be a preferable place to implement the algorithm. However, future phones will have better processors and better processing power. Thus, an ordinary processor might be sucient in the future..

(26) 25(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. 6 Future work Although, a guitar can be tuned with existing implementation, it needs some further studies to become a commercial product. The tuner must be more robust. Current implementation gives a rather uncertain impression. Further analysis of the FDD should be made to improve this. Other algorithms, should also be considered, for example, phase-locked loops. Additional, performance when the string is out of range needs improvements. As previously described, the tuner does not give an accurate answer if the deviation is too large. A commercial product is required to have better out of range performance, as the user always should be informed if the string should to be loosened or tightened. The tuner should also be able to identify an arbitrary frequency. That is, the users does not have to select tone. The tuner identies the frequency and associates it, with the closest tone. Both these features, could probably be solved with FFT. In this thesis, no eorts where made to examine the DSP, existing in the mobile phone. The DSP is however of high interest for implementing the algorithms. If further eorts are made, resources should be allocated to study the DSP. Currently, the tuner is only able to tune guitars. Tuning others instruments, like violins and wind instrument is a possible continuation..

(27) 26(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). A. Date. Rev. 2002-06-05. A. Glossary. AC DC DSP FDD FFT GUI IIR LF LPF MMI PAM PCM RAM. Alternating Current. Direct Current. Digital Signal Processor. Frequency Dierence Detector. Fast Fourier Transform. Graphical User Interface. Innite Impulse Response. Loop Filter. Low Pass Filter. Man Machine Interface Pulse Amplitude Modulation. Pulse Code Modulation. Random Access Memory.. Reference.

(28) 27(27). Open REPORT Prepared (also subject responsible if other). No.. LD/ECS/GUB/DK Henrik Ahlm / Mathias Jeppsson Approved. Checked. LD/ECS/GUB/DK (John Sarhede). Date. Rev. 2002-06-05. A. Reference. References [1] Advanced RISC Machines Limited, www.arm.com. Application Fixed Point Arithmetic on the ARM, September 1996.. Note 33,. [2] Gardner Floyd M. Characteristics of frequency-tracking loops. In Chak M. Chie William C. Lindsey, editor, Phase-Locked Loops. IEEE Press, 1985. [3] Dimitris G. Manolakis John G. Proakis.. DIGITAL SIGNAL PROCESS-. , chapter 4, pages 352354.. ING : Principles, Algorithms and Applications. Prentice-Hall, 3rd edition, 1996. [4] Ken C. Pohlmann. Principles of McGraw-Hill, 4th edition, 2000.. , chapter 3, pages 4952.. Digital Audio.

(29)

Figure

Figure 1: A simplied system overview.
Figure 3: Second overtone.
Figure 5: a) An analog signal, b) The signal represented in PAM, c) The result-
Figure 6: General frequency tracking loop.
+7

References

Related documents

At the end, the results were analysed from four different points of view to show significance of: (i) acoustic model, (ii) speech quality, (iii) language model, and (iv)

The tuning-speed was appraised by counting the number of times a guitar string had to be plucked before the motor stopped within an acceptable tun- ing interval.. The automatic

Det nya är att företagsinterna event (också kallade corporate events) efterfrågas tillsam- mans med en uppdelning av de externa eventen utifrån om de riktar sig mot företag

Om man gjorde alla lärarna på skolan medvetna om vilka faktorer som kan påverka självförtroendet och vilka olika pedagogiska strategier man som lärare kan använda sig av i

Even though neurons and glial cells play two different functions within the CNS they share the same origin; both are generated from neural stem cells which ultimately produce a

Flertalet pedagoger har uppmanat elever till att använda olika mobiltelefonens olika funktioner såsom applikationer, miniräknare, internet, fotografering och ljudupptagning för

Detta för att få motmedelssystem vars energi skapas genom helikoptern, och medgör att ett systemfel krävs för att helikoptern inte skall kunna generera ett självskydd. Forskning

Recent policy developments at EU and regional levels – endorsement of the Ecosystem Approach by HELCOM and in various EU acts related to marine environmental management and the