DIGITAL GUITAR AUTO-TUNER PROJECT

J

Jerry Avins

Jan 1, 1970
0
Daniel said:
["Followup-To:" header set to sci.electronics.design.]
On 23 Apr 2005 01:11:51 -0700,
in Msg. said:
its actually a qualifying sample project for my first job. actually, i
was just tasked to study the assembly programming and hardware design
and be able to produce a working model for me to qualify for the job.


Well, maybe "Go out and buy one for $20 at a store" is still the answer.
Knowing what's already on the market (especially in unrelated fields) is
probably just as important as knowing how to design something.

--D.

You can's emphasize that too strongly. When my job was designing special
laboratory equipment (from satellite echo simulators to diffusion
furnaces with 1C repeatability at 1800C) the very best way I could serve
a client was showing him a page in a catalog.

Jerry
 
J

Jerry Avins

Jan 1, 1970
0
dhaevhid wrote:

...
it must be capable of tuning both electric and acoustic guitar.

If it's any good, you can also use it to tune an oboe.
im finished with the signal conditioning part of the hardware. i used
an op amp to have a 2volts squarewave that will be the input signal of
the microcontroller. i will be using the eFH5830 mcu buy EMC.(elan
microelectronics) the mcu is 8-bit RISC type, 3.582Mhz. im aiming for
about +/-2 hz accuracy. with the fastest possible response time...

im thinking about zero crossing detection but the guitar signal is
consists of the fundamental and higher harmonics maybe up to 4 or 5
harmonics... and these harmonics cause erroneous zero crossings...

Think again. Once you have a squarewave, the time between successive
zero crossings in the same direction is the period.

...

Jerry
 
M

Mark

Jan 1, 1970
0
this is interesting..

I look forward to the next opportunity I have to connect an
oscilloscope to a bass (guitar) or a mic'ed piano to observe this
phenomenon in the form of the beat note of the off frequency overtone
to the fundamental.

thanks

Mark
 
J

Jerry Avins

Jan 1, 1970
0
Ville Voipio wrote:

...
Nononononnononoooooo! If you tune it to the "even-tempered" scale,
the result is very bad-tempered. All the fifths are bad, all the
thirds are bad.

