The Sound of Music
Hello, and welcome to my web page
for my Elec 301 gang project. The only problem is that I really have
no group!
To remedy this situation I decided
to do the project all by my lonesome. Hope you enjoy!
Group Members: Adan Galvan
Abstract
This website was set up in order to investigate the capabilities of matlab to serve as a tuner. Tuner is meant in the musical sense, a device that aids in making sure an instrument's sound is in tune. My goal is to write a program that will take in a wave file and output a frequency, along with the direction that one must change the pitch of a certain instrument(in my test case a guitar) in order to put it in tune. Also, I plan to implement some filters in the hope that suffiient noise will be removed from the signal as to make the tuner more accurate.
I.Introduction
The first step in creating my tuner
was to take sample from my guitar. I have a digital tuner that will
aid in my project . This tuner will allow me to take precise
sample and save them to a wave file via my home computer microphone.
With these samples I plan to use matlab and take the FFT of
the samples to compare them to a wave that is in tune. I will
then proceed to search for peaks in the FFT of the wave, thus allowing
me to see the difference between the original in tune wave, and that
of the inputed wave.
Following is a couple of the samples that I have taken and displayed using Matlab's wavread command.
In order to allow the reader some familiarity I have included
a short document that
tells the correct pitches for guitar strings in standard
tuning.
Standard concert pitch is defined as the A (or 5th) string being at
exactly
440 Hz.
An octave is given by a doubling of the frequency, i.e. 5th string,
12th fret
would be at 880 Hz.
The frequencies of the notes in between these octaves are regular multiples
of
440. The multiple being 2^(1/12) i.e. two to the power of one
twelfth. Each
multiple raises the pitch of the note by one semitone, so after 12
semitones
(i.e. 12 frets) you have multiplied 440 by 2 hence 880 Hz. and increased
the
note by an octave.
So, assuming I can use my calculator correctly, the pitches of the
open
strings of your guitar in standard tuning should be as follows,
String Number Note Pitch(Hz)
1
E (high) 1318.51
2
B
987.77
3
G
783.99
4
D
587.33
5
A
440.00
6
E (low) 329.63
Basically, the idea is to start with 440Hz and keep multiplying by 2^(1/12)
to
increase a semitone at a time until you get the required note then
just
multiply or divide by 2 to raise or lower the note an octave as required.
II.MATLAB
After using MATLAB's wavread command and plotting the samples, I decided that it was time to begin analyzing the information. Using MATLAB's FFT command, I was able to take the fast fourier transform of the samples that I had taken. Initially, I was baffled with the results. When plotting the results , I was unsure as to what exactly was being portrayed. The graph had an unusual form.
Following is an example of the code I used to find the FFT.
>>a=wavread('a.wav');
>>af=fft(a);
>>plot(af)
This was the result.
After I got these results I realized
that the graph was obviously complex, and that I would have to take
the magnitude of these results. But first I was foing to take smaller
samples and repeat the above experiment.
III.Smaller Samples-A new approach
New Samples
The next step in my research was to take the samples that I had and to make them more compact. There were twp problems with my original approach.
1.The samples I had taken were too
large, and even the FFT in matlab took quite a while to compute.
2. When graphing the FFT, the magnitude
was skewed because my samples included to large a variety of amplitudes.
These two problems gave way for the need for smaller samples.Following is the new samples that I took.
Unfortunately, I was unable to get this sample , but it
looks like this.
The new sample was clearly a better model of the waveform. It was also more compact. Using this sample I was able to proceed on to the next step.
FFT
Now that I had new samples, I was
going to take the FFT's of the samples, and try to analyze that data.
Following is an example of the
MATLAB code I used to compute and graph the FFT of the sampels.
>>a=wavread('NEWA.WAV');
>>ap=fft(a);
>>plot(fftshift(abs(ap)))
And here is the result.
Interpreting the data
Interpreting the data was very difficult at this point. I was unsure of exactly how to compute the frequency of the resulting FFT. I had the sampling rate, but was still unsure of how to go about computing the approximate frequency. I believed that by plotting the FFT, I would be able to locate peaks, and form these peaks I would find the relative frequency. Unfortunately, this was not the case.
Following is a zoom of the FFT of the waveform.
From this picture I believe that it is feasible to say that the 440hz frequency that I was looking for was the peak on the right hand side. Alternatively, I believe that the peak on the left was the -440hz frequency.
In order to provide some point of comparsion, I have also inluded:
1. Sample of A Flat A
2.FFT of the Flat A
3.Possible peak frequencies of Flat A
With this information I would be
able to compare the FFT of the 'A' sample, and compare that to the 'Flat
A' sample. The next step would be to write a program that compare
the frequency of the Flat A, with that of the A that was in tune.
The program would then proceed to tell the user what direction he must
tune the string of the guitar in order to put the string in tune .
Dead End
At this point I found it difficult to proceed with my previous plans. Without the ability toapproximate the frequency from the FFT of the signals, I would not be able to continue with my plans. At this point I decided to abandon my original plans. The program that I intended to write would not be possible for two reasons.
1.I was unable to approximate a
frequency from the information on the FFT graph.
2. Even if I had been able to approximate
the frequency of the resulting FFT, I lacked the programming skills
to be able to write a program that would take in samples through a microphone,
and compute the calculation in real time. Any program that I would
write would only be able to compare the frequencies of the samples I had
in memory, no real-time data would have been accessible.
I decided that if I would not be
able to proceed with the original plans, then I would find some other way
to approximte frequency and compare to different samples.
IV.Colea
After admitting to my failure, I decided to search the web for some MATLAB software that would help me approximate the frequencies of my samples. After only about half an hour I found Colea. Colea was written by Phillip Loizou at the University of Arkansas at Little Rock. It was intended to be a tool to help in speech analysis. But, with a little modifications that the program allowed, I was able to succesfully compare the signal samples that I had taken.
FFT in Colea
Using Colea, I was able to take my samples, sample them at 44100hz, and analyze the data of any size region I wanted. I finally decided to take a 20ms fragment, and compute a 1024 sampe FFT. Colea also allowed me to use a hamming window, and allowed me to view the FFT as a discrete function.
Following are my results when taking
this FFT on my 440hz sample.
There was clearly a peak at 440
hz. Using this method, I was able to compare two siganls!!
Here is a graph of both of the
FFT's overlaid.
It may seem as if this data
is inconclusive because of all the other peaks. But, by also analyzing
the LPC spectrum of the sample, you are able to see where the energy of
the siganl lies. The LPC spectra of the two signals follow.
V.Conlusions
In conlucion I would like to say that although I was not
able to complete the project as was originally planned, I still was able
to find some conclusive info on the samples. Using Colea I was able to
find peaks that indicated what the frequency of the signal was. I
wish I would have been able to write the program as I originally planned,
but I'll save that for another time. Also, I just wanted to remind
whoever is reading this that I was a one man group, and believe that if
the guys who originally agreed to work with me would have, that much more
work on this tuner could been done. Thanks for your time, and happy
grading!!!!!
This page was last updated on 12/01/99.