This is called the Doppler Effect. If something that emits a wave moves whilst it is doing so (imagine a noisy motorbike coming towards you then going further away, emitting sound waves the whole time) then the wavelength of the sound will become shorter as it is moving towards you, increasing the frequency, and  stretched as it is moving away, decreasing the frequency.

 

You will hear this as a change in pitch, getting higher as it approaches and lower as it moves away. The same thing happens for a moving object that is emitting light waves –e.g. a galaxy.