How to frequency modulate (FM) two sinewaves by software?

On every moment of the samplerate (for example 44.4 usec.) you have two amplitudes available.

Carrierwave (CARR) and modulator (MODU) wave. (both generated from the same sine lookup table by two phase accumulators.) But what to do with those two amplitudes?

## How to FM two soft sines?

Emulating FM sound synthesis? :)

An phase accumulator is incremented by a certain to get a certain frequency. You add/subtract your modulation input to this increment value; e.g.

phase_accu+=phase_inc+mod

If you want to do FM sound synthesis you need to add the amplitude (with a fudge factor probably) to the accumulator but not save the result;e.g.

phase_accu+=phase_inc temp_phase=phase_accu+mod

Hoop dat je er wat aan hebt :)

Emulating FM sound synthesis?

yes, and also AM. 8)

You add your modulation input to this increment value.

The phase accumulator causes the frequency of the sine. So the amplitude of the second sine is the modulation factor? (not the adder value?)

And how does AM work? It's not adding the amplitudes, because that is mixing two sines. (I manage to do this already, adding two amplitudes and divide by two.)

And how does AM work? It's not adding the amplitudes, because that is mixing two sines.

Isn't it? I thought that was exactly what AM meant - the signal to be transmitted varies the amplitude of the carrier.

Looks like AM what I got, but I mix two amplitudes of two sines with two different frequencies.(A+B/2)

(signal coming from DAC AT90PWM3)

The most cost-effective and musically valid way to FM modulate two sine waves is to buy a Yamaha FB01 MIDI tone module on eBay for about $25 US. You get an excellent Z-80 microprocessor-based piece of equipment ready for use. The sound chips inside the FB01 handle all the trigonometry needed to FM modulate four separate sine waves simultaneously. There is no way that you can get inexpensive stand-alone microcontrollers to work at creating the complex waveforms needed for the beautiful bell/piano/spacy tones characteristic of FM synths. Yamaha spent millions developing these ICs, then they sold them in expensive tone modules twenty years ago to professional musicians. The same tone modules are selling for @$25 (Yamaha FB01) to @$65 (Yamaha TX81Z) now all the time on eBay.

Use the AVR to convert your inputs into the MIDI messages needed to control the FB01. Set the FB01 to INIT_VOICE which is a single unmodulated sine wave. The AVR would convert the frequency to its note equalivant (256 Hz is C3 or MIDI note-on value 0x3c; standard reference pitch 440Hz is MIDI note value 0x45). Frequencies can also be fine tuned with 100 cent steps between each half tone. MIDI (musical instrument digital interface) is a serial signal similar to RS232. It is 8 data bits, one start, one stop bit, LSB first. It differs from RS232 by being 31.25K baud (1MHz/32, which seemed like a good idea in 1982) and also being a +5V/ground current-loop, instead of +15/-15 volt signal with ground shared between the two computers.

Some remarks about AM (2 cents)

If you have a carrier with Amplitude A and frequency Fc

the signal voltage u(t) is is:

u(t)=A*cos(2*pi*Fc*t)

With amplitude modulation you change A with time.

If you modulate with a sine of Frequency Fm, you use

A(t)=a+b*sin(2*pi*Fm*t)

So the signal is:

u(t)=(a+b*sin(2*pi*Fm*t) ) * cos(2*pi*Fc*t)

In normal AM he value of b is smaller than a,

so there is always a "positive amplitude", and the

spectrum consists of three sines. The

Carrier at Fc and the two "sidebands" at Fc-Fm and Fc+Fm.

If you choos a=0 you use the so called suppressed

carrier modulation with only the sidebands at

at Fc-Fm and Fc+Fm left in the spectrum. Instead of

the multiplicative way, you may get this waveform

by adding two sines.

So generally you use a muliplier to do AM.

Yamaha does not implement true FM synthesis, it's actually phase modulation.

e.g. u(t)=sin(2*pi*Fc*t + mi*sin(2*pi*Fm*t))

You can read the patent on how they implemented it; especially figure 8. Be warned though, patents are difficult to read :)

Interestingly, to prevent to have to implement multipliers in silicon, they represent the sine table in a logarithmic format, and as adding two logarithms together equals multiplication it's easy to adjust the 'volume' of an operator with just a simple adder. You only need a log->lin converter after that, which is just a LUT.

Simply summing two sines does not result in amplitude modulation. Under some circumstances, it may look like AM, but it is not.

Real AM is generated by either multiplying one signal (the carrier) by the other. This is equivalent to varying the gain of a carrier amplifier under the control of the other signal (the way it was done historically). Done numerically, the modulation should vary between 0 and 2 and have a value of 1 when there is no modulation. Or, effectively scaled to produce this.

So, simply construct a lookup table and step trough each. Multiply one by the other (taking care of offsets and clipling). You will have AM.

Jim

I am with Jayjay - That's how it works. Basically what your scope image shows is not AM, because it looks like the carrier phase gets inverted (after the zero crossing, your signal is negative). I think real AM does not invert carrier, but not sure.

So basically:

Out(x) = slowsignal(x) * carrier(x), but by using a nifty trick with logarithmic lookup tables, the slow multiply operation gets converted to addition:

Out(x) = exptab[ log_slowsignal(x) + log_carrier(x) ];

That picture, if there is "modulation", is more like single sideband (SSB), not AM. With AM, there is carrier out when there is zero input. With SSB, no carrier at zero input. Clawson's little graphic shows it nicely.

Jim