Why does a train whistle change pitch as it passes?
(Lansing State Journal, April 10, 1996)
Imagine that you drop a stone into a pond. You could count the number of waves that pass an object like a reed in the water in a particular time interval (the frequency). Now consider an object like a toy boat that is moving toward the point where the stone was dropped. As a result of the motion, the number of waves that hit the boat in the same time interval increases. That is, the frequency of the wave increases.
The same effect occurs in a sound wave. If you are moving toward a train blowing its whistle, or if the train is moving towards you, the waves are compressed and the frequency of the sound waves is higher. This results in a higher pitch. If the train is moving away from you (or if you are moving away from the train), the frequency decreases, resulting in a lower pitch. This is called the Doppler effect and can be observed bin all types of waves, including light.