The Mathematics of Tuning Musical Instruments –
a Simple Toolkit for Experiments

Erich Neuwirth

University of Vienna

 

Summary:

This paper gives an overview of the (rather simple) mathematics underlying the theory of tuning musical instruments. Besides demonstrating the fundamental problems and discussing the different solutions (only on an introductory level), we also give Mathematica code that makes it possible to listen to the constructed scales and chords. To really get a “feeling” for the contents of this paper it is very important to hear the tones and intervals that are mentioned. The paper also has the purpose of giving the reader a Mathematica toolkit to experiment with different tunings.

 

More than 250 years ago Johann Sebastian Bach composed “Das wohl temperirte Clavier” (the well tempered piano) to celebrate an achievement combining music, mathematics, and science. Finally, a method of tuning musical instruments had been devised which allowed playing pieces in all 12 major and all 12 minor scales on the same instrument without retuning. Nowadays, we are so used to this fact that we almost lack an understanding for the kind of problems musicians were facing for a few hundred years.

The appendix of this paper contains some Mathematica code. This code allows us to play scales and chords with given frequencies. Using these functions, we will be able to listen to the musical facts we are describing in a mathematical way. (Warning: On slower machines this code may take some time to create the sounds.) The waveform used for this sound is not a sine wave. For musicians, sine waves sound very bad. Therefore, we are using a more complicated waveform, which has been described in [4] and is heavily used in [3]. Our code defines three Mathematica functions, PlayScale, PlayChord, and PlayStereoScale, and we will explain the use of our examples later in the paper. The code will run on any computer with a sound device and a Mathematica version supporting the Play function on this platform. In particular, it will run on PCs with any 32-bit version of Microsoft Windows.

Now let us start historically.

The ancient Greeks, and especially the Pythogoreans, noticed that the length of strings (of equal) tension and the musical intervals they produced showed some interesting relationships. Using more modern knowledge from physics we know that the lengths of strings and the frequencies of the tones are inversely proportional. So in the context of this paper we will study the relation between frequencies, frequency ratios, and musical relationships like consonance.

The first fact we note in this respect is that when we compare two tones and the frequency of the second tone is double the frequency of the first tone, we feel that this is “the same tone on a higher level”. The interval created this way is called an octave, and it seems to be a universal musical constant in the sense that an octave is perceived as a consonance in every musical culture.

To listen to this phenomenon, we can execute the command PlayScale[{220,440},1.5]. To listen to these two tones played as a chord, we execute PlayChord[{220,440},1]. We also can hear that this fact only depends on the ratio and not on the absolute frequencies by playing PlayChord[330*{1,2},1.5] or PlayChord[264*{1,2},1.5].

Since we noticed that doubling the frequency produces something musical, we also might be interested in listening to a sequence of tones consisting of the first few integer multiples of a base frequency, for example the sequence 220, 440, 660, 880, 1100, 1320, 1540, 1760.

In our code, we use PlayScale[220*{1,2,3,4,5,6,7,8},1.5].

Listening to this sequence, between the consecutive tones we hear many intervals, which in Western music are considered to be consonant. In musical terms, we hear 7 intervals, and the first five are octave, fifth, fourth, major third, and minor third. The last 2 intervals normally are not used in Western music. Especially the tone with sevenfold base frequency is not used in Western music, but it is used in Jazz.

Considering integer multiples of a base frequency is not just “mathematical aesthetics”, valveless fixed length wind instruments like historical horns and trumpets only can produces tones with exactly this property. So asking about the kind of music possible under these restrictions in not just academic, but connected with real wind instruments.

The 2 musically most important intervals in our sequence are the major third and the fifth. From our series we see and hear that the fifth corresponds to 3/2 and the major third corresponds to 5/4. Playing a base frequency and these two intervals at the same time produces a major triad, probably the most used chord in Western music.

Defining MajorTriad={1, 5/4, 3/2} we can do PlayChord[264*MajorTriad,1.5] and hear that it sounds very consonant.

The sequence of tones having integer multiple frequencies of a base frequency is often called overtone series.

