Theory:

When a fast-moving train approaches a stationary listener, the whistle appears to increase in pitch, and it appears to decrease as the train goes away from the listener. An Austrian mathematician and physicist, Christian Doppler (1803-1853) was the first to notice and explain this apparent change in frequency.

Relative motion between the observer and the train

When there is a relative motion between the source and the listener, the frequency of the sound received by the listener differs from the original frequency produced by the source. This phenomenon is called doppler effect. This relative motion could be caused by a number of factors, such as:
• The listener moves towards or away from a stationary source.
• The source moves towards or away from a stationary listener.
• Both source and listener move towards or away from one other.
• The medium moves when both source and listener are at rest.
Whenever there is a relative motion between a source and a listener, the frequency of the sound heard by the listener is different from the original frequency of sound emitted by the source. This is known as the “Doppler effect.”
Doppler effect

For simplicity of calculation, it is assumed that the medium is at rest. That is, the velocity of the medium is zero.
Reference:
https://pixabay.com/photos/people-man-train-station-travel-2590657/
https://commons.wikimedia.org/wiki/File:Dopplerlkm_effect.jpg