You are on page 1of 47

AIR JAM

Session 2006

Project Advisor: Dr. K.M.HASSAN Group Members: MARYAM MOHSIN ZAHRA FATIMA 2006-E-185 2006-E-199

DEPARTMENT OF ELECTRICAL ENGINEERING UNIVERSITY OF ENGINEERING & TECHNOLOGY, LAHORE

AIR JAM
This project report is submitted to the Department of Electrical Engineering, University of Engineering and Technology, Lahore Pakistan, for the partial fulfillment of the requirements of the degree of

Bachelor In Electrical Engineering

Approved By:

Internal Examiner ( Supervisor )

Signature: _______________ Dr. K.M.Hassan

External Examiner

Signature: _______________ Name: _________________

DEPARTMENT OF ELECTRICAL ENGINEERING UNIVERSITY OF ENGINEERING & TECHNOLOGY, LAHORE

ii

ACKNOWLEDGEMENTS

The completion of any project brings with it a sense of satisfaction, but is never complete without thanking those people who made it possible and whose constant support crowned our efforts with success.

One cannot even imagine the power of the force that guides us all neither can we succeed without acknowledging it. Our deepest gratitude to ALMIGHTY ALLAH Who enabled us to complete this project.

This project could never have been completed without the guidance and encouragement of our advisor, Sir K.M Hassan. We would like to thank our parents for their unwavering support, prayers and belief in us. We would also like to thank staff members of EE department and KICS for providing us the required facilities.

iii

ABSTRACT

Our project Air Jam is inspired by the idea of having a machine that will take our jamming and turn it into music we can actually hear. Guitar simulations have been around since a long time. In this project we have focused on mathematically processing two inputs, corresponding to the selection of chords of the guitar and strumming of its strings, and using them to synthesize the sound of an acoustic guitar. Initially we had aimed to use flex sensors to show the selection of chords but due to budget constraints we opted for variable resistors instead. Similarly we had to give up the idea of using an accelerometer as our strumming device. Instead we will be providing the input to the microcontroller in the form of a varying voltage that corresponds to the different strings being strummed. The core of our project is the microcontroller code that processes the inputs and produces the desired frequencies.

iv

TABLE OF CONTENTS

1 INTRODUCTION 2 THEORETICAL BACKGROUND 2.1 STRUCTURE OF A GUITAR 2.2 GUITAR STRINGS 2.3 CHORDS OF A GUITAR 3 IMPLEMNTATION OF CHORDS USING CODE 4 FUNCTIONAL COMPONENTS 4.1 VARIABLE RESISTORS 4.2 VOLTAGE WAVEFORM 4.3 CODING 5 OPERATION OF THE SYSTEM 6 RESULTS REFERENCES

1 3

8 9

35 37 40

LIST OF FIGURES

Fig-2. 1: AN ACCOUSTIC GUITAR Fig-2.2: EXAMPLE OF A CHORD Fig-4.1: Time response of a guitar strum Fig-4.2: Frequency Response of a guitar strum Fig-4.3: A classic ADSR envelope Fig-4.4: A typical ADSR envelope for a guitar

5 6 14 14 15 16

Fig-4.5: Time and Frequency response of a guitar strum using the Musical Instruments Properties Project 17 Fig-4.6: Wavetable synthesis 19

Fig-4.7: (a) Attack, (b) Sustain and (c) Release Wave Shape of a Real Pluck String 20 Fig-4.8: Original Karplus-Strong Algorithm Fig-4.9: (a) Attack, (b) Sustain and (c) Release Wave Shape of a Pluck String Create with The Karplus-Strong Algorithm 21

21

Fig-4.10: (a) Low-Pass Filter Magnitude Response, (b) Low-Pass Filter Phase Delay 23 Fig.-4.11: Desired Pitch Versus Resulting Pitch for a 44100 Hz Sampling Rate

24

Fig-4.12: Waves Created by the Karplus-Strong Algorithm for a (a) Low Frequency (100 Hz), and for a (b) High Frequency (1260 Hz) at a Sampling Rate of 44100 Hz 25 Fig-4.13: Jaffe and Smith Extension Fig-4.14: Extended Karplus-Strong (EKS) filters Fig-5.1: Block diagram 26 29 35

vi

LIST OF TABLES

Table-2.1: GUITAR STRINGS AND FREQUENCIES Table-4.1: CHORD ENCODING Table-5.1: THEORETICAL AND AIRJAM FREQ

5 10 37

vii

CHAPTER 1

INTRODUCTION

