My understanding is that the vast majority of western music uses equal temperament, i.e. all semitones have a frequency ratio of the 12th root of 2. However I can hear in my piano that the notes at the low and high extremes of the keyboard are ever so slightly out of pitch. It seems that the lowest notes are slightly flat and the highest notes slightly sharp. This is a digital piano from Roland so they must be doing this on purpose. Why is this? I suppose normal pianos are like this too - is it done on purpose or is it a historical thing?
There are physical and psychoacoustics reasons behind it.
A vibrating string held by its two extremities can only vibrate at certain frequencies (cycles per second, expressed in Hertz, i.e. 440 Hz = 440 cycles/second), which relates to the characteristics of the string (e.g. its weight per unit of length, its flexibility) and how it is used (e.g. the vibrating length — which is fixed by the instrument and the player; how much force is used to tense it — which is how you tune a stringed instrument). These are called partials.
For an ideal string, that is a string which offers no resistance to being bent or rolled, there is a lowest frequency at which the string can vibrate, the fundamental; every other frequency at which the string can vibrate is a multiple of this frequency. These particular cases of partials are called harmonics.
For example, the string of a middle A in the piano can vibrate at 440Hz, 880Hz = 2*440Hz, 1320Hz = 3*440Hz, 1760Hz, … When you hit the string with the hammer, the string typically vibrates with a combination of several of these frequencies.
Now go an octave higher. The fundamental of that A is 880Hz, with harmonics at 1760Hz, 2640Hz, 3520Hz, … As you can see, the harmonics of the higher A all are harmonics of the lower A. Thus, they sound right together.
In the middle range of the piano, its strings can pretty accurately be considered perfect and partials tend to be true harmonics.
But if you go to the extreme range of the piano, it’s not the case any longer. The heavy string of the low notes can’t be rolled so easily (they are too large). This means that the partials are not harmonics any longer. For example (totally fictional and probably wildly inaccurate), the frequencies of a low A tuned to 55Hz could be 115Hz instead of 110Hz, 172Hz instead of 165Hz, … But this means that if you play a low 55Hz A with the A an octave higher, 110Hz, well, there is a 110Hz vibration (the higher A) and a 115 vibration (from the low A) at the same time. These conflict and you can hear that something is out of tune (you could hear a 5Hz beating, e.g.).
To avoid this, the low A is tuned flat, let’s say at 52Hz, with partials (still fictional) at 110Hz, 167Hz, … Now when you play the low A alone? Its fundamental is at 52Hz, which your trained ear might perceive as a bit flat. But when you play both As together? Now there is way less conflict between their partials. They sound good together.
Same with the high range on the piano: the very thin, highly constrained strings are far from an ideal string; their partials also are not true harmonics. So you tune them sharp (once again, to your trained ear) to ensure they sound good together with the lower strings.
Octaves on a piano are not tuned pure.
Because of inharmonicity, the higher partials of a single piano string are slightly sharper than theory would predict.
Ideal harmonic series above 100Hz (Hertz): 100 200 300 400 etc
Actual harmonic series above 100Hz (approximation): 100 200.05 300.2 400.6
The higher the partial; the sharper the pitch.
Shorter piano strings have a higher inharmonicity.
For an octave to sound in tune, all the partials of each note have to be as in tune with each other as possible.
If the 2nd partial of the top note equals the 4th partial of the bottom, it is called a 4:2 octave.
In tune octaves are wide 2:1's meaning the frequencies of the notes would be something like 100Hz and 200.2Hz. The culmination of this slightly sharper top note adds up to sharp treble notes, and flat bass notes, but this is relative to a tuner with no stretch. The octaves sound fine.
Any single string creates harmonics as it rings. Up to eight parts a C would generate C C G CEG Bb and C, essentially a dominant 7th chord. The lower partials are louder and than the upper partials due to string length influencing volume. A longer portion of the string vibrating will be louder. Tempered tuning requires that octaves and fifths sound good while the other weaker relationships can be slightly out. Our brains interpret wobbling major thirds as shimmer rather than being seriously out since that would be more noticeable at the octave for example. The upper partials sound sharp compared to what we define as proper tuning in tempered tuning. The sharpness is natural but would prevent us from playing in different keys. When an upper note is slightly flat your brain will interpret this as unnatural and object more than an upper note that is slightly sharp. Notes have a certain range of sharpness before they become objectionable. If you play a root and a fifth on a guitar you can bend the fifth ever so slightly sharp and it still sounds okay. The problem with the piano is that if you tune the low notes to standard pitch, the upper notes would sound slightly sour at standard pitch. Therefore the most used notes in the midrange should be at standard pitch allowing upper notes to be sweetened by being slightly sharp and the lower notes tuned slightly flat for the same reason. This would mimic the natural state of things. The length of string and thickness play a role as well as mentioned above. This is generally the reason why short scale upright pianos don't sound so great at the low and high range compared to a grand piano.
Edouard provided a perfect explanation. I don't have to add anything to that. Just a couple of comments:
I would be very surprised if your digital piano was tuned with sharp low notes and flat high notes. Perhaps the samples Roland uses for the high notes have particularly strong (flat) harmonics and you are sensitive to them? It would be interesting if you could take a digital tuner or simply record and run a pitch analysis to see where the fundamentals are compared to the other octaves.
You ask whether it is historical. I don't think we are well equipped to know the answer to this question as people didn't have the tools to assess this a while back: they would trust their ears in the tuning and whether they ended up with a stretch tuning or not, we will never know: some tuners stretch instruments naturally not even realizing they do until someone comes to show them what the frequency analyzer says--frequency analyzer which may have flaws of its own as the fundamentals are not a very clear spike, especially for low tones.
But I think we can say stretching is subjective and cultural. The stretching technique intended to compensate for the non-harmonic partials is in the end a matter of taste since it depends on how sensitive you are to these harmonics compared to the fundamental. For example, I noticed that piano tuners in the US tend to stretch the tuning much more than European tuners. I am French living in the US and tunings that are too stretched make me cringe.
- Last, this post gives some interesting insights from a tuner's perspective on stretching. I was glad to read that the overstretch on an old piano recording made him feel pain. Clearly lots of subjectivity on this topic at the end of the day.
Just one thing to add.
There are a wide number of historical piano tunings. One commenter said they thought that using the 'actual' tuning would sounds better. That is known as mean temperament, and was the most common tuning before bach. The wikipedia entry has a reasonable but abbreviated statement with links to the different tunings.
What is less clear is the fact that different keys sounds moody, or bright, has to do but only with the frequency, but where it is in the circle of fifths for a given tuning. Once you realize that, you realize that a given piece of music is written for a given tuning, and you need to know more than a 440 or a397.
If you are trained as a string player, as i am, you often ignore these effects until you advance a few years. At some point you are taught to raise and lower certain notes, especially 3s and 7s, to make them 'sound right', which means you need to understand from the sheet music what chord is being implied or played around you, app you can raise and lower just a few hertz. This is also why indian music includes those effects in the shruti system, which includes 22 values per octave, so the author can notate what goes high and low without requiring mental gymnastics from the performer.
The stanford University organ is unusual that it has two sets of pipes, and is in two different tunings. You can only play one tuning at a time, but it is quick to switch... A huge lever.
With digital pianos (samplers) you can often load a patchs in different tunings, which is great for playing what we now call period music.