You are on page 1of 6

Integrated Guitar Tuner

Launizar Rocha Hugo Natanael


Depart ment of Electrical Engineering, Instituto Tecnolgico de Tijuana, Tijuana B.C., Mexico Phone (661) 110-6600 E-mail: razinual_oguh@hotmail.co m

Abstract The present document describes the design and implementation of the integrated guitar tuner project, made for the microprocessors and microcontrollers subject. It explains the process and development of the project. It is divided in three main parts, the signal acquisition from the guitar, the acquired signal conditioning and fundamental frequency detection, and the results and user interface programming. The main reason for this project was the need for a guitar tuning method that would not involve external appliances such as tuners or a tuner-integrated footswitch, and to be something that already comes integrated with the guitar. This was achieved using external filters together with a microcontroller with all the programming. And it is this programming the basis of the project, as it is the main concept of what the subject is about: microcontroller programming. Keywords Band pass Filter, Fundamental Frequency, Integrated Tuner, Microcontroller, Tuning.

II. M ET HODOLOGY A. Band Pass Filtering. A simple Active Band Pass Filter can be easily made by cascading together a single Low Pass Filter with a single High Pass Filter as shown in Fig. 1.

Fig 1. Block diagram of the bandpass filter

I. INT RODUCT ION A guitar is an acoustic- based musical instrument, wh ich works due to the vibration of the strings generated by plucking them, and depending of the musicians skill and talent, these can make harmon ic sounds. Also, another important thing is that each string should vibrate at a certain wavelength; therefore each one must be tuned to a certain predefined scheme. There are six strings, and each one has a defined musical note to it, so depending of the strings pressed, the resulting wavelength will change and other notes will co me as a result. Many times one has the need to tune the instrument, and yet there is not a tuner at hand, when in fact it should be a part of the instrument itself. Likewise, an empirical tuning by ear alone is notoriously unreliable when you h ave no experience, as mentioned before. As an innovation, it is something very amusing which can be imp lemented on electric guitars in a general manner, while financially benefit ing the seller for drawing the markets attention, since it is also a better choice from a technical point of view, because it would save having to get the guitar and the tuner separately.

The cut-off or corner frequency of the low pass filter (LPF) is higher than the cut-off frequency of the high pass filter (HPF) and the difference between the frequencies at the -3dB point will determine the "bandwidth" of the band pass filter while attenuating any signals outside of these points. One way of making a very simple Active Band Pass Filter is to connect the basic passive high and low pass filters we look at previously to an amplify ing op-amp circuit as shown in fig. 2.

Fig 2.Active Band Pass Filter

This cascading together of the individual low and high pass passive filters produces a low "Q-factor" type filter circuit which has a wide pass band. The first stage of the filter will be the high pass stage that uses the capacitor to block any DC biasing from the source. This design has the advantage of producing a relatively flat asymmet rical pass band frequency response with one half representing the low pass response and the other half representing high pass response as shown.

Fig 3.Band Pass characteristic

The higher corner point (H ) as well as the lower corner frequency cut-off point (L ) is calculated the same as in a standard first-order low and high pass filter circu its. A reasonable separation is required between the two cut-off points to prevent any interaction between the low pass and high pass stages. The amplifier provides isolation between the two stages and defines the overall voltage gain of the circuit. The bandwidth of the filter is therefore the difference between these upper and lower -3dB points. The normalized frequency response and phase shift for an active band pass filter will be as follows.

the filter is related to the values of R1, R2, C1 and C2. The output of the filter is again taken fro m the output of the op amp. We can improve the band pass response of the above circuit by rearranging the components again to produce an infinite gain multip le feedback band pass filter. This type of active band pass design produces a "tuned" circuit based around a negative feedback active filter g iving it a high "Qfactor" (up to 25) amp litude response and steep roll-off on either side of its mid frequency. Because the frequency response of the circuit is similar to a resonance circuit, this centre frequency is referred to as the resonant frequency, (r). Th is is shown in the circuit below.

Fig 6.Infinite Gain Multiple Feedback Active Filter