Now let us try to construct a major scale by using only intervals we found between

neighboring tones in the overtone series we just studied. Using a piano keyboard as our visual aid for constructing a scale we see that we immediately can create the base tone and tones for the third, the fourth and the fifth and, of course, for the octave.

 



Defining PartialScale1={1,5/4,4/3,3/2,2} we can listen to PlayScale[264*PartialScale1,1.5].

So we still are missing the second, the sixth, and the seventh. To find the corresponding frequency ratios, we look at the following picture:

 

 

We see that the lower interval marked by one dark and one light circle are similar intervals. We know that the lower interval, as a major third, corresponds to a frequency ratio of 5/4. The lower tone of the upper interval has a frequency ratio of 3/2 to the base tone. Therefore, we use a frequency ratio of (3/2).(5/4)=15/8 for the seventh.

We can listen to these intervals: Third={1,5/4}. PlayScale[264*Third,1.5] and PlayScale[264*3/2*Third,1.5]. We also can listen to these intervals as chords: PlayChord[264*Third,1.5] and PlayChord[264*3/2*Third,1.5]. Using this we can define PartialScale2={1,5/4,4/3,3/2,15/8,2}  and do PlayScale[264*PartialScale2,1.5].

So we have been able to fill one of the holes in our scale. Similarly, we can construct the sixth by noting that the sixth is one third above the fourth:

 

 

So the frequency ratio we need for this tone is (4/3).(5/4)=5/3.

We can check the musical quality of these intervals with PlayChord[264*Third,1.5] and PlayChord[264*4/3*Third,1.5]. To extend our scale, we define PartialScale3={1,5/4,4/3,3/2,5/3,15/8,2}  and do PlayScale[264*PartialScale3,1.5].

Summarizing we see that we have almost all the tones we need for a major scale:

 

 

The only tone we are missing is the second. We cannot get the second from the overtone series up to the eightfold multiple of the base tone (i.e. within a range of 3 octaves of the base tone). But we can note that by extending the keyboard a little bit and going up 2 fifths:

 

 

we get the tone one octave above the second. Just going down one octave (i.e. multiplying with 1/2) we see that we can construct the second as (3/2).(3/2).(1/2)=9/8.

So now we have completed our scale, PureMajorScale={1,9/8,5/4,4/3,3/2,5/3,15/8,2} and we can listen to the scale with PlayScale[264*PureMajorScale,1.5].

Now we have a musically pleasing scale represented by fractions with rather small numerators and denominators. The tuning building upon this scale is called pure tuning (or just tuning). The major triad over the base tone is the one we already discussed, it has a very simple mathematical description, and it sounds very harmonic. So what we have now seems like a mathematically and musically perfect solution to the problem of tuning instruments. To test the musical qualities of our scale, let us try a few other chords consisting just of thirds and fifths taken from our scale.

PlayChord[264*{3/2,15/8,2*9/8},1.5] is the major triad based on the fifth of our scale, and it sounds musically pleasing also.

This chord, has the same frequency ratios as the major triad on the base tone: (15/8)/(3/2)=5/4 and (9/4)/(3/2)=3/2.

Now let us look at the triad based on the second of our scale (it is a minor triad).

PlayChord[264*{9/8,4/3,5/3},1.5] does not sound musically pleasing.

Let us look at the internal frequency ratios of this chord: (4/3)/(9/8)=32/27, and (5/3)/(9/8)=40/27. These ratios are not related to the intervals we derived from the overtone series. For the “upper” interval, however, we have (5/3)/(4/3)=5/4, and this is a pure major third. We would expect a pure fifth for the ratio between the lowest tone and the highest tone in our triad, so instead of 40/27 we would need 3/2. If we try to change the lowest tone of the triad such that we get the pure fifth, we have to take a (5/3)/(3/2)=10/9 for the ratio between the base one and the second.

Listening to a chord containing this tone, PlayChord[264*{10/9,4/3,5/3},1.5] gives us a consonant musical experience again.

