DSP Explorables

Modulation, part 1: putting a signal on a carrier

A voice covers roughly 100 Hz to 3 kHz. To send it by radio, you can’t simply connect a microphone to an aerial, for two reasons:

So a transmitter moves the sound up to a carrier frequency of its own, and the receiver moves it back down. Each station gets its own slice of the spectrum, and the aerials can be a sensible size. Moving a signal to a carrier and back is modulation and demodulation. A device that does both is a modem (modulator–demodulator).

This page starts with the simplest way to move a sound up, and finds out what goes wrong. Each fix leads to the next idea: AM, then I/Q signals, then the Hilbert transform and single sideband, then FM, and finally a receiver that handles all of them the way a modern software radio does. Part 2 moves on to sending bits.

The page leans on two earlier ones:

Everything runs at 44.1 kHz, with carriers between 4 and 17 kHz. A real radio’s carriers are a thousand times higher, but here every signal, even one sitting on its carrier, can be listened to.

1 · Moving a sound up: multiply by a carrier

Section titled “1 · Moving a sound up: multiply by a carrier”

The message is the sound to be sent. Here it’s either a synthetic voice, a steady 1 kHz tone, or a note (220 Hz and its harmonics), each limited to 3 kHz. The carrier is a plain cosine at a much higher frequency, fcf_c.

The simplest way to move the message up is to multiply the two, sample by sample:

sent(t)=m(t)⋅cos⁡(2πfct)\text{sent}(t) = m(t) \cdot \cos(2\pi f_c t)

Why that moves the spectrum is one line of trigonometry. Take a single frequency in the message, cos⁡(2πft)\cos(2\pi f t):

cos⁡(2πft)⋅cos⁡(2πfct)=12cos⁡(2π(fc−f)t)+12cos⁡(2π(fc+f)t)\cos(2\pi f t) \cdot \cos(2\pi f_c t) = \tfrac12 \cos\big(2\pi (f_c - f) t\big) + \tfrac12 \cos\big(2\pi (f_c + f) t\big)

Every frequency ff in the message turns into two, at fc−ff_c - f and fc+ff_c + f, each at half the amplitude. The whole message reappears twice around the carrier: once the right way up, above it (the upper sideband), and once mirrored, below it (the lower sideband). The carrier itself isn’t there at all. This is called double sideband, suppressed carrier, or DSB.

Listen:

Top: 20 ms of the message, drawn dashed with an upside-down copy, and the message × carrier in blue. The carrier wiggles fast inside the message’s outline, and flips over whenever the message goes negative. Bottom: spectra. The message sits at 0–3 kHz; after multiplying, it sits either side of the carrier.

The two sidebands hold exactly half the power each (50.0% · 50.0%). Together they have 3.0 dB less power than the message had, because a cosine’s average square is ½. Listen: the result sounds like a whistle at the carrier frequency, shaped by the message. Move the carrier, and the spectrum moves with it.

2 · Getting it back, and the receiver’s phase problem

Section titled “2 · Getting it back, and the receiver’s phase problem”

To bring the message back down, the receiver does the same thing again: it multiplies by the carrier. Using the same trigonometry, each sideband splits into a copy at 0 Hz and a copy around 2fc2f_c. A low-pass filter keeps the copy at 0 Hz and removes the other one:

mixed = 2 * received * cos(2π · fc · t + phase_error)
message = lowpass(mixed, 3500) # keep 0–3.5 kHz

This is synchronous detection: the receiver makes its own copy of the carrier, in step with the transmitter’s. But what if it isn’t quite in step? The receiver’s oscillator is a separate piece of hardware, miles away. Even if its frequency is perfect, its phase (where it is in its cycle at a given moment) is whatever it happens to be. Working through the trigonometry with a phase error φ\varphi gives:

output=m(t)⋅cos⁡φ\text{output} = m(t) \cdot \cos\varphi
Listen:

Top: the spectrum after multiplying by the receiver’s carrier: the message back at 0–3 kHz, plus a copy around 16 kHz, which the low-pass filter (green) removes. Bottom: the whole message, sent (grey) and received (blue).

