Nanfeng

Notes on software development, code, and curious ideas

AM Modulation and Demodulation in MATLAB

Amplitude modulation is a useful introduction to how a baseband message changes a carrier and how a receiver recovers that message. In conventional AM with carrier,

[
s(t) = A_c,[1 + \mu m_n(t)]\cos(2\pi f_c t),
]

where the normalized message satisfies |m_n(t)| ≤ 1. Keeping 0 ≤ μ ≤ 1 avoids overmodulation for envelope detection.

Generate the signal

1
2
3
4
5
6
7
8
9
10
11
12
fs = 100e3;
duration = 0.05;
t = (0:1/fs:duration-1/fs)';

fm = 500;
fc = 10e3;
Ac = 1;
mu = 0.7;

message = cos(2*pi*fm*t);
carrier = cos(2*pi*fc*t);
am = Ac * (1 + mu*message) .* carrier;

The sample rate must comfortably exceed twice the highest generated frequency.

Envelope detection

1
2
3
analyticSignal = hilbert(am);
envelope = abs(analyticSignal);
recoveredEnvelope = (envelope / Ac - 1) / mu;

The Hilbert-transform method is an analytical envelope detector. A physical diode detector introduces ripple, thresholds, and an RC time-constant tradeoff.

Coherent demodulation

1
2
3
4
5
mixed = 2 * am .* carrier;
cutoff = 2e3;
order = 120;
b = fir1(order, cutoff/(fs/2));
recoveredCoherent = filter(b, 1, mixed);

Coherent detection requires carrier frequency and phase alignment. The FIR filter introduces group delay that should be compensated before waveform comparison.

Noise and spectrum analysis

Add controlled white noise with a documented signal-to-noise ratio, then run both demodulators and compare mean-squared error or output SNR. Plot a properly scaled FFT or use periodogram to show the carrier at fc and sidebands at fc ± fm.

This simulation demonstrates principles, not a complete radio receiver. Real systems also face bandwidth limits, oscillator error, nonlinear stages, fading, interference, automatic gain control, and filtering constraints.

+