We see that for a pure triad upon the fifth we need a second of 9/8 and for a pure triad on the second, we need a second of 10/9. So the problem is that when we try to play different chords with the tones taken from one scale, we are getting into musical trouble.

The frequency ratio between the two different seconds we need is (9/8)/(10/9)=81/80, and it is called the syntonic comma. It also occurs in a different problem. Musically speaking, when we go up 4 fifths and then go down 2 octaves, we should arrive at the third above the base tone. Up 4 fifths and down 2 octaves corresponds to (3/2).(3/2).(3/2).(3/2)/4=81/64, one third corresponds to 5/4=80/64, so the ratio occurring here also is the syntonic comma of 81/80=1.0125. We can say that the syntonic comma is the degree of incompatibility between the pure third and the pure fifth.

Defining SyntonicComma = {1, 81/80} we can listen to PlayScale[264*SyntonicComma,1.5] and PlayChord[264*SyntonicComma,1.5] to perceive the musical relevance of this difference.

Musically speaking, we would like to have compatible fifths and thirds. Since the fifth is the simplest interval in the overtone series (except the octave, of course), we try to keep the value for the fifth and use a third, which is “compatible” in the sense that one third and 4 fifth essentially produce the same tone. To achieve this, we have to use a frequency ratio of 81/64 for the third. Since in our construction of the scale we used the third in 3 places, for the third, for the sixth, and for the seventh, we have to change the definition of the corresponding intervals in our scale. The scale built according to these principles is called Pythaorean scale.

So we define
PythagoreanMajorScale={1,9/8,81/64,4/3,3/2,4/3*81/64,3/2*81/64,2} and we play PlayScale[264*PythagorealMajorScale,1.5]. To hear the difference between the two different thirds (the pure third and the Pythagorean third) we do PlayScale[264*{5/4,81/64},1.5]. We also can listen to the two thirds played on the two stereo channels: PlayStereoScale[264*{5/4},264*{81/64},1.5]. The audible beats demonstrate that the difference between these two tones really matters musically. Finally, we can listen to the pure scale and the Pythagorean scale played simultaneously on the two stereo channels: PlayStereoScale[264*PureMajorScale,264*PythagoreanMajorScale,1.5].

We already noted that the Pythagorean third does not sound too harmonic when played as a constituent of a major triad.

To demonstrate this, try PlayChord[264*{1,81/64,3/2},1.5].

The pure triad sounds much better.

To demonstrate this, try PlayChord[264*{1,5/4,3/2},1.5].

So, music played in this temperament (temperament in musical context is just another word for tuning) probably should avoid the major triad on the base tone. Generally speaking, also the chords on the fourth and the fifth do not sound too well in Pythagorean tuning. As long as music is played monophonically, this does not really matter that much, but when playing chords, tuning becomes a serious issue. This fact explains why interest in tuning grew in the 16th century: keyboard instruments became popular. Keyboard instruments are used to play chords, and it is rater difficult to change tuning. Therefore, there was the need for a tuning method that would allow playing many different chords reasonably well. As we have seen, Pythagorean tuning and pure tuning both have serious problems with some very basic chords. So people tried to find alternative methods of tuning. One of the basic problems to be solved was incompatibility between the third and the fifth. Pythagorean tuning had enlarged the third to make it compatible with the pure fifth. The alternative is to reduce the fifth to make it compatible with the pure third. This implies that the fifths are not pure any more. To make the fifth compatible with the pure third we note that one third and 2 octaves together produce a frequency ratio of 5. Therefore, to create a fifth with the property that 4 fifths produce the same interval as one third and 2 octaves, the fifth has to have a frequency ratio of the fourth root of 5, . The frequency ratio for the fourth then is . Using the building principles we applied to create the pure tuning we can create the scale for this new tuning called meantone tuning.

MeantoneMajorScale={1,5^(1/2)/2,5/4,2/5^(1/4),5^(1/4), 5^(1/4)* 5^(1/2)/2, 5^(1/4)*5/4,2}. Using this definition, we can do PlayScale[264*MeantoneMajorScale, 1.5]. We also can compare the meantone scale to the pure scale, PlayStereoScale[264*MeantoneMajorScale, 264*PureMajorScale, 1.5], and to the Pythagorean scale PlayStereoScale[264*MeantoneMajorScale, 264*PythagoreanMajorScale, 1.5].