With no phase error, the output matches what was sent exactly. At a phase error of 60°, the output is 6.0 dB quieter (cos 60° = ½). At 90°, it’s silent: the message has gone completely. A small frequency error is worse still. The phase error then keeps growing, so the output fades in and out. At 0.5 Hz it falls silent once a second.

So the receiver has to know the carrier’s phase exactly, and from the received signal alone, which doesn’t even contain the carrier. That can be done (Part 2 shows how), but for decades it was too hard for a cheap radio. The next two sections show two different ways round it.

3 · AM: send the carrier as well

Section titled “3 · AM: send the carrier as well”

The oldest fix is to send the carrier as well, and plenty of it. Amplitude modulation (AM) adds 1 to the message before multiplying:

sent(t)=(1+k⋅m(t))⋅cos⁡(2πfct)\text{sent}(t) = \big(1 + k \cdot m(t)\big) \cdot \cos(2\pi f_c t)

kk is the modulation depth. As long as kk isn’t too big, 1+k m(t)1 + k\,m(t) never goes negative, so it’s the outline of the signal, its envelope. Now the receiver doesn’t need its own carrier at all. It just has to trace the outline, and that’s a job for two components:

The average of the top half of a cosine is 1/π1/\pi of its peak, so what comes out is the outline divided by π\pi. Take off the steady part, and what’s left is the message. This is the envelope detector.

There’s one more part, and it comes first. An aerial picks up every station at once, and a diode fed all of them would trace the outline of the whole jumble. So before the detector there’s a band-pass filter that lets through only the station you want: its carrier and the two sidebands around it. In a simple radio, this is a tuned circuit, a coil and a capacitor that resonate at one frequency, like the two-pole resonator on the IIR design page. Turning the tuning knob changes the capacitor, and so the frequency it picks out. Aerial, tuned circuit, diode, earphone: that’s the whole of a “crystal set” radio, which needs no batteries at all, because the station’s own signal powers the earphone.

The figure below starts with one station on its own, where a tuned circuit would have nothing to remove. Then you can add a second station, and a tuned circuit to separate them.

Listen:

Top: 15 ms of the AM signal (blue) and its outline, 1 + depth × message (dashed). Middle: what the envelope detector gives back (blue), on top of the message (dashed). Bottom: the spectrum: a big spike, the carrier, with the two sidebands either side.

With the tone at 80% depth, the detector’s output is the message to within −71.7 dB, and the carrier takes 75.8% of the power. At 100% depth the carrier still takes 66.8%, and with the voice at 100% it takes 96.2%, because speech is mostly much quieter than its peaks.

Above 100%, the outline would go negative, but the detector can only see its size, so the bottom of each wave is folded back up. This is overmodulation. With the tone at 110%, the distortion jumps to −27.3 dB, and at 150% to −11.3 dB. Listen to the difference.

Now choose the voice and add station B, playing a tune at 16 kHz. With no tuned circuit, the diode traces the outline of both stations at once, and what comes out resembles B (0.862) more than A (0.459). Turn on the tuned circuit. With a sharpness (Q) of 2, the output is A (0.996), and only a trace of B is left (0.083). Now turn the tuning dial to 16 kHz: the output becomes B (0.999), with only a trace of A (0.039). Halfway between, at 13 kHz, you hear both (A 0.565, B 0.789).

Sharper isn’t simply better. A tuned circuit’s response is a smooth hump, so the sharper it is, the more it also cuts A’s own outer sidebands, and the higher notes of A’s message with them. Tuned to A at Q = 2, the sidebands 3 kHz below and above the carrier lose 6.7 and 6.2 dB. At Q = 20, B is almost gone (0.025), but those sidebands lose 25.6 and 25.0 dB, A sounds muffled, and it resembles itself less (0.820). The readouts allow for the small delay a tuned circuit adds, which you wouldn’t hear.

One tuned circuit can’t be both flat across one station and steep at its edges. That’s one reason radio designers moved to the superheterodyne, in section 8.

