The same thing happens when you enjoy a swing at the park. Gravity pulls you down, but when you are at the bottom you are moving quickly, so up you go. A restoring force brings you back to equilibrium, then inertia takes you past equilibrium, and the restoring force pulls you back again, and the cycle continues until friction drains the energy out of the system.
A swinging child only has one frequency, back and forth, so many cycles per second, but a plucked guitar string has many vibrational modes. Let's look at the primary mode first.
The entire string moves up and down, and the middle of the string sweeps out the greatest area. The ends of the string are fixed and can't move at all. This is the fundamental frequency. If the string is tuned to middle C, approximately 261.6 hz, the wave form repeats 261.6 times a second. To perform a spectral analysis, plot the pressure of the sound wave as a function of time, over one cycle, 1/261.6 seconds, rescale the interval to 2π, and derive the fourier coefficients.
Assume the microphone is centered at zero volts, so we don't need an a0 coefficient. The largest coefficient will then be a1, or b1, or some combination of these, depending on when you start measuring the wave form. If you start measuring at 0, when the air pressure is on the rise, it's going to look like a sine wave. Thus b1 will be large, and a1 will be near zero. This is the fundamental frequency. But other coefficients appear as well. Why is that?
A second vibrational mode is overlaid on top of the first. It's not as strong, but it's there. Half of the string moves up, while the other half moves down. This mode leaves the midpoint of the string fixed in space. Of course the entire string could be moving up and down at its fundamental frequency, but if we could subtract that motion out, the midpoint is fixed and the two halves move up and down in opposition to each other.
Concentrate on the half-string between the midpoint and the bridge. The tention in the metal, i.e. the restoring force, is the same, yet the mass of the wire is cut in half. If you solve an appropriate differential equation, the frequency is doubled. The half strings produce a tone with twice the frequency of middle C. If you could isolate this sound, it would be an octave above middle C. This is the second harmonic. (The fundamental frequency is considered the first harmonic.) Thus the second sine wave in the fourier series, with twice the frequency, corresponds to the second harmonic. This is reflected in the coefficient b2.
If we could subtract the first two vibrational modes from the bouncing string, we would find a third. The middle third of the string moves down, while the outer segments move up, then the middle third bounces back up and the outer segments bounce back down. They vibrate in opposition, like three short strings anchored to the guitar. This produces the third harmonic, at three times the frequency of the fundamental, and the strength of this harmonic is indicated by b3. If you could hear it in isolation, it sings at G above C above middle C.
In the fourth vibrational mode, the first and third quarter segments of the string move up, while the second and fourth quarters move down. They bounce back and forth in this manner, again and again. The fourth harmonic has four times the frequency of the fundamental. We already said that a doubling of frequency is a jump of one octave, so this note must be C above C above middle C.
The fifth harmonic is E above C above C above midddle C, and the sixth harmonic is G above C above C above middle C. There are even higher harmonics, but they are relatively weak.
If you have studied music at all, then you know that C E and G form a major chord, that is pleasant to the ear. Is it a coincidence that a single guitar string, when plucked, should produce, through its first six harmonics, the notes of a major chord? Probably not. We've been listening to things vibrate, in nature, for hundreds of millions of years, and our brain is accustomed to hearing these frequencies together. Pull the third harmonic down an octave, and the fifth harmonic down two octaves, and build a major chord. Thus, major chords sound natural to us.
The gap between the fifth and sixth harmonic is a minor third, so a minor chord still sounds like music. However, notes that are a half step apart, when played simultaneously, seem to clash. Now a plucked string certainly has harmonics that are a half step apart, but these are high harmonics, and they are relatively weak. In some cases they are too high to hear. We simply aren't use to these intervals.
This suggests that another life form, some 40,000 light-years from earth, may appreciate the same type of music as we do. It's all based on physics and math, which are universal concepts. They would enjoy hearing Mozart, and I'm sure we would enjoy listening to Shnogglehaus. We just have to wait 40,000 years for the transmission, and hope they use the mp3 format. :-)
If you can find "music tubes" at a party store, buy three or four; it's a great investment. A music tube looks like a vaccuum cleaner attachment. It's a flexible plastic hose about one meter long, with ridges along its length. Twirl it over your head, and air is pulled through the tube by centrifugal force. (Or you can blow right into the bell at one end.) As the air bumps along the ridges, it creates "wind" sounds, clustered around a frequency that depends on the speed of the wind, which depends on how fast you are twirling the tube, or how hard you are blowing into the bell. When one of these frequencies corresponds to a natural harmonic of the tube, it is amplified. The note is easily heard, even in the next room. spin the tube slowly, and listen to the second harmonic. (The fundamental frequency is not accessible. If you spin the tube that slowly, you just don't get enough air going through.) Spin the tube a little faster to hear the third harmonic. These two notes are a fifth apart, and they sound natural, like an interval you might play on the piano. The fourth harmonic is an octave above the second, the fifth harmonic provides the major third, and the sixth harmonic repeats the dominant of the major chord. A rapid twirl can sometimes evoke the seventh harmonic, which is the note that turns a major chord into a major seventh.
One day I taped three tubes together to make one long tube. This cannot be twirled; you simply blow into the bell at one end. The fundamental frequency was far below the threshhold of human hearing. The notes that I heard, by blowing into the bell, represented the harmonics in the teens and twenties. These are clustered close together, with spacings of a half step or less. Sometimes you can hear two or three harmonics at once. These notes sound very strange together; our brains are not accustomed to these intervals. If the alien, 40,000 light-years away, has ultrasonic hearing, he may indeed listen to the high harmonics, spaced close together, and this might form the basis for his music. So I guess I shouldn't pre-judge; his music could be quite different from ours.
When tunable stringed instruments were first developed, the masters usually tuned them for a particular key. If the tuning was based on the key of C, G would indeed be 1.5 times the frequency of C, and E would be 1.333, and E flat would be 1.25, and so on, according to the harmonics. The instrument was "configured" to play in that key, and the song sounded pure and perfect. But if the next song was in another key, the instrument didn't sound right at all. Everyone had to wait while the clavichord was retuned.
Andreas Werckmeister (and others) began exploring alternate tuning methods. No key (i.e. no scale) was perfect, relative to the ideal harmonics, yet most of them sounded reasonably good. In some methods of tuning, different keys had different "colors". This depended on the intervals selected, which ones were pure and which ones were a little bit off. In contrast, an "equally tempered" instrument exhibited uniform tuning. Every scale sounded exactly the same. Only someone with perfect pitch could determine the key, having heard the song.
During the 1720's, Bach wrote 48 fugues, two for each major and minor key, proving the worth of the latest tuning methods. These fugues are collectively known as the "Well-Tempered Clavier". (Clavier simply means keyboard; it is not a specific instrument.) It is not clear whether Bach intended a uniformly tuned instrument, or whether different key signatures might have slightly different tonal qualities. Some say Bach wrote these fugues to celebrate the perfection of an equally tempered instrument, but others believe he sought a well tempered instrument wherein each key sounded good, but they did not all sound alike. I am not a musicologist, and cannot comment further.