What is the algorithm to do frequency modulation? I'm familiar with audio synthesis, oscillators etc. I'm now trying to implement my own software algorithm to do FM as described by https://en.wikipedia.org/wiki/Frequency_modulation.

What I have implemented outputs the following (spectrogram produced with sox):



This was produced by my algorithm set with a property of:
A 1200hz sine wave modulated by a 12hz sine wave. 

However, I don't think this is actually 'correct' in what FM should do. I'm assuming I would see a 'signal' increasing and decreasing in frequency.



Is this correct? Or am I doing something wrong?



The way I am calculating the amplitude for each time point (code is written in Haskell):

fmSine :: Frequency -&gt; Signal' -&gt; Signal'
fmSine (Frequency hz) (Signal sng) = Signal (\t -&gt; sin ( (sng t) + (hz* 2 * pi * t)))


Essentially I'm doing sin ((amplitudeOfModulationFrequency t) + hz * 2pi * t)
Where hz is the frequency and amplitudeOfModulationFrequency t is the amplitude at time t of the modulating frequency.
What your plot shows is noise from varying size discontinuities in the waveform.

When you change a modulating frequency, you have to make sure the resulting FM waveform does not have discontinuities.  You have to do this by incrementally changing the phase of the argument to the sin() function, not by naively multiplying the modulating frequency by time, which will jump the phase by some (psuedo)random angle when the frequency changes.