Ah, come now! Even in the best of guitars, the frets are located by "the
rule of nineteen". Pianos and fretted instruments have tuning
similarities (although you can't "bend" a piano).
And here we come to the point where a custom-made tuning tool would
be useful. It is quite easy to go and buy a simple one which just
shows the pitch on a scale. However, I'd like to have one which
can be taught different temperaments.

There are some such instruments available, but they tend to be
rather bulky, eat up a lot of batteries, and cost a lot. On the
other hand, it should not be difficult to use different tempera-
ments once a reliable frequency meter has been made.

---

There are a few challenges which have to be addressed. Here is my
list:

- accuracy down to 1 cent (1/100 of a half note, around 0.6 permille
of the frequency, i.e. 0.24 Hz @ 415 Hz)

- fast response (preferably in the 100s of milliseconds), because
slow response makes it difficult to tune plucked instruments
(rapidly changing pitch)

- freely adjustable a', at least from 390 Hz to 465 Hz

- custom temperations

- good response over four octaves (lowest string of a violone is
at around 35 Hz, the highest string of a violin at 625 Hz)

I know this is not a trivial problem. Using FFT might be a solution.
On the other hand, a sliding sampling window or some other trickery
should be used, and there might be some better algorithms. In
any case the first problem is to have a coarse idea of the basic
tone and get rid of the harmonics. After that some time-domain
algorithms might be good enough.

The good thing is that the relative accuracy requirement (1 cent)
can be relaxed a lot in the low frequencies.

If someone comes up with a robust, fast, and relatively simple
algorithm, that would be nice. Even nicer if the algorithm is
simple enough to be realized with a few hundred kIPS, but OTOH
MIPS are not so expensive after all.

- Ville (viola da gamba player)

<aside> Do you know Roland Hutchinson? (He was quite taken with the
selectable temperaments on my recently acquired Yamaha "piano".)

Jerry
 
B

Bob Stephens

Jan 1, 1970
0
A typical overtone series might be:

1.000 (fundamental)
2.003 (second partial)
3.008 (third partial)
4.015 (fourth partial)
5.024 (fifth partial)
6.035 (sixth partial)
...etc.

I'll bet this varies according to the type of string also. i.e. The lower
wound strings will have different harmonic properites than the upper 'piano
wire' strings.


Bob
 
J

Jerry Avins

Jan 1, 1970
0
Daniel said:
... When I read the article I regretted that my hearing was perfect.

--Daniel

Poor you! My hearing is perfectly flexible.

Jerry
 
J

John Woodgate

Jan 1, 1970
0
(in said:
this is interesting..

I look forward to the next opportunity I have to connect an
oscilloscope to a bass (guitar) or a mic'ed piano to observe this
phenomenon in the form of the beat note of the off frequency overtone
to the fundamental.
I don't think you will see it: the enharmonic amplitude is too small and
they run through at different rates. Maybe if you use bass cut to reduce
the fundamental it will be visible.
 
J

John Woodgate

Jan 1, 1970
0
He was quite taken with the selectable temperaments on my recently
acquired Yamaha "piano".

Can this feature be retrofitted to s.e.d contributors?
 
J

Jerry Avins

Jan 1, 1970
0
Robert said:
This phenomenon has been well-studied for pianos where precise tuning
is much more important. It is called "inharmonicity", and it is due
to the stiffness of the strings. The overtones are theoretically pure
harmonics only for an infinitely thin string with zero stiffness,
where the restoring force is totally due to the tension in the string.
When part of the restoring is force is due to stiffness in addition to
tension, then higher overtones will be higher in pitch than pure
multiples because higher overtones involve more bending than lower
overtones. A typical overtone series might be:

1.000 (fundamental)
2.003 (second partial)
3.008 (third partial)
4.015 (fourth partial)
5.024 (fifth partial)
6.035 (sixth partial)
...etc.

The effect may be less on guitars than on pianos because the length to
thickness ratio is not as bad on a guitar. But it is still enough of
an effect to be considered in the design of a tuner.

I know that you are right, but it puzzles me. It seems to me that the
common bridge should enforce harmonicity, just as it locks together the
slightly detuned piano doubles and triplets. (Exact tuning makes the
note loud ans it's decay rapid. Slight detuning softens the attack,
hoarding energy for better sustain. The same is true of a 12-string guitar.)

It is a real challenge to build 5.0000 and 5.0001 MHz oscillators on the
same chassis, even with crystals, that will actually beat. The
evaporation thickness/rate monitor I wrote of in another thread worked
around that problem.

Jerry
 
J

Jerry Avins

Jan 1, 1970
0
dhaevhid said:
i guess i have to correct myself for few mistakes;

1. for the accuracy, that will be +/-2cents maximum. +/-1cent
must be nice.. not +/-2hz.
2. for the harmonics, im wrong about the 12th root of two, that
is the even tempered scale. the other components found in the guitar
signal are supposed to be the harmonics factor of 2, 4, 6, 8 belongs
to the higher octaves.

here comes another newbie question:

does anyone have an exact idea how to safely "count" the
fundamental freq with all of these harmonics on the considerations?

Marching harmonics are not likely to affect any one period by more than
ten percent. If you count the total time for 100 periods, the accuracy
becomes one part per thousand. To that, you must add the uncertainty of
your time measurement, up to perhaps two ticks on the counter.

In a way analogous to a bell's "clang tone", the harmonic structure
changes rapidly when the string is first plucked. Don't measure the
first part of the note, and don't try for such a long measurement that
the note fades away.

Jerry
 
R

Robert Scott

Jan 1, 1970
0
I know that you are right, but it puzzles me. It seems to me that the
common bridge should enforce harmonicity, just as it locks together the
slightly detuned piano doubles and triplets. (Exact tuning makes the
note loud ans it's decay rapid. Slight detuning softens the attack,
hoarding energy for better sustain. The same is true of a 12-string guitar.)

It is a real challenge to build 5.0000 and 5.0001 MHz oscillators on the
same chassis, even with crystals, that will actually beat. The
evaporation thickness/rate monitor I wrote of in another thread worked
around that problem.

Yes, there is in fact a "lock-in" phenomenon that happens through the
interaction at the bridge. But typical amounts of inharmonicity, at
least in piano strings, exceeds the lock-in range. Inharmonicity is
easily measured by precisely measuring the pitch of individual
overtones and comparing them. Another way to verify inharmonicity is
to observe the signal on a scope. If the overtones were all locked to
the fundamental, the overall shape of the signal would be constant,
just decaying in amplitude. Perhaps the individual overtones would
decay at different rates. But it would be quite clear that the
overtones are frequency locked. But that is not in fact what you will
observe. If the scope is triggered by the fundamental, then the
overtones will appear as higher-frequency components that are "riding
to the left" as compared to the fundamental.


-Robert Scott
Ypsilanti, Michigan
 
G

Guillaume

Jan 1, 1970
0
Ronald said:
Incorrect. For single pitch detection, one can use as many points as
the signal-to-noise ratio will allow.

You are incorrect, because you didn't think of the real-world problem
here.

You can't use as many points as you want, for two reasons: the guitar
string signal doesn't last forever, and as I said, it evolves in various
"nasty" (well, to the engineer) ways while it lasts.

To increase resolution, you have to increase the number of points, hence
the duration of the take. As I just said, this is not a real option.
Besides, even if the played open string lasted long enough (which is not
that obvious), the longer the time it takes for your tuner to give you
the pitch, the more useless your tuner is (just try to tune a guitar
with a tuner that needs 5 seconds to give you the current pitch, good
luck).

Padding with zeros to artificially increase the number of points without
having to analyze a longer take will quickly prove not very useful
either in this particular application because of all the transients.

But don't take my word for it. Just do it. I did and I claim it's
not the way to go. You'll see.
If you can come up with a usable and accurate guitar tuner using an
FFT only, please show us. I'll be glad to hear from it.
Meanwhile, no commercial tuner that I know of uses an FFT.
 
G

Guillaume

Jan 1, 1970
0
Hans-Bernhard Broeker said:
If indeed the FFT's resolution is poor, that can have two reasons:

1) the FFT was done badly, or on insufficient input

Done badly? I'm talking about the obvious FFT resolution, which
is the sample frequency divided by the number of points.
So yes, it could be (and is) insufficient signal length.
But more length means longer time to get a result, and as I said
in my other reply, the tuner becomes unusable. Besides, as the time
goes by, the guitar string signal changes a lot and you won't get
a lot of useful information out of the FFT.
2) the uncertainty principle on waves applies