The diode in this figure is simulated at 8 × 44.1 kHz. Chopping off half of each cycle makes harmonics far above the carrier. At 44.1 kHz, those would fold back into the audio band, as on the sampling page. A real diode has no samples, so it has no such problem.

AM is simple, robust and cheap to receive, which is why it was broadcasting’s first standard and is still in use. But it’s wasteful in two ways:

Sections 4 to 6 fix both, by finding a way to send just one sideband with no carrier.

4 · I/Q: two carriers, 90° apart

Section titled “4 · I/Q: two carriers, 90° apart”

Look again at the receiver in section 2. At a phase error of 0°, multiplying by the cosine got the whole message. At 90°, it got nothing, and the multiplier was then a sine rather than a cosine. So a receiver that multiplies by both, a cosine and a sine, can’t lose the message: whatever the phase error, it lands somewhere between the two.

The two outputs have names:

With a phase error φ\varphi, I gets m(t)cos⁡φm(t)\cos\varphi and Q gets −m(t)sin⁡φ-m(t)\sin\varphi. The message is split between the two, but nothing is lost: I2+Q2=m(t)2I^2 + Q^2 = m(t)^2 at every phase. (The minus sign is a convention: receivers usually multiply by minus the sine, so that the arrow below turns anticlockwise for frequencies above the carrier, as on the Fourier page.)

The best way to see I and Q is as a single arrow, a complex number I+jQI + jQ. As on the Fourier page, a complex number is an arrow on a plane, with I across and Q up. A phase error just turns the arrow, and a frequency error makes it spin. Neither changes its length.

One wave, two knobs

Section titled “One wave, two knobs”

There’s a bonus: a transmitter can send two messages, one on the cosine and one on the sine. That can seem impossible. What arrives at the aerial is a single real wave, one number at each moment, so how can it hold two messages?

Zoom in to a few cycles of the carrier. Over that short time the messages hardly change, so what arrives is just a sinusoid at the carrier frequency. A sinusoid at a known frequency has two things you can set independently:

So one wave has two knobs. “How much cosine plus how much sine” is just another way to describe the same two knobs. Adding a cosine and a sine of the same frequency doesn’t make a more complicated wave. It makes another plain sinusoid at that frequency, shifted in time:

Acos⁡(2πfct)+Bsin⁡(2πfct)=A2+B2 cos⁡(2πfct−θ)A\cos(2\pi f_c t) + B\sin(2\pi f_c t) = \sqrt{A^2 + B^2}\,\cos(2\pi f_c t - \theta)

Here θ\theta is the angle of the arrow (A,B)(A, B). Turning up B doesn’t add a second wave: it slides the one wave later, and makes it bigger.

The receiver gets each knob back with the test from the Fourier page: multiply, then average. A cosine times a cosine averages to ½, but a sine times a cosine averages to 0. So multiplying by the cosine measures A and ignores B entirely, and multiplying by the sine measures B and ignores A. It’s the same orthogonality that stops one frequency in a DFT from seeing another.

Top: A × the cosine (dashed) plus B × the sine (dotted) make one wave (blue). The orange lines mark its peaks. Middle and bottom: the receiver multiplies the wave by its own cosine and its own sine. The products wiggle at twice the carrier frequency, and their averages (orange) are the two knobs.

With A = 0.80 and B = 0, the wave is a plain cosine of size 0.80, and the cosine receiver measures 0.80. Now turn up B to 0.60. The wave grows to 1.00 and its peaks slide 37° later, but the cosine receiver still measures exactly 0.80. Only the sine receiver notices: it measures 0.60.

Then give the receiver a phase error. At 30°, its cosine measures 0.39 and its sine 0.92: each now gets a blend of A and B. That’s why the receiver’s carrier must be locked to the transmitter’s.