Musical instruments have been around from ever since we can remember. Guitar in particular is used in every genre of music. So why not create the guitar sounds using simple electrical components and to see if it is possible to mathematically manipulate the sounds. The main inspiration of our project came from the idea of air jamming. This is basically an act of playing a guitar while moving your fingers in air. We wanted to implement this idea so that moving our fingers in air will produce real guitar sounds. Hence our project Air Jam. There are three basic functional components of Air Jam: 1) The variable resistors 2) The Voltage Waveform 3) The Code The variable resistors provide an input for the chords to be played. The voltage waveform is used to simulate the strumming of the guitar strings. The code is the basic part of the whole project since it not only implements the Karplus Strong string synthesis theorem which produces the sound of strings but also includes functions to play different chords of the guitar which essentially produce a note.

Karplus Strong theorem is the heart of the code which uses a burst of white noise (generated in this case by the repeated use of the stdlib rand() function) that is repeatedly filtered and played back. The frequency of the delay controls the frequency of the plucked string with a simple formula: Delay Length L = Fsample/Fout. It must be remembered that each guitar has 6 strings which have different frequencies associated with them.

CHAPTER 2

THEORETICAL BACKGROUND

2.1

STRUCTURE OF GUITAR [1]

The guitar is a stringed musical instrument played by plucking, either with fingers or a pick. The guitar consists of a body with a rigid neck to which the strings, generally six in number but sometimes more, are attached. The basic parts of a guitar are: Neck Frets Fret board Body

NECK A guitar's frets, fret board, tuners, headstock, and truss rod, all attached to a long wooden extension, collectively constitute its neck. The wood used to make the fret board usually differs from the wood in the rest of the neck. The bending stress on the neck is considerable, particularly when heavier gauge strings are used, and the ability of the neck to resist bending is important to the guitar's ability to hold a constant pitch during tuning or when strings are fretted. The rigidity of the neck with respect to the body of the guitar is one determinant of

a good instrument versus a poor one. The shape of the neck can also vary, from a gentle "C" curve to a more pronounced "V" curve.

FRETS Frets are metal strips (usually nickel alloy or stainless steel) embedded along the fret board and located at exact points that divide the scale length in accordance with a specific mathematical formula. Pressing a string against a fret determines the strings' vibrating length and therefore its resultant pitch. Standard classical guitars have 19 frets. Frets are laid out to a mathematical ratio that results in equal tempered division of the octave. The ratio of the spacing of two consecutive frets is the twelfth root of two. The twelfth fret divides the scale length in two exact halves. Every twelve frets represent one octave.

FRET BOARD Also called the fingerboard, the fret board is a piece of wood embedded with metal frets that comprises the top of the neck. It is flat on classical guitars and slightly curved crosswise on acoustic and electric guitars. Pinching a string against the fret board effectively shortens the vibrating length of the string, producing a higher pitch.

BODY In acoustic guitars, string vibration is transmitted through the bridge and saddle to the body via sound board. The sound board is typically made of wood. Timbers for tone woods are chosen for both strength and ability to transfer mechanical energy from the strings to the air within the guitar body. Sound is further shaped by the characteristics

of the guitar body's resonant cavity. The body of an acoustic guitar has a sound hole through which sound projects. The sound hole is usually a round hole in the top of the guitar under the strings. Air inside the body vibrates as the guitar top and body is vibrated by the strings, and the response of the air cavity at different frequencies is characterized, like the rest of the guitar body, by a number of resonance modes at which it responds more strongly.

Fig-2.1: An Acoustic Guitar [1]

2.2

GUITAR STRINGS

STRING First Second Third Fourth Fifth Sixth

NAME High E B G D A Low E

SCIENTIFIC PITCH E4 B3 G3 D3 A2 E2

FREQUENCY 329.6 Hz 246.94 Hz 196.00 Hz 146.83 Hz 110 Hz 82.41 Hz

Table-2.1: Guitar Strings and Frequencies [2]

The low E is the thickest string and high E is the thinnest string. Conventionally, the string with the highest pitch (the thinnest) is called the first string, and the string having the lowest pitch is called the sixth.

2.3

CHORDS OF A GUITAR

A guitar chord is a collection of tones usually sounded together at once, played on a guitar. It can be composed of notes played on some adjacent or separate strings or all the strings together. Most guitars used in popular music have six-strings and are tuned (from the lowest pitched string to the highest): E-A-D-G-B-E

Fig-2.2: Example of a chord

In the case of C Major, these notes are C, E and G. The graphical representation on the left shows how left-hand fingering produces: the low E string has no dots, so it's not played the A string has a dot above the 3rd fret, So we put a finger on the 3rd fret the D string is fingered at the 2nd fret the G string is open the B string is fretted at the 1st fret the high E string is open