If a correctly done FT fails to deliver the necessary frequency
resolution on the given data, then no other technique is going to
work.

This is extremely wrong.
First, a Fourier analysis doesn't deal well at all with transients
as it is meant to analyze periodic signals. A guitar sound is nothing
but periodic when you look at it. It might "sound" so, but it isn't.

Wavelets could be a way of better dealing with this.

But as I said to the other person, don't take my word for it.
If you think an FFT will do the job, please be my guest.

Pitch analysis is most often based on autocorrelation techniques.
Search the web, you'll find plenty of research articles on the
subject.
 
J

John Woodgate

Jan 1, 1970
0
I read in sci.electronics.design that Guillaume <"grsNOSPAM at
NOTTHATmail dot com"@?.?.invalid> wrote (in
Meanwhile, no commercial tuner that I know of uses an FFT.

How do they work, then? (The answer 'Very well' is not acceptable.)
 
B

Ben Bradley

Jan 1, 1970
0
In
sci.electronics.design,sci.electronics.misc,comp.dsp,comp.arch.embedded,
The trouble with phase detectors in the presence of noise is that they
only work if you are close. The indication for "way off" is useless.
It is like using a strobe. The pattern is clear only if the pitch is
within a certain range.

This is where multiple methods come in handy. A low-pass filter and
zero-cross detection gets you in the ballpark, then your method (looks
like a PLL using a phase-accummulator DCO) gets good accuracy.

For a look at the competition (well not quite, you need a PC to run
it on), here's a good tuner program with everything:
http://www.jhc-software.com/gtune.htm
 
J

Jon Harris

Jan 1, 1970
0
Jerry Avins said:
Ville Voipio wrote:



