# Strange results from my FM synthesis algorithm

It seems that I haven't studied enough about FM Synthesis. My current algorithm looks like this:

modulator = sin( 2 * pi * fm_freq * i/sample_rate )
carrier = sin( 2 * pi * ( freq + modulator ) * i/sample_rate )


Instead of generating one stable waveform, it generates a sound warping from a pure sine wave to something awfully distorted. What am I doing wrong?

It should be more like this:

modulator = A_mod * sin(2 * pi * fm_freq * i / sample_rate)

carrier = sin (2 * pi * (freq * (1 + modulator)) * i / sample_rate)


The two main changes are:

• the modulation signal needs a scale factor (A_mod) which determines the amplitude of the FM - typically A_mod << 1

• the carrier frequency needs to be multiplied by (1 + modulator) rather than just modulator, since it needs to be centered about freq with a deviation of +/- A_mod * freq (in your version the centre frequency is zero and your instantaneous frequency is varying between +/- freq !).

• +1 for reminding the OP to include A_mod << 1 in modulator. I assume the OP has already ensured that fm_freq << freq because if not, one can get quite unexpected results. – Dilip Sarwate Jan 13 '12 at 12:54
• What does the << imply here? – Chris Stryczynski Feb 8 at 23:12
• << is the mathematical sense of “very much less than”. – Paul R Feb 9 at 9:21

What you're doing is actually phase modulation rather than frequency modulation. You mustn't multiply the modulator with the sample index then, though: try

carrier = sin( 2 * pi * ( freq*i/sample_rate + modulator ) )


An actual frequency modulation is not quite as simple, it would be rather something like

phi += 2 * pi * (freq + modulator)/sample_rate
carrier = sin(phi)