You’ve seen a real signal turn into complex numbers before: in the DFT. Feed it a purely real signal and every bin comes out complex. The real part is “how much cosine” and the imaginary part is “how much sine”: size and timing again. An I/Q receiver is one DFT bin, parked at the carrier frequency, worked out again for every sample. I+jQI + jQ is that bin’s value. The signal at the aerial was never complex. The complex number is just a tidy way to write down two measurements of one real wave.

The bandwidth adds up, too. A message on the cosine alone makes two sidebands that are mirror images of each other, so half the band carries nothing new. A second message on the sine makes the two sidebands different, and uses the half that was being wasted. Two messages, each 3 kHz wide, share a band 6 kHz wide.

Sending one message on each knob is quadrature amplitude modulation (QAM). Part 2 uses it to send bits.

Listen:

The square: I against Q over 300 ms: where the arrow’s tip goes. Beside it: I and Q over the same time. Below: the spectrum of I+jQI + jQ, with negative frequencies.

With only the voice on the cosine, at a phase error of 30°: I gets 75.0% of the power and Q gets 25.0%, and together they have all of it (0.0 dB). The arrow goes back and forth along a line, tilted by the phase error. Add a frequency error and the line spins.

Now send the voice on the cosine and the note on the sine. With no phase error, I holds only the voice and Q only the note: each message has its own channel. At 30°, each leaks into the other at −4.8 dB.

Finally, send a single tone 1 kHz above the carrier, then one 1 kHz below it. I alone, which is all section 2’s receiver had, hears a 1 kHz tone either way. The arrow tells them apart: it turns 1000 times a second anticlockwise for the tone above, and clockwise for the tone below. The spectrum shows it at +1 kHz or at −1 kHz.

That last point matters. A real signal’s spectrum always mirrors itself, so its negative frequencies carry nothing new. A complex signal, an arrow spinning one way or the other, can tell +f+f from −f-f. That’s what lets a single sideband be picked out, which is the next step.

5 · The Hilbert transform: a 90° all-pass filter

Section titled “5 · The Hilbert transform: a 90° all-pass filter”

To transmit one sideband only, the transmitter needs a way to shift its message by 90°. Not just one frequency, but every frequency in it at once, without changing any of their levels.

The filter that does this is the Hilbert transform. Any filter that leaves every level alone and changes only phases is an all-pass filter. The Hilbert transform is the ideal one: exactly 90° at every frequency, so a cosine goes in and a sine comes out.

Combined with the message itself, it makes a complex signal with no negative frequencies, the analytic signal: m(t)+j H{m(t)}m(t) + j\,\mathcal{H}\{m(t)\}. Its length is the message’s envelope: the outline traced by the AM receiver in section 3, but for any signal. The finding-signals page used it to draw smooth matched-filter outputs.

The ideal Hilbert transform’s impulse response is h[k]=2πkh[k] = \dfrac{2}{\pi k} for odd kk, and 0 for even kk. It goes on forever in both directions, so it’s impossible to build exactly. There are two ways to approximate it:

For sending one sideband, both errors have the same effect: the unwanted sideband isn’t fully cancelled. A gain ratio gg and a phase error ee leave ∣1−geje∣/∣1+geje∣\left|1 - g e^{je}\right| / \left|1 + g e^{je}\right| of it.

Top: the impulse response: the FIR’s taps, or the two all-pass chains’ responses. Then: the phase error, the gain error, and what they leave of the unwanted sideband, by frequency.

FIR: with a Hann window, 63 taps keep the unwanted sideband below −40 dB only from 1.1 kHz upwards, and leave −7.5 dB of it at worst between 300 Hz and 3 kHz. Low frequencies are the hard part: to shift 300 Hz by 90°, the filter has to see about a cycle or more of it, so it has to be long. 127 taps reach −40 dB from 532 Hz, and 255 taps from 264 Hz. Without a window (rectangular), the gain ripples, as on the FIR page: even 255 taps reach −40 dB only from 1.7 kHz.

IIR: two sections per chain keep the phase within 9.6° of 90° from 100 Hz to 10 kHz, which leaves −22.0 dB of unwanted sideband at worst between 300 Hz and 3 kHz. Each extra section cuts the error by about five: four sections reach 0.40° (−49.2 dB), and five reach 0.09° (−63.3 dB), using only 10 multiplies per sample, against 64 for the 255-tap FIR.