CHAPTER 3

IMPLEMENTATION OF CHORDS IN THE AIR JAM CODE

Now the C major chord can be implemented in the code using the following strategy strLE is not played strA[3] means string A on third fret strD[2] means string D on second fret strG[0] means string G is open and so is strHE[0] strB[1] means string B on first fret chords[7][0] = 0; chords[7][1] = strA[3]; chords[7][2] = strD[2]; chords[7][3] = strG[0]; chords[7][4] = strB[1]; chords[7][5] = strHE[0];

This is how chords are implemented via our C language code.

CHAPTER 4

FUNCTIONAL COMPONENTS OF AIR JAM

The components used in the project are Variable resistors x5 Op-Amp LM741 x5 Micro-controller ATMEGA32L Capacitors, resistors, diodes Power supply

4.1

VARIABLE RESISTORS [2]

A frequent element of electronic devices is a three-terminal resistor with a continuously adjustable tapping point controlled by rotation of a shaft or knob. These variable resistors are known as a potentiometer when all three terminals are connected, since they act as a continuously adjustable voltage divider. The resistance of the variable resistors is changed to attain a chord that is to be played.

OPERATION OF THE VARIABLE RESISTOR [3] Our guitar is essentially a chord player. With 5 variable resistors we can have up to 32 different encodings of different chords we can play. Wires run from the resistors to our circuit board through a voltage divider and an analog comparator implemented by an op-amp with the

inverting input tied to a 3.33 V line. The voltage divider between the variable resistor and R brings the non-inverting line above and below 3.33 V as the resistance is changed. The input from the resistors, through the op-amps goes to 5 ADC inputs of the microcontroller. The code uses these inputs to determine which chords are selected to be played. Each chord has a different combination. The chord input is sampled at 100 Hz (roughly twenty times as fast as a human can strum a guitar.) This sampling rate gives responsive audio feedback and provides with the ability to control volume and expression of sound. So in this way we can play different codes by just adjusting the resistances of the resistor. Initially the goal was to use flex sensors which provide more flexibility and give the feeling of air jamming in its truest form. But due to its unavailability we are resorted to use variable resistors.

CHORDS ENCODING

Chord # 1 2 3 4 5 6

Variable resistors values 00001 00010 00011 00100 00101 00110

Chord Name B minor F sharp major A major E major G major D major

10

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001

E minor C major C minor C sharp major C sharp minor D major D minor D# major D# minor E major E minor F Major F minor F# major F# minor G major G minor G# major G# minor

11

26 27 28 29 30 31 0

11010 11011 11100 11101 11110 11111 00000

A major A minor A# major A# minor B major B minor Open Strings

(A 1 shows, that the resistor is turned to higher resistance )


Table-4.1: Encoding of the chords with resistors [4]

4.2 VOLTAGE WAVEFORM CORRESPONDING TO STRUMMING Our code processes two inputs. One for the chord and other for the strumming. Ideally speaking the strumming should be in real time with an accelerometer outputting the voltage waveform corresponding to the acceleration and deceleration of the pick. The function of an accelerometer is to provide accurate response to movement in measurable increments small enough to be converted to useful signals. This is accomplished by converting physical measurement of movement from a mass into electronic impulses that can be interpreted by a separate electronic device. But since accelerometers are hard to come by as single units and must be bought in large numbers as an industrial and commercial supply, therefore we have implemented the strumming as an input waveform, which we will supply by ourselves. The waveform might be obtained either using the data available on the internet, or by simulating the accelerometer on MATLAB. Either way, our goal is to obtain a
12

varying voltage having an analog value from 0 V to 3 V. This output is hooked up to the Mega32's A to D converter through a simple protective circuit (diodes to prevent any voltage less than 0 or greater than Vcc from being put on the ADC input pin). The strumming input is sampled with frequency 8 kHz (the music sampling rate) by our code in order to catch the very brief output spikes caused by the rapid acceleration and deceleration of the pick that is reflected by the changing waveform. After an above threshold voltage is found, the MCU saves that value and stops polling the ADC for 100 ms to give the control code a chance to catch this trigger and process it.

MATLAB SIMULATION OF A GUITAR STRUM An acoustic guitar like the one that we have been trying to model has two basic inputs, one from the chords and the other from the strings. Our code which stimulates the sound of the guitar also makes use of these three inputs. The selection of the chords is done through the changing resistance of variable resistors while the strumming input is taken in the form of the wave. Instead of mechanically producing the strumming effect model, we have tried to implement a saperate code that stimulates the strumming of a guitar and as a result we get a wave form corresponding to the pluck.