This active band pass filter circu it uses the full gain of the operational amplifier, with multip le negative feedbacks applied via resistor, R2 and capacitor C2. Then we can define the characteristics of the filter as fo llo ws:
Fig 4.Active Band Pass Frequency Response

While the above passive tuned filter circuit will work as a band pass filter, the pass band (bandwidth) can be quite wide and this may be a problem if we want to isolate a s mall band of frequencies. Active band pass filter can also be made using inverting operational amplifiers, and by rearranging the positions of the resistors and capacitors within the circuit we can produce a much better filter circuit as shown below. The lower cut-off -3d B point is given by C2 while the upper cut-off -3d B point is given by C1 .

(2)

We can see then that the relationship between resistors, R1 and R2 determines the band pass "Q-factor" and the frequency at which the maximu m amplitude occurs, the gain of the circuit will be equal to -2Q2 . Then as the gain increases so does the selectivity. In other words, high gain results in high selectivity. B. PIC M icrocontroller C Programming. Besides the common known C programming topics, three other things must be taken in consideration, regarding PIC microcontrollers for this pro ject, specifically the 18F4550. Further information can be found in the microcontrollers datasheet.

Fig 5.Inverting Band Pass Filter Circuit

(1)

This type of band pass filter is designed to have a much narrower pass band. The mid frequency and bandwidth of

Oscillator configuration. There are several fuses that can be configured depending on what is the desired oscillator frequency for the microcontroller. For co mp lete definit ion and configuration refer to the Microcontroller datasheet. These are the most relevant:

HSPLL: For crystals over 4MHZ using PLL, else if 4M HZ it changes to XTPLL. A. Signal Filtering MCLR: It means that pin 1 will be used as Master Clear. USBDIV: It means that the USB clock will be taken fro m PLL/2. PLL5: The PLL pre-scaler will d ivide by 5 the crystals frequency. CPUDIV1: The PLL post-scaler decides the division by 2 of the output frequency fro m the 96MHz PLL. VREGEN: Enables the 3.3 voltage regulator used by the USB. If not in use, NOVREGEN should be used. There are mo re fuses to configure, but the compiler configures the rest. Regardless of this, the datasheet should be consulted prior to this. Timer1. It can work using an external oscillator and run at a frequency different to the main oscillators frequency. Same as TMR0, Timer 1 can run in two modes: as a timer and as a counter. Operation mode is determined by the selected cock type, internal for timer or external for counter. Its configured using setup_timer_1( ) function, found in the microcontrollers header file. For details the header should be revised. The time it takes to increment is called a step; this time depends on the oscillators frequency and the selected prescaler. The formu la to determine Timer1s timings when used with an internal clock is TMR1_OF=4* P*(65536-TMR1)/Osc_F. (3)

III. RESULT S

Since the output of the guitar has low amplitude that is about 3mV peek to peek, the signal must be amp lified before running it to the 18F4550s ADC. To do this, it needs the circuit shown below:

Fig 6. Guitar signal conditioning circuit

This signal conditioning circuit is divided into four stages:

Fig 7. Guitar signals offset circuit

Where TMR1_ OF is the timers overflo w, P is the prescaler, TMR1 is the timers initialization value, and Osc_F is the oscillators frequency. ADC module. The functions in PIC-C for using the ADC module are as fo llo ws: SETUP_ADC (M ODE) Init ialization for the ADC module. It refers to the ADCON0 register bits 7 and 6. SETUP_ADC_PORTS (VA LUE) Defines the analog inputs to use, equivalent to ADCON0 b its 3 to 0. SET_ADC_CHANNEL (CH) Selects analog channel to enable. VA LUE = REA D_ADC () Reads the result, where value is a 16 bit integer, according to the #DEVICE ADC= applied directive.

Offset stage - The purpose of this stage is to filter out any DC bias the guitar may apply to its AC output. The guitar is connected through a 3.5mm headphones jack. The 1uF capacitor blocks any DC bias and the two 1M-ohm resistors introduce a 2.5V bias to the AC signal to center it. It is important to note the 3DB frequency or half amplitude of the filter created by the 1uF capacitor and 1M-ohm resistor. The frequency of this high-pass filter is given by f = 1/(2*p i*R3*C1) = 0.16 Hz.