Major triads in this tuning sound acceptable.

To hear this, we do PlayChord[264*{1,5/4,5^(1/4)},1.5].

Comparing this with the major triad in Pythagorean tuning really makes an audible difference.

To hear this, we do PlayChord[264*{1,81/64,3/2},1.5].

There is another problem we have not coped with until now, the circle of fifths. 12 consecutive fifths would bring us back to the original tone, or, in other word, should be the same as 7 consecutive octaves. If this were true for pure tuning, we should have , which of course is not true. The frequency ratio  is called the Pythagorean comma and it is the measure of incompatibility between the pure fifth and the octave.

Defining PythagoreanComma = {1, 3^12/2^19} we can listen to PlayScale[264*PythagoreanComma,1.5] and PlayChord[264*PythagorenaComma,1.5] to perceive the musical relevance of this difference.

We note that the Pythagorean comma and the syntonic comma have similar orders of magnitude.
To make fifths and octaves compatible, we could either make the fifth smaller or make the octave larger. Since the factor 2 for the octave is an almost universal constant, we will change the fifth to be compatible with the octave. To accomplish that, we need a fifth with a frequency ratio of . Since we also want a third compatible with this fifth, we need a third of

Using these values for the fifth and the third, we can construct a new tuning for a scale. For reasons we will mention briefly later this temperament is called equal temperament.

After some easy algebraic transformations this scale can be defined as follows:

EqualMajorScale = {1,2^(1/6),2^(1/3),2^(5/12),2^(7/12),2^(3/4), 2^(11/12), 2}.
We can play this scale,
PlayScale[264*EqualMajorScale, 1.5]. Like with our previous scale examples, we can also compare it with other scales using stereo sounds, e.g. PlayStereoScale[264*EqualMajorScale,264*PureMajorScale,1.5].

Chords in equal temperament sound reasonably well, we do not have very bad dissonances. On the other hand, we do not have any pure interval except the octave.

This is illustrated by comparing PlayChord[264*{1,2^(1/3),2^(7/12)},1.5] and PlayChord[264*{1,5/4,3/2},1.5].

Our Mathematica toolkit also contains a function Triad allowing to select a triad with a given base note from a give scale. Triad[264*PureMajorScale,2] will construct the frequencies for the triad constructed from the second, the fourth and the sixth of a scale in pure tuning with a frequency of 264 Hz for the base tone of the scale. Using this toolkit, the reader can do extensive comparisons of chord in different tunings and learn how differently notationally identical chords sound in different tunings.

We have seen that the fundamental numbers for tuning are the frequency ratios for the third and the fifth, all the other frequency ratios are derived from these two.

So let us compare these ratios for all the tunings we have studied in a table:

 

 

Pure

Pyth.

Meantone

Equal

third

1.2500

1.2656

1.2500

1.2599

fifth

1.5000

1.5000

1.4953

1.4983

 

We see that the largest difference occurs for the pure and the Pythagorean third. This at least partially explains why triads in Pythagorean tuning sound very bad. Meantone tuning for the two basic intervals is very similar to pure tuning, therefore the basic major triad sounds rather well in meantone tuning. The third in equal tuning is also quite different from the pure third; therefore the musical characteristics of the major triad in equal temperament are quite different from pure tuning.

Since in all our tunings (except pure tuning) the value of the fifth and the third detemine each other,  the complete scale can be derived from the frequency ration of the fifth alone. In [1], tunings constructed ny this principle are called diatonic tunings, and it is shown that possible values for fifths are in the range from  to .

Using ScaleFromFifth from our appendix, we can define PythagoreanMajorScale=ScaleFromFifth[3/2], MeantoneMajorScale= ScaleFromFifth[5^(1/4)], and EqualMajorScale= ScaleFromFifth[2^(7/12)]