13

When a guitar string is strummed the time response can be plotted as

Fig-4.1: Time response of a guitar strum

The frequency response of a guitar is

Fig-4.2: Frequency Response of a guitar strum

The sound output of musical instruments does not immediately build up to its full intensity nor does the sound fall to zero intensity instantaneously. It takes a certain amount of time for the sound to

14

build up in intensity and a certain amount of time for the sound to die away. The period of time during which a musical tone is building up to some amplitude (volume) is called the attack time and the time required for the tones intensity to partially die away is called its decay time. The time for final attenuation is called the release time. Many instruments allow the user to hold the tone for a period of time which is known as the sustain time so that various note durations can be achieved. The amplitude of the tone can fit inside a curve often called the Attack-Decay-Sustain-Release (ADSR) envelope. [5]

A classic ADSR envelope is given as

Fig-4.3: A classic ADSR envelope

15

Typical ADSR envelope for a guitar is shown below

Fig-4.4: A typical ADSR envelope for a guitar

Computer Music in Undergraduate Digital Signal Processing,Phillip L. De Leon,New Mexico State University,Klipsch School of Electrical and Computer Engineering. The idea has been implemented at the Miami University under the Musical Instruments Properties Project. In this project, each music sample was recorded at CD quality (44.1/16) and saved as a .wav file. Each sample includes its ADSR envelope and is about three seconds long. The FFT analysis was done on a 25ms frame (rectangular window) in the sustain part of the sample Using Matlab, we can analyze simple properties of common musical instruments.. The FFT results were converted into Power Spectral Density and plotted. The full sample was analyzed with a spectrogram analysis, after being decimated by a factor of 3 to improve the results (not much energy exists above 8kHz anyway). Each plot includes the full time waveform, spectrogram result, time plot of the 25ms frame, and PSD result. [3]

16

The results obtained for a guitar strum are as follows

Fig-4.5: Time and Frequency response of a guitar strum using the Musical Instruments Properties Project [6]

In our hardware we have made use of the signal generator. Although our code is capable of detecting different strumming effects and produce corresponding sounds but to simplify our design and for checking purposes we have input a sine wave corresponding to repeatedly strumming a single string to the microcontroller. The MATLAB results show that continuous strumming of a guitar string
17

can be approximated by a very slow decaying sine wave. In our hardware we have approximated the strumming by a sine wave of varying frequencies, supplied to the ADC pin 0 of the microcontroller through a simple protective circuit, consisting of diodes, to ensure the voltage does not exceed the required levels.

4.3

CODING

The code implements the Karplus Strong algorithm to produce the sound of plucked string. There is a different frequency associated with each of the 6 strings in different frets. In our coding we have taken up to 12 frets. Apart from that, the code also keeps on polling ADC after every 10msec to obtain an output. The code includes both up strumming and down strumming. The only difference between the two is that in up strumming High E is played first and in down strumming Low E is played first.

KARPLUS STRONG THEOREM Karplus-Strong string synthesis is a method of physical modeling synthesis that loops a short waveform through a filtered delay line to simulate the sound of a hammered or plucked string or some types of percussion. Although it is useful to view this as a subtractive synthesis technique based on a feedback loop similar to that of a comb filter for z-transform analysis, it is better viewed as the simplest of a class of wavetable-modification algorithms now known as digital waveguide synthesis, as the delay line acts to store one period of the signal. In fact, the algorithm is easy on the processor and produce rich sounds. The use of noise as input reduces the synthetic effect that characterizes most computer sounds. On the other side, the way the loop creates the periodicity and operates the decay preserve the timbre

18

characteristics that permits to identify the sound as coming from a unique instrument.

WAVETABLE SYNTHESIS The original Karplus-Strong algorithm is based on wavetable synthesis. In wavetable synthesis, a buffer is filled with samples that are then read by a pointer that circulate from the beginning of the table to the end and back to the beginning, thus creating a periodic sound. The wavetable can be filled with any kind of wave. Triangular, sinusoidal and square wave are normally used but even a random signal like noise will sound periodic. The initial conditions of the wavetable determine the resulting timbre and its length determines the periodicity (i.e. the pitch) of the sound.

Fig-4.6: Wavetable synthesis

Wavetable synthesis is very simple but unfortunately also very dull because the sound doesn't present any variation over time. Traditional instruments, on the other side, create sounds that vary a lot. Most synthesis techniques remedy to this situation by modifying the sound after it is read from the wavetable. The Karplus-Strong algorithm differs from those techniques by the fact that it directly modifies the wavetable at each of its iteration. The wavetable in the Karplus-Strong algorithm can therefore be seen as a delay-line. [7]