Ah, come now! Even in the best of guitars, the frets are located by "the
rule of nineteen". Pianos and fretted instruments have tuning
similarities (although you can't "bend" a piano).

At times I've experimented with "open" tuning on my acoustic guitar, such as
tuning the strings to form an E major chord. In that context, I can tune it to
"just intonation" so the third is low, the fifths a bit high, etc.. Unfretted,
it sounds brilliant! However, if I fret some of the strings to play a different
chord where, for example, a string that was the third now becomes the fifth, it
is horribly out of tune! So while for strumming a single chord, just intonation
is great, I have to use a compromise closer to equal-temperament if I want to
actually play a song.
 
A

Al Clark

Jan 1, 1970
0
[email protected] (Robert Scott) wrote in @news.provide.net:
This phenomenon has been well-studied for pianos where precise tuning
is much more important. It is called "inharmonicity", and it is due
to the stiffness of the strings. The overtones are theoretically pure
harmonics only for an infinitely thin string with zero stiffness,
where the restoring force is totally due to the tension in the string.
When part of the restoring is force is due to stiffness in addition to
tension, then higher overtones will be higher in pitch than pure
multiples because higher overtones involve more bending than lower
overtones. A typical overtone series might be:

1.000 (fundamental)
2.003 (second partial)
3.008 (third partial)
4.015 (fourth partial)
5.024 (fifth partial)
6.035 (sixth partial)
...etc.

The effect may be less on guitars than on pianos because the length to
thickness ratio is not as bad on a guitar. But it is still enough of
an effect to be considered in the design of a tuner.


-Robert Scott
Ypsilanti, Michigan

I observed this many years ago using an FFT analyzer. As I recall (25
years ago),I also noticed that the G string on my guitar was actually
vibrating at two different frequencies that straddled the desired center.
I think this is why I never think that a B created at the 4th fret of the
G string ever sounds perfectly in tune with the B string. I attributed
this to the fact that the G is a wirewound string and therefore has
significant thickness.

As was mentioned earlier, the choice of temperment is always a
compromise. The frets contribute to temperment as well, I wonder what the
best compromise tuning is for a guitar given all the various parameters.

You might start with the fact that a guitar is usually tuned E A D G B E.

I suppose a smart tuner could have open tuning capabity as well. Open
tunings might be easier to consider if you want fifths and thirds etc to
be perfect (1.5 vs 1.4983 & 1.25 vs 1.25992)

Piano tuners fight the temperment issue all the time. If I have a piano
tuner come out and tune my piano to even temperment (unfortunately, the
typical situation), I hate the sound. I used to have a guy who tuned most
of the pianos for the recording studios in my area tune my piano. When he
did the tuning, my piano sung!

Too bad I can't actually play very well.....

Unfortunately (fortunuately) I have a pretty good sense of pitch.
 
R

Rich The Newsgroup Wacko

Jan 1, 1970
0
Why do you think he's a "Wacko"? He thinks he's funny, but...

Somebody called me that once, and I thought it was rather cute, so
started using it, for the times that I'm consciously being a wacko. :)

As to who's the asshole, ISTR responding to a "please do this for me"
type of post, and I made a casual offer to do the work, for a price.
Lessee...

Oh, yeah. Here it is:
----excerpt----
From: [email protected] (dhaevhid)
...
its actually a qualifying sample project for my first job.
...
im tryin to do it all by myself but its taking me so long to understand
the concepts...
----end excerpt---

So, in other words, you're not qualified for the job, so you want
us to help you cheat your way in. _That's_ what the asshole part
was for.
--
Cheers!
Rich
------
"There was an old man of Tagore
Whose tool was a yard long or more,
So he wore the damn thing
In a surgical sling
To keep it from wiping the floor."
 
G

Guillaume

Jan 1, 1970
0
John said:
How do they work, then? (The answer 'Very well' is not acceptable.)

Most of them use a simple design. You can find one on CircuitCellar,
and that's pretty much how this is done in commercial products.

It consists of an input stage, which is basically a good low-pass filter
filtering everything above the maximum fundamental frequency it's
supposed to deal with (probably something like 1000 or 1500 Hz), usually
a 2nd order active filter. Then it's followed by a comparator set with
some hysteresis, which can also be an amplifier based on some AOP with
a lot of gain - so that the AOP clips the signal, which is easily
transformed into a digital signal with a schmitt trigger, for instance.
This circuit basically extracts the fundamental frequency of the input
signal with a reasonable usability.

Then the comparator's output can be dealt with in various ways.
Some can be rather crude (just measuring the frequency of the resulting
digital signal), some are more clever, and I like the one that's used
in the CircuitCellar project. The comparator's output goes to a digital
I/O pin of a microcontroller, of course set as an input. The algorithm
used consists of measuring the delay between two consecutive raising
edges - but this is not all. To make sure the measure is meaningful,
several consecutive measures are compared, and only if we get a few
(like 10, for instance) consecutive measures that are close enough
to one another, do we consider this is the fundamental frequency.
The latter is computed from the period, using for instance an average of
the 10 given "meaningful" past measures.

By comparing the frequency with a few preset ranges, the tuner can
even guess what the string it is you're trying to tune, and
automatically give you how far away you are from the nominal
frequency for this string.

As to how the above input stage, based on a filter and a saturation
stage, translates in the frequency domain (in other words, how
the spectrum of the original signal is transformed), I'll let you
think about it. It resembles, but is not quite like simply looking
at zero-crossings - because the saturation on the signal actually
tends to "ignore" the harmonics, whereas simple zero-crossing
analysis has to deal with them.

All in all, this is a working approach and it's much simpler than any
sophisticated DSP analysis you might try.
 
Top