In the framework of this paper we could only discuss some of the mathematical problems for tuning musical instruments. Especially, we only studied diatonic scales (i.e. scales without using the black keys on keyboards). The problems get much more complicated when tunings are extended to chromatic scales. Detailed discussions of these problems can be found in [1] and [2]. For studying chords and scales along the lines we have described here, [3] gives a very large set of almost 300 sound examples.

 

References

[1] Easley Blackwood, The Structure of Recognizable Diatonic Tunings, Princeton University Press

[2] Mark Lindley, Ronald Turner-Smith, Mathematical Models of Musical Scales,
     Verlag für systematische Musikwissenschaft/

[3] Erich Neuwirth, Musical Temperaments, Springer Verlag.
[4] Erich Neuwirth, Designing a Pleasing Sound Mathematically, to appear in
      Mathematics Magazine

 

 


Appendix: Mathematica code

 

PlayChord[FreqList_, Duration_] :=

  Play[Min[1, 20*t, 20*(Duration - t)]*

      Sum[(Sin[2*Pi*t*FreqList[[i]]]/
           (1.13 - Cos[2*Pi*t*FreqList[[i]]])),
         {i, 1, Length[FreqList]}],
      {t, 0, Duration - 0.001}, SampleRate -> 22050]

 

PlayScale[FreqList_, Duration_] :=

  Play[Min[1, Abs[20*(t - Duration*Floor[t/Duration])],

        Abs[20*(t - Duration*(1 + Floor[t/Duration]))]]*

      Sin[2*Pi*t*FreqList[[1 + Floor[t/Duration]]]]/(1.13 -

            Cos[2*Pi*t*FreqList[[1 + Floor[t/Duration]]]]),
       {t, 0, Duration*Length[FreqList] - 0.001}, SampleRate -> 22050]

 

PlayStereoScale[FreqListLeft_, FreqListRight_, Duration_] :=

  Play[{Min[1, Abs[20*(t - Duration*Floor[t/Duration])],

          Abs[20*(t - Duration*(1 + Floor[t/Duration]))]]*

        Sin[2*Pi*t*FreqListLeft[[1 + Floor[t/Duration]]]]/(1.13 -

              Cos[2*Pi*t*FreqListLeft[[1 + Floor[t/Duration]]]]),

      Min[1, Abs[20*(t - Duration*Floor[t/Duration])],

          Abs[20*(t - Duration*(1 + Floor[t/Duration]))]]*

        Sin[2*Pi*t*FreqListRight[[1 + Floor[t/Duration]]]]/(1.13 -

              Cos[2*Pi*t*FreqListRight[[1 + Floor[t/Duration]]]])},
   {t, 0, Duration*Length[FreqListLeft] - 0.001}, SampleRate -> 22050]

 

 

Triad[Scale_, BaseTone_] :=

  List[Scale[[BaseTone]],

    If[BaseTone + 2 > 8, 2*Scale[[BaseTone - 5]],
                         Scale[[BaseTone + 2]]],

    If[BaseTone + 4 > 8, 2*Scale[[BaseTone - 3]],
                         Scale[[BaseTone + 4]]]]

 

ScaleFromFifth[Fifth_] :=

  List[1, Fifth^2/2, Fifth^4/4, 2/Fifth,
       Fifth, Fifth^3/2, Fifth^5/4, 2]

 

PureMajorScale = {1, 9/8, 5/4, 4/3, 3/2, 5/3, 15/8, 2}

PythagoreanMajorScale = {1, 9/8, 81/64, 4/3, 3/2,
                        (4/3)*(81/64), (3/2)*(81/64), 2}

MeantoneMajorScale = {1, 5^(1/2)/2, 5/4, 2/(5^(1/4)), 5^(1/4),
                     (5^(1/2)/2)*5^(1/4), (5/4)*5^(1/4), 2}      

EqualMajorScale = 2^({0, 2, 4, 5, 7, 9, 11, 12}/12)

SyntonicComma = {1, 81/80}

PythagoreanComma = {1, 3^12/2^19}