PLUCKED-STRING ALGORITHM

19

In the Karplus-Strong algorithm, the pluck, which in real string can contain energy at any frequency, is simulate by filling the delay-line with noise at each note beginning. Originally, Karplus and Strong used two-level randomness with probability of 1/2 for -A and A, where A represents the maximum desired amplitude. This is more economic than using uniform randomness between -A and A with the only difference that the signal is 5 dB louder. On today computers, generation of random numbers is not an issue and therefore uniform randomness can be use without any speed consequence.

Fig-4.7: (a) Attack, (b) Sustain and (c) Release Wave Shape of a Real Pluck String [8]

In a real string, vibration eliminates those frequencies introduce by the pluck that don't match the normal modes of the string. Friction and losses at end point will create the sound decay, with higher frequencies decaying faster than lower ones. At the end, the wave shape will almost be sinusoidal with a period corresponding to the fundamental mode of the string. The sound will finally decay to silence. In the Karplus-Strong model this can be achieve by the introduction of an averager in the loop.

20

Fig-4.8: Original Karplus-Strong Algorithm [4]

Alex Strong device his averager by simply adding the two last outputs and right shifting the result (divide by 2). The so create sample is then re-introduce in the loop. This and the length of the loop will cause self-cancellation of the "non-harmonic" partials. This will also cause higher frequencies to decay more and more at each delay-line trip, until only the fundamental remain. Like in the case of a real string, the delay-line content will finally decay to a constant value, which sounds like silence.

Fig-4.9: (a) Attack, (b) Sustain and (c) Release Wave Shape of a Pluck String Create with The Karplus-Strong Algorithm

21

The averager is in fact equivalent to a low-pass filter with the following impulse response: ( ) ( ) ( )

And transfer function: ( )

It can be shown that this filter as a frequency response corresponding to the first quadrant of a cosine wave (i.e. a gentle drop off from unity to the Nyquist frequency) and a linear phase delay of 1/2. | ( )| ( )

Where sr stands for sampling rate

[ (

)] Where

22

Fig-4.10: (a) Low-Pass Filter Magnitude Response, (b) Low-Pass Filter Phase Delay

This implies that the frequency corresponding to the system is now:

Where d is the delay-line length [8]

PROBLEMS [5] Quantization of the Representation of the Frequencies One of the major problems of this model is that the delay-line length needs to be of an integer size. This limitation has for effect the quantization of the frequencies that can be precisely reproduced. As figure 6 illustrates, the effect is small for low frequencies (long delayline) but can be major for higher frequencies where the difference between sr / (d + 1/2) and sr / (d + 1 + 1/2) is huge. Precise tuning is therefore impossible without a way to achieve fractional delay length.

23

Fig.-4.11: Desired Pitch Versus Resulting Pitch for a 44100 Hz Sampling Rate

Difference in the Decay rate of Low and High Frequency Another problem, this time cause by the low-pass filter is the difference between the decay of low and high pitch. This difference exists in real string too but is much less severe. In the Karplus-Strong algorithm as in real string, higher frequencies decay faster than lower one and higher partials also decay faster than lower one. This feature is desirable for the sound to decay from a noisy attack with energy at any frequency to a sinusoidal wave representing the fundamental only and finally to silence. The problem is to control this decay rate so to obtain note of desire duration. This can be done by modifying the low-pass filter. Karplus and Strong suggest a way to do that but Jaffe and Smith solution is more interesting for modern computer. Their solution will be presented in the next section.

24

Fig-4.12: Waves Created by the Karplus-Strong Algorithm for a (a) Low Frequency (100 Hz), and for a (b) High Frequency (1260 Hz) at a Sampling Rate of 44100 Hz

Variation of the Amplitude is Perceived like a Variation in the Distance of the Sound Another problem is in the control of the amplitude. In Karplus-Strong model this is done limiting the range of the random numbers between -A and A where A represent the maximum amplitude. In a real string, the pluck force not only varies the amplitude but also the energy of the higher frequency content. A hard pluck will create a sound with more energy in the higher frequency range than a soft pluck. Varying the amplitude only, create an effect closer to a variation of the source location than that of a variation in the plucking force.

JAFFE AND SMITH EXTENSIONS: [4] Karplus and Strong suggested two solutions for the lengthening of the decay time. One is called the "harmonic trick" and the other one is call "multiplicative decay stretching". The first idea is really simple and
25