The IIR chains have a catch: they change the phase of every frequency, by a different amount, on both paths. The 90° difference is right, but neither path is the original signal. For a voice that hardly matters, because the ear barely notices phase. But the waveform comes out a different shape.

6 · Single sideband

Section titled “6 · Single sideband”

With a 90° shifter, one sideband can be cancelled. Send the message on the cosine and its Hilbert transform on the sine:

sent(t)=m(t)cos⁡(2πfct)−H{m(t)}sin⁡(2πfct)\text{sent}(t) = m(t)\cos(2\pi f_c t) - \mathcal{H}\{m(t)\}\sin(2\pi f_c t)

For each frequency in the message, the two products give the same lower sideband with opposite signs, so it cancels, and the same upper sideband twice, so it adds up. Flip the sign to keep the lower sideband instead. This is the phasing method, patented by Ralph Hartley in 1928. The other method is to make DSB, then remove one sideband with a very sharp band-pass filter. That’s the filter method, which needs a crystal filter in a real radio.

Single sideband (SSB) fixes both of AM’s problems. It uses half the bandwidth, and all of its power carries the message. Most long-distance voice radio uses it: amateur radio, aircraft over the oceans, and ships.

Speech for SSB is usually cut to 300 Hz – 3 kHz. The phase shifter then doesn’t have to work down to the lowest frequencies, and the ear still hears the voice’s pitch from its harmonics: the missing fundamental.

The receiver is the synchronous detector from section 2, called a product detector here. Its errors now behave quite differently:

Listen:

Top: what’s transmitted: double sideband (grey) for comparison, and SSB (blue). Bottom: what the receiver hears (blue) on top of what was sent (grey).

With the 4 + 4 section IIR shifter, the unwanted sideband for the voice is −52.6 dB down. With an FIR of 63 taps it’s only −16.5 dB, and with 255 taps −56.4 dB. Turn the receiver’s phase error: the level stays at 0.0 dB the whole way, where double sideband went silent at 90°.

Now set the tuning error to +50 Hz with the note. Its 220, 440 and 660 Hz arrive at 270, 490 and 710 Hz. Every harmonic has moved up by 50 Hz, so they’re no longer in the ratio 1 : 2 : 3, and the 2nd is now only 1.815 times the 1st. Listen: a mistuned SSB voice sounds like a cartoon duck, and a note sounds like a bell or a gong.

That cartoon duck is a frequency shifter: everything moved by the same number of hertz. It’s a very different thing from pitch shifting, which multiplies every frequency by the same ratio, so harmonics stay harmonic. Synthesisers have both. The frequency shifter, also called a Bode shifter after the engineer Harald Bode, is the phasing method above, used as an audio effect.

7 · FM: information in the frequency

Section titled “7 · FM: information in the frequency”

Every scheme so far puts the message in the carrier’s size. So anything that changes the size of the received signal changes the sound: noise added on top, a signal that fades as a car moves, a crackle from a lightning strike.

Frequency modulation (FM) puts the message in the carrier’s frequency instead, and keeps its size constant:

frequency(t)=fc+D⋅m(t)\text{frequency}(t) = f_c + D \cdot m(t)

DD is the peak deviation: how far the frequency swings when the message is at its peak. The receiver mixes down to I and Q as in section 4, and measures how fast the arrow turns from one sample to the next. That’s the frequency. The arrow’s length doesn’t come into it, so changes in level don’t matter.

FM’s bandwidth isn’t simply twice the message’s, as for AM. A rule of thumb named after John Carson, Carson’s rule, says about 98% of the power falls within 2(D+ftop)2(D + f_{\text{top}}), where ftopf_{\text{top}} is the message’s highest frequency. The receiver’s filter has to be a bit wider than that, because cutting off the last 2% distorts the sound. This one uses 1.5 times Carson’s width.

