HETERODYNING

When two different vibrations are mixed together, sum and difference
frequencies, called heterodynes, are created. In acoustics, heterodynes
are called beats.
For example, when two slightly detuned notes are sounded
together, a slow vibration or beating is heard. The
beat frequency equals the difference in frequency between the two
notes.
Since a musical chord is a mix of different frequencies, one might
wonder why unwanted beats don't ruin the chord. The
answer lies in the musical scale.

JUST INTONATION

In a Just scale, note frequencies relate to the
Fundamental frequency (the tonic) by small, whole number ratios. As a result, the
semitones aren't
evenly spaced. If you try to move the tonic (the "I") to a different note,
the intervals will be off and the transposed scale will be noticeably out of tune.
In Just scales, chordal beating (heterodyning) tends to produce
harmonic notes
already in or suggested by the original notes, with pleasing results.
For example, a 440Hz root beating with a 220Hz suboctave generates a
difference frequency of 220Hz (already present) and a sum frequency of
660Hz which is a musical 5th interval (3/2 ratio above 440Hz).
The disadvantage of a Justscaled instrument is that it only plays in
tune in one key.

EQUAL TEMPERAMENT

In the Equaltempered scale, each frequency is
the twelfth root of two (~1.059463) times higher in frequency than the
last. In this way, the tuning issues are spread out amongst the key
signatures, making all of them sound okay—it doesn't matter which note
is the tonic.
And conveniently, after multiplying the tonic by the
twelfthroot of two twelve times, its
frequency is perfectly doubled, which just happens to be one octave.
Of course now the heterodynes aren't perfect but then neither are the
note intervals
themselves! In spite of it all, keyboards and guitars, both equally tempered instruments, usually sound okay.