Fig 8. Amplification stage

Amplification stage The purpose of this stage is to amp lify the guitar signal but block DC amplification. Since the DC offset is 2.5V, amplify ing the bias causes the opamp to rail. Fo r this reason, a capacitor is set to ground to block DC amplification. The low pass filter to ground formed by the capacitor and resistor has a 3DB cutoff frequency of f = 1/(2*p i*R2*C2) = 3.39 Hz. The opamp is set up in a non-inverting amplifier configuration as shown in fig 8, which has a voltage gain of Av = 1 + R2/ R3 = 1 + 200/ 1 = 201.

This gives the amplified signal a cleaner shape, only letting through the necessary frequencies for detection through the microcontroller.

Fig 10. Band pass filtering stage

Fig 9. Band pass filtering stage

Band pass filtering stage - An active 2-pole band pass Butterworth filter was designed, following the informat ion found in the active filter design techniques document from Texas Instruments [1]. The first thing to do is to define the med iu m frequency (fm), the bandwidth (BW), and the filter gain (Am). For this case the medium frequency selected is 188.5 Hz, and the bandwidth is 115 Hz; this is because the cutoff frequencies are taken fro m E3 (131 Hz) to B3 (246 Hz); that is only one cycle of the musical tempered scale, and its in the middle of all other frequencies fro m the guitar. This way the other harmonics are not included into the signal.

. Saturation stage - Its purpose is to further amplify the signal so that it gets into the 5V to 0V range, turning into a saturated 2.5V peek to peek with a 2.5V bias, or almost square signal. This amplifier has a gain of Av = 1 + R2/R3 where R9 is 328 and R8 is 150k. Thus Av = 457. The total gain fro m stages 2 and 4 is then 201 * 457 = 91920, y ield ing a peek to peek voltage of 3mV * 91920 = 275V. This is impossible as the voltage source only provides 5V, so it gets saturated. The main reason for this is because the string dims quickly and the software is still slow at acquiring, so the signal needs to stay as long as possible. The low pass filter to ground formed by the capacitor and resistor has a 3DB cutoff frequency of f = 1/(2*p i*R9*C3) = 5.13Hz. Therefore , overall, the circuit cuts out any frequencies below 5.13Hz. This presents no problem, because this low frequency is out of the range of human hearing and unachievable on the guitar. This way the circuit provides an interface that filters the signal to enter the microcontroller, without any unwanted harmonics. The resulting signal is shown in Figure 7.

Table 1. Values of alpha or different Qs

The values for a1, b1, and alpha are taken fro m table 1, which in this case are for a Butterwo rth type filter. These values are a1=1.4142, b1=1, Q=1 and alpha=1.4426. The capacitor is proposed as 10nF. With this values and inserting the equations in Excel, the resistor values for the filter were obtained, and are as follows: R2 = Q / ( *fm1 *C) = 200k R1 = R2 / (2*A m1 ) = 603k R3 = A m1 *R1 / 2Q2 + A m1 = 22k

Fig. 11 Band pass filter input and output

The observed sinusoidal signal co mes fro m a generator at a frequency of 200 Hz, which is only a frequency in the middle of the bandwidth used for testing purposes . The amp litude is less than 100 mV and presented here to display the resemblance in the input and output frequencies. The blue wave is the output of the filter, as can be seen is in the

range of 0 to 5V. The frequency is the same, as shown in Figure 11, but the waveform is designed so that it can work in the microcontroller. B. Program Code The program is div ided into two main parts. One is the guitar tuning mode, and the other is the tuning selection menu. Here is a short overview. Tuning mode. The analog signal enters the microcontrollers ADC through the A0 input. It then enters a loop where it searches for the bias voltage, which is 2.5V, using this code
Sold = S; //store old value S = read_adc();//sample if(Sold < bias && S >= bias) //if trigger { zerocross=zerocross+1; //cuenta //cruce por cero }

delay_ms(300); lcd_gotoxy(1,1); printf(lcd_putc, "\fStd. Tuning Ok!"); printf(lcd_putc, "\nE A D G B e"); delay_ms(500); printf(lcd_putc, "\f"); output_low(pin_C4); break;

