3
$\begingroup$

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?

$\endgroup$
6
$\begingroup$

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 !).

$\endgroup$
  • 2
    $\begingroup$ +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. $\endgroup$ – Dilip Sarwate Jan 13 '12 at 12:54
  • $\begingroup$ What does the << imply here? $\endgroup$ – Chris Stryczynski Feb 8 at 23:12
  • $\begingroup$ << is the mathematical sense of “very much less than”. $\endgroup$ – Paul R Feb 9 at 9:21
4
$\begingroup$

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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.