Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

Tuning a Piano

Date: 05/28/2002 at 14:14:27
From: Mike Turley
Subject: 3-point quadratic intorpolation

I need help understanding 3-point interpolation. I am a music teacher
who is working on writing a computer program to tune pianos and other
musical instruments. I have three college degrees in music; but
unfortunately 3-point quadratic interpolation was never covered. 

I need to be able to figure the tuning curve on a piano. A piano is
perfectly in tune in the middle range but flat in the lower range and
sharp in the upper range. Each piano has a unique tuning curve that
can be measured and calculated through 3-point quadratic
interpolation. 

I need to be able to come up with a formula that will allow me to
measure three different notes on the piano and find the tuning curve
in between these points. 

Two octaves on a piano are made up of 25 succesive keys numbered from
0-24. I would take the following three measurements: A0, A12, and A24.
The readings would be measured in cents sharp or flat.

Let's suppose A0 was 1.5 cents sharp, A12 was 3 cents sharp, and A24
was 9.5 cents sharp. I need a formula that will tell me the cents of
all the points inbetween. I have read several different web pages on
3-point interpolation and know that this equation is possible, I just
don't understand all of the language that is used (keep in mind that
I'm a musician, not a mathmatician). I need to find someone who can 
help me find this equation.

Sincerely,

Mike Turley


Date: 05/30/2002 at 12:29:18
From: Doctor Douglas
Subject: Re: 3-point quadratic intorpolation

Hi, Mike.

Thanks for submitting your question to the Math Forum.

Let's suppose that the keys are labelled by x and the measurements
are labelled by y.  Thus the first note is x=0 and the last note is 
x=24.  The measurement from the lowest note (x=0) is y=A0, and
the measurement from the highest note (x=24) is y=A24.  Here, x and
y are variables, and A0 and A24 are numbers (which might be 1.5 and
9.5).

Now we want to find a function f such that it takes x to y [i.e.,
f(x) = y], and such that f(0) = A0, f(12) = A12, and f(24) = A24.
Furthermore, we want a function f that is a quadratic polynomial 
[i.e. is of the form f(x) = P*x^2 + Q*x + R for some constants 
P,Q,R].

Without going into all of the details of showing where it might
come from, here is that quadradic function:

         A0 * (x-12)(x-24)   A12 * (x-0)(x-24)   A24 * (x-0)(x-12)
  f(x) = ----------------- + ----------------- + -----------------
           (0-12)(0-24)        (12-0)(12-24)       (24-0)(24-12)

You can simplify the denominators, and if you multiply everything
out, you can get it in the form Px^2 + Qx + R, if you wish.  But
in this form above it's easy to see that this function is quadratic
(since in each term you only get powers of x^2 and x and constants).
Also, it is easy to see that the first term is what gives us A0 
when x=0, because when x=0, the second and third terms vanish by the
(x-0) factor in the numerator, and only the first term remains.  And
it is easy to see that the terms in parentheses cancel each other
when x=0, so that f(0) ends up being equal to A0, as we require.

Note that you can change this expression to handle points other than
at x=0,12, and 24.  Of course, the points where you take measurements
must be different from each other, but they need not be equally
spaced (for example, if a piano has a steep tuning curve at the
bottom but is relatively flat in the upper octave), you might choose
to measure at x=2,x=8, and x=16, and then hope that what happens for
x<2 and x>16 is well-modeled by the quadratic.  There is nothing
special about the numbers 0,12, and 24 in the above example, and 
you can convince yourself that a similar expression with 2,8, and 16
will do exactly the same thing (i.e., will equal A2 at x=2, etc.).

Note also that you can make a polynomial of the next higher order by
making some simple changes.  Suppose you have the quadratic above and
you make one more measurement, where the tuning curve is steep at say
x=7 (let the measurement there be equal to A7).  Then the CUBIC
polynomial that interpolates through all four points (0,A0),(7,A7),
(12,A12),(24,A24) is

         A0(x-7)(x-12)(x-24)   A7(x-0)(x-12)(x-24)  
  f(x) = ------------------- + -------------------
          (0-7)(0-12)(0-24)     (7-0)(7-12)(7-24) 

                A12(x-0)(x-7)(x-24)   A24(x-0)(x-7)(x-12)
              + ------------------- + -------------------
                (12-0)(12-7)(12-24)   (24-0)(24-7)(24-12).

Incidentally, these expressions are known as Lagrange's form
of the interpolating polynomial.  For a small number of data
points it's fine to use these expressions, but as the number of
data points gets large, these expressions become cumbersome, and
errors may arise from numerical inaccuracies when making actual
computations.  These are more advanced topics, of course.

I hope this helps.  

- Doctor Douglas, The Math Forum
  http://mathforum.org/dr.math/ 


Date: 06/08/2002 at 20:56:14
From: Mike Turley
Subject: Thank you (3-point quadratic intorpolation)

Doctor Douglas,

I very much appreciate the time that you took to help me 
understand 3-point interpolation. I have done my best to 
understand your explanation but I'm afraid I need a little 
more help. 

Could you please show me an example or two of how to solve for the
different points of my tuning curve? I will be measuring, for
instance: A0 (1.5 cents #), A12 (3 cents #), and  A24 (9.5 cents #).
Could you please give me an example of how to solve for the other
points of the tuning curve? For instance how would the equation look
to solve for A#1, and then what would I have to do change the 
equation to solve for B2? 

Please understand that I have not had to use much algebra at all in
the last 20 years so I think that to see a more specific example would
help me greatly.

Sincerely,

Mike Turley


Date: 06/09/2002 at 10:31:47
From: Doctor Douglas
Subject: Re: Thank you (3-point quadratic intorpolation)

Hi again, Mike!

Let's suppose, as you said that A0 = 1.5, A12 = 3, and A24 = 9.5.  Now
we need to solve for the interpolated value of A1.  Let's start from
the function that I gave earlier:

         A0 * (x-12)(x-24)   A12 * (x-0)(x-24)   A24 * (x-0)(x-12)
  f(x) = ----------------- + ----------------- + -----------------
           (0-12)(0-24)        (12-0)(12-24)       (24-0)(24-12)

Now we ask, what is f when x=1?  We just plug in the number "1" 
everywhere that x appears, and we plug in the measurements for A0, 
A12 and A24.  So now it's nothing more than pressing the right 
buttons on your calculator:

         A0 * (1-12)(1-24)   A12 * (1-0)(1-24)   A24 * (1-0)(1-12)
  f(1) = ----------------- + ----------------- + -----------------
           (0-12)(0-24)        (12-0)(12-24)       (24-0)(24-12)

          A0 * (-11)(-23)     A12 * (1)(-23)     A24 * (1)(-11)
       = ----------------  +  ---------------- + ---------------
            (-12)(-24)          (12)(-12)           (24)(12)

         253 A0    23 A12   11 A24
       = ------ + ------- - ------
          288       144      288

         253 * 1.5   23 * 3   11 * 9.5
       = --------- + ------ - --------
            288       144       288

       = 1.318 + 0.479 - 0.363

       = 1.434 cents sharp 

To solve for the next note, you simply use x=2.  In other words,
you compute f(x=2).  And for the next note after that, you use x=3 
to compute the polynomial value for A3.  The data points A0, A12, 
and A24 of course don't change.  And if you try checking the notes 
f(x=0), f(x=12), and f(x=24), you will get back A0, A12, and A24
respectively.   The polynomial f passes through those points 
because of the way in which we constructed it.

- Doctor Douglas, The Math Forum
  http://mathforum.org/dr.math/ 
Associated Topics:
College Calculus
High School Calculus

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/