After the set of frequencies are loaded, the function ends and goes back to the main menu, either to select another tuning mode, or to tune the guitar.

Fig. 13 T uning selection mode

IV. DI SCUSSION The main problem while doing this project was the signal filtering. Several methods were applied, one was to filter the full range of the guitar frequency bandwidth, but it was useless because the secondary harmonics induced noise to the acquired signal, making it unstable. Another issue that needs fixing is the frequency acquisition. The first approach was to detect the zero crossings during one second to directly determine the frequency from the signal in the ADC. Th is method, though the most precise, was too slow to determine, and by the time the frequency stabilizes and gets processed in the microcontroller, the sound is dimmed. Therefore, it rarely showed the precise tuning. In contrast, while try ing to make it faster by reducing the timer overflo w, this had to be mult iplied to determine frequency. But the variations grew larger. Another method of detecting frequency was to detect the time fro m a zero crossing from h igh to low, to a low to high cross. But the returned value though stable, could not be converted to its frequency form due to the lack of informat ion, or maybe misinterpretation, resulting in trialand-error to find the right interpretation of the acquisition fro m the timer. Surely with some more research this can be solved, and it may be the most precise way to detect the frequency. If time allo ws, the project can be optimized for real use. The development of the project took more time than what was expected to be given for this semesters microcontroller subject, and yet it needs more work. Nevertheless, it is a

When it happens, it counts one zero crossing going from low to high. The iteration goes on for one second, established by the instruction. Then, the overflow interruption is executed, and it runs the frequency analysis, stabilization and LCD display algorith ms. Figure 12 shows the resulting screen
set_timer1(3036)

Fig. 12 LCD tuning screen

In this screen, the current ADC frequency, the selected string and the status bar are shown. The status bar shows a letter x to point how near the ADC frequency is from the base frequency of the selected string is. Therefore, the string being tuned should be selected manually, using the two side buttons. Tuning selection menu. This mode is a menu where different frequency values can be loaded, according to each of three common tuning modes: Standard mode, Drop-D mode, and Half-Step Up mode. Each has its own set of base frequencies and frequency limits. The code is based on a switch structure, where a constant named cuerda decides which set of frequencies will be loaded for tuning.
STRING_1=329.6; STRING_2=246.9; STRING_3=196; STRING_4=146.8; STRING_5=110; STRING_6=82.4;

large advance to what a real commercial guitar tuner actually does. V. CONCLUSION The system works, even though it is still slow. The band pass filter gives the frequency range it was designed for, and it cancels most of the noise and unwanted harmonics. The microcontroller code for frequency acquisition still needs optimization, but in essence it does it nevertheless. As for the specific objectives of the pro ject, the generated frequency fro m the guitars pickup was effectively detected, though at times it gives an incorrect reading due to unknown causes. But when used with a tone generator coming fro m the co mputer through the headphones socket, it performs flawlessly. For the note-to-frequency relating part of the code, it also works right. The frequency ranges were taken fro m the general info about the guitar, and the standardized values are in use, so it is universally acceptable. The plucked string must be selected first, of course, as it has been stated in the results section. The displayed results are properly working, though at first there was trouble due to a broken LCD, which was the only one due to financial reasons and could not afford to acquire a new one. The simu lation works flawlessly, so even though only half of the screen can be seen in the prototype, it is implied that the code is working. In general, the objectives were met, though it still needs improvements so that it can actually be used as a real guitar tuner. But given the time allotted, this was as far as the project got finished. A CKNOWLEDGMENT The author H. L. thanks God for the life g iven, thanks to the family for their full support both emotional and motivational. This project is dedicated to Miguel Launizar, who helped the author give orig in and develop this projects main concept, and whose illness made the author realize the bliss of having him as a brother. REFERENCES [1] Thomas Kugelstadt, Active filter Design techniques (2011) Mohd Hairedzan Bin Kamaluddin, Automatic guitar tuner (2010) Ilan Lachish, Automatic Guitar tuner (2001).

Evan Anderson, Infinitune Project Proposal, (2011) Charles Duvall, Design and Fabrication of a mixed signal automated Guitar tuning system (2008)