involves the delay-line. The idea is to use longer delay-line with multiple copies of the input wave. A delay-line containing two identical copies of a waveform will sound an octave higher than the period represent by its length but will last twice the duration of the original delay-line. The lengthening of the decay create by using n copies of a wave is always proportional to n times the decay rate of one copy of the original wave. The method is really simple but does not provide precise control on the note duration since the possible durations are only multiples of the original decay rate. The second method involves the averager function. The idea is to slow down the decay rate by introducing a probability that one sample is reintroduced untouched in the delay-line. This can be done by replacing the averager equation by the following:

WORKING AND TUNING

Fig-4.13: Jaffe and Smith Extension

26

Working A short excitation waveform (of length L samples) is generated. In the original algorithm, this was a burst of white noise, but it can also include any wideband signal, such as a rapid sine wave chirp or frequency sweep, or a single cycle of a saw tooth wave or square wave. This excitation is output and simultaneously fed back into a delay line L samples long. The output of the delay line is fed through a filter. The gain of the filter must be less than 1 at all frequencies, and the filter is usually a first-order low pass filter (as pictured). In the original algorithm, the filter consisted of averaging two adjacent samples, a particularly cheap filter that can be done without a multiplier (just shift and add operations). The filtered output is simultaneously mixed back into the output and fed back into the delay line

Tuning The period of the resulting signal is the period of the delay line plus the average group delay of the filter; the fundamental frequency, as usual, is the reciprocal of the period. The required delay D for a given fundamental frequency F1 is therefore calculated according to D = Fs/F1 where Fs is the sampling frequency. The length of any digital delay line is a whole-number multiple of the sampling period. In order to obtain a fractional delay, interpolating filters are used with parameters selected to obtain an appropriate group delay at the fundamental frequency. Either IIR or FIR filters may be used, however FIR have the advantage that transients are suppressed if the fractional delay is changed over time. If the group delay varies too much with frequency, harmonics may be sharpened

27

or flattened relative to the fundamental frequency. The original algorithm used equal weighting on two adjacent samples, as this can be achieved without multiplication hardware, allowing extremely cheap implementations. Z-transform analysis can be used to get the pitches and decay times of the harmonics more precisely. Holding the period (d= length of the delay line) constant produces vibrations similar to those of a string or bell. Increasing the period sharply after the transient input produces drum-like sounds.

EXTENDED KARPLUS STRONG ALGORITHM [6] The Extended Karplus-Strong (EKS) algorithm extends the KS digitar in a number of ways that will be introduced one-by-one. The EKS extensions were motivated by the demands of a musical composition and the interpretation of the KS algorithm as a transfer-function model of a simplified physical string. They illustrate how several small digital filters can achieve various desired musical effects. We will see that the EKS can be regarded as a blend of spectral and physical (transfer-function) modeling techniques.

28

Fig-4.14: Extended Karplus-Strong (EKS) filters [9]

Figure illustrates where the various filters may be located in the patch. The filters in series outside the feedback loop can of course be implemented in any order, and the filters within the feedback loop can be arbitrarily reordered. (The series order of linear, time-invariant filters may matter in fixed-point, but generally not in floating-point)

ALGORITHM IMPLEMENTED IN AIR JAM [4]

Air Jam makes the acoustic sound using the Karplus-Strong algorithm. Math In the Karplus-Strong algorithm, the pluck, which in real string can contain energy at any frequency, is simulated by filling the delay-line with noise at each note beginning. In a real string, vibration eliminates

29

those frequencies introduce by the pluck that don't match the normal modes of the string. Friction and losses at end point will create the sound decay, with higher frequencies decaying faster than lower ones. At the end, the wave shape will almost be sinusoidal with a period corresponding to the fundamental mode of the string. The sound will finally decay to silence.

To make the algorithm extremely efficient 6 vectors of different length each representing the maximum length of the delay line for each string are used. To avoid shifting, two pointers are update for each vector to keep track of the elements of interest. To avoid multiplies, an extremely simple low pass filter is used which is simply an averager that averages adjacent elements within the delay line. The delay length is calculated which corresponds to desired frequencies of each note playable on an acoustic guitar and this information is stored in 6 length 12 vectors which correspond to 6 strings and 12 frets (higher frets are ignored for conciseness). To play a note or make a chord delay lengths are looked up within these vectors. This makes encoding the chords extremely simple and intuitive as most guitar tabs available online are in terms of strings and frets. In the Karplus-Strong model this can be achieve by the introduction of an averager in the loop. Alex Strong device filters by simply adding the two last outputs and right shifting the result (divide by 2). The so created sample is then re-introduce in the loop. This and the length of the loop will cause self-cancellation of the "non-harmonic" partials. This will also cause higher frequencies to decay more and more at each delay-line trip, until only the fundamental remain. Like in the case of a real string, the delay-line content will finally decay to a constant value, which sounds like silence.

