An oscillator is used to generate a periodic signal, such as a carrier wave, which is essential for modulation in communication systems.