The extra bandwidth is the price of FM’s big advantage. Noise moves the arrow’s tip a little in a random direction. If the arrow sweeps through a wide range of angles for the message, as it does with a big deviation, that small random wobble matters less.

Listen:

Top: what arrives, the FM signal plus noise, with Carson’s bandwidth in green. Bottom: 30 ms of what was sent (dashed), and what an FM receiver (blue) and an AM receiver (orange) give back.

The SNR here is the received signal’s power against the noise’s power within the message’s 3 kHz, the same for FM and for AM. With the tone, a deviation of 3 kHz puts 98% of the power within 8.1 kHz, and Carson’s rule says 8.0 kHz.

At an SNR of 20 dB, FM with a deviation of 3 kHz gives 20.1 dB, and AM 14.4 dB. With 5 kHz of deviation, FM reaches 24.4 dB. But turn the SNR down. At 10 dB, FM with 5 kHz of deviation gives 3.4 dB, no better than AM (3.5 dB), and at 8 dB it’s worse (−0.9 dB against 1.0 dB). This is FM’s threshold: once noise can swing the arrow right round the origin, the receiver hears a click. Listen at 8 dB.

Broadcast FM radio uses a deviation of 75 kHz for 15 kHz of audio, so Carson’s width is 180 kHz: twelve times the bandwidth of the audio, spent on a clean sound. Edwin Armstrong showed what wide deviation buys, in 1936.

The capture effect

Section titled “The capture effect”

FM has one more trick. If two FM stations share a frequency, the receiver locks onto the stronger one and almost completely ignores the weaker. The arrow mostly points where the stronger signal says, and the weaker one only nudges it. This is the capture effect, and it’s why aircraft radio (which uses AM) can carry two pilots talking at once, while an FM radio between two stations flips from one to the other.

Listen:

Two stations on the same frequency: A sends the voice, B sends a tune. The readouts say how much each receiver’s output resembles each one (1 = exactly).

With B 6 dB weaker, the FM receiver gives A (0.81) with no trace of B (0.02). The AM receiver gives both (0.75 and 0.68). With B 1 dB weaker, FM still hears only A. With B 1 dB stronger, it switches completely to B (0.77), with no trace of A (0.02). AM just changes the mix.

8 · One receiver for all of them

Section titled “8 · One receiver for all of them”

Every receiver on this page started in the same way: multiply by a cosine and a sine at the station’s frequency, and low-pass the results. That gives I and Q, the arrow. Only the last step differs:

The low-pass filter here does the tuned circuit’s job from section 3. Only the station you’re tuned to lands near 0 Hz, so the low-pass keeps it and removes the rest, with edges much sharper than a coil and a capacitor could manage. Analogue radios do the same thing with the superheterodyne design, which Edwin Armstrong invented in 1918. They mix every station down to one fixed “intermediate” frequency. There, a filter that never has to be retuned, so it can be made both flat and steep-sided, picks out the one you want.

A software-defined radio (SDR) takes the idea all the way. Its hardware does one thing: it mixes a slice of the radio spectrum down to I and Q, and digitises them. Everything else is software, and the same samples can be heard as AM, SSB or FM, or decoded as digital data.

Jump to:
Listen:

A band with three stations: AM (the voice) at 4 kHz, upper-sideband SSB (the note) at 8.5 kHz, and FM (the tune) at 16.5 kHz. The square: I against Q for the tuned station. Beside it: what comes out. Below: the band, with the receiver’s setting marked.

The I/Q plot shows each kind of signal’s shape. The AM station’s arrow points one way and changes in length. The FM station’s arrow keeps the same length, so its tip stays on a circle. The SSB station’s arrow wanders, in both length and angle.

Tuned exactly, in the right mode, each station’s output matches what it sent: 1.00 for AM, 0.99 for SSB and 1.00 for FM. Tune the SSB station just 100 Hz off, and the match drops to 0.01: the cartoon duck again. Listen to the whole band, then to each station.

Summary

Section titled “Summary”

Further reading

Section titled “Further reading”