30

The period of the resulting signal is the period of the delay line plus the average group delay of the filter; the fundamental frequency, as usual, is the reciprocal of the period. The required delay D for a given fundamental frequency F1 is therefore calculated according to D = Fs / F1 where Fs is the sampling frequency. One of the major problems of this model is that the delay-line length needs to be of an integer size. This limitation has for effect the quantization of the frequencies that can be precisely reproduced. The effect is small for low frequencies (long delay-line) but can be major for higher frequencies where the difference between sr / (d + 1/2) and sr / (d + 1 + 1/2) is huge.

CODE

1 Constants defining timer counts, sampling frequencies and delays are initialized. 2 Variables defining the delay between strings and array vectors corresponding to frequency for each strings are initialized. 3 Counter variable is used for the initial noise burst used in K-S. Str[13] is for delay length lookup tables for six strings for up to 12th fret including open string. 4 Chords and burst for Karplus Strong are initialized, we can have upto 32 chords with 6 chars within each chord. 5 The maximum delay length for each string is different, corresponding to the natural frequency of each string. We initialize different vector lengths to conserve memory. Delay[] represents the DelayLine for each string.

31

6 Out, in and mute are defined. Output defines what needs to be outputted. 0 = no output, 1 = burst of "noise", 2 = no noise. 7 adcout,play are for loop counter and ADC output variables. Waittime is the time to wait before checking an ADC for output, incremented by 2. 8 Count, time, count2, count3, time2, time3 are used to handle timing. 9 When timer 2 overflows then get value from data register of ADC. Sampling is done with timer 2 overflows. 10 If count==0 then count=countMAX corresponding to 0.2

seconds, count2==0 then count2=count2MAX corresponding to 1 ms and if count3==0 then count3=count3MAX corresponding to sampling frequency of strumming. 11 If play and waittime both ==0 then adcout=ADCH which is the high byte of ADC data register. For normal ADC operation there is reference voltage needed Vref and clock signal Fadc. Fadc is selected from ADCSRA register. Converted signal is stored in register pair ADCH and ADCL. 12 If adcout > 110 then play=adcout, else if adcout=0 then ADSCR.6=1 i.e. 6th bit (ADSC) in ADSCR register is set to 1 to start sampling the ADC. 13 If we want to output a sound and it is a down strum then first of all Karplus Strong algorithm is implemented. For each string we first see if it is time to play the string (since this is a down strum LE is always played). When time2 is greater than a string's delay time. We start the synthesis.

32

14 The indices 'out' and 'in' are used to avoid shifting of whole delay vector. For the initial input a burst of noise, we add the noise and the average value of the last two values within the delay vector and then put this value at the beginning of the delay line. 15 Once the burst is gone we simply average the last two values of the delay line and place this value at the beginning of the delay line. 16 OUTPUT is used to store the frequencies to be played for each string. This method is used to detect and update values of each string. 17 In up strum we again follow the same procedure as in down strum except that in up strum high E is played first. 18 To more closely model strumming done on a real guitar. The higher strings are supposed to be quieter than the lower strings because musicians usually strum the top strings harder than the bottom ones. This is done by shifting the outputs for both up strum and down strum. 19 Mute strings are implemented which have zero output. 20 We add one more waveform to the output every strDelay length of time .OCR0 is the timer/counter compare register used. strDelay is the delay time between each string 21 Initialize lookup tables for DelayLine lengths that correspond to the frequency of every note playable on an acoustic guitar for the first 12 frets.

33

22 Similarly for each string, a 12 element vector is initialized. The frequency of the delay controls the frequency of the plucked string with a simple formula. Delay Length L = Fsample/Fout. T2 overflow rate is the sampling rate. 23 All of the 32 chords are initialized using the delay lengths of strings in each fret. 24 We initialize delay time between each string (string delay times). 25 Check input from PIN0 of ADC every 10ms. 26 Shift the input and determine which strings to mute. 27 Display chord on port D and check if chords are valid, if not play open strings 28 If chords are valid then update chords' vector accordingly using the input. DelayLengths are updated according to the chords 29 Check if ready to play. if yes update timer, upstrum=1, play is reset, input from acc is debounced and initiate burst 30 Check for each string whether it is strummed or muted or not played 31 Turn output ON

34

CHAPTER 5

OPERATION OF THE SYSTEM

The operation of the overall system is very simple.

Fig-5.1: Block diagram

First step in the operation is to adjust the resistance of the 5 variable resistors to choose a chord according to the lookup table. The operational amplifiers will then take the voltage above or below 3.3V according to the combination of the chord we chose. This action corresponds to pressing the fingers on the strings in different frets to play a chord in a real guitar. After this we provide a voltage waveform corresponding to the strumming, the varying voltage waveform should have an analog

35

value between 0 to 3V. This procedure corresponds to the action of strumming the guitar strings by pick in the real guitar. The code is responsible for implementing the Karplus Strong theorem which produces the string sound according to the chord chosen. It also checks the ADC of the microcontroller after every 10ms for outputs. The code is essentially responsible for producing the required output

36

CHAPTER 6

RESULTS

The idea behind Air Jam is essentially to air guitar with minimum electronics and deliver a realistic sound. But due to time and monitory constraint, we dedicated most of our energy to figure out different ways to simulate the strumming of a guitar. The sound may not be ideal but we still have managed to get close to our desired objective.

Strings & frets Open Low E Low E 1 Low E 2 Low E 3 Low E 4 Low E 5 & Open A Low E 6 & A 1 Low E 7 & A 2 Low E 8 & A 3

Theoretical Frequency 82.41 Hz 87.31 Hz 92.50 Hz 98.00 Hz 103.83 Hz 110.00 Hz 116.54 Hz 123.47 Hz 130.82 Hz

Exact synthesized frequency 83.111 Hz 87.781 Hz 93.001 Hz 98.892 Hz 104.167 Hz 110.035 Hz 116.604 Hz 124.008 Hz 132.415 Hz

37

Low E 9 & A 4

138.59 Hz

139.509 Hz 147.405 Hz 156.250 H 166.223 Hz 177.557 Hz 186.012 Hz 200.321 Hz 211.149 Hz 223.214 Hz 236.742 Hz 252.016 Hz 269.340 Hz 279.018 Hz 300.481 Hz 312.500 Hz 339.674 Hz 355.114 Hz 372.024 Hz 411.194 Hz

Low E 10 & A 5 & Open 146.83 Hz D Low E 11 & A 6 & D 1 Low E 12 & A 7 & D 2 A8&D3 A9&D4 A 10 & D 5 & Open G A 11 & D 6 & G 1 A 12 & D 7 & G 2 D8&G3 D 9 & G 4 & Open B D 10 & G 5 & B 1 D 11 & G 6 & B 2 D 12 & G 7 & B 3 G8&B4 155.56 Hz 164.81 Hz 174.61 Hz 185.00 Hz 196.00 Hz 207.65 Hz 220.00 Hz 233.88 Hz 246.94 Hz 261.63 Hz 277.18 Hz 293.66 Hz 311.13 Hz

G 9 & B 5 & Open High E 329.63 Hz G 10 & B 6 & High E 1 G 11 & B 7 & High E 2 G 12 & B 8 & High E 3 349.23 Hz 369.99 Hz 392.00 Hz

38

B 9 & High E 4 B 10 & High E 5 B 11 & High E 6 B 12 & High E 7 High E 8 High E 9 High E 10 High E 11 High E 12

415.30 Hz 440.00 Hz 466.16 Hz 493.88 Hz 523.25 Hz 554.36 Hz 587.32 Hz 622.26 Hz 659.26 Hz

434.028 Hz 459.559 Hz 488.281 Hz 520.833 Hz 558.036 Hz 558.036 Hz 600.962 Hz 651.042 Hz 710.227 Hz

Table-5.1: Theoretical and air jam frequencies [4]

39

REFERENCES:
[1] http://dustinsmusic.com/guitarlesson1.aspx

[2] http://en.wikipedia.org/wiki/Guitar [3] http://en.wikipedia.org/wiki/Resistor [4] http://courses.cit.cornell.edu/ee476/FinalProjects/s2007/apb36_yn47/ECE_476 _Website.html [5] Phillip L. De Leon, Computer Music in Undergraduate Digital Signal Processing, New Mexico State University, Klipsch School of Electrical and Computer Engineering [6] http://chronos.ece.miami.edu/~dasp/samples/samples.html [7] http://en.wikipedia.org/wiki/Karplus-Strong_string_synthesis [8] http://www.music.mcgill.ca/~amburns/physique/basic.html [9] http://www.dsprelated.com/dspbooks/pasp/Extended_Karplus_Strong_Algorith m_I.html

40

You might also like