A Python implementation of an AM (Amplitude Modulation) communication system, exploring DSB-LC and DSB-SC modulation, modulation index effects, and demodulation techniques.
Cairo University — Faculty of Engineering, Computer Engineering Department Course: Communications Engineering (EECG227)
.
├── src/
│ └── voice-sample.wav # Input audio file (mono WAV, 5–10 seconds)
├── outs/ # Generated plots (auto-created on run)
├── part1_modulation.py
├── part2_modulation_index.py
├── part3_envelope_detector.py
├── part4_coherent.py
└── README.md
Implements both DSB-SC and DSB-LC modulation on a real voice signal resampled to 1 MHz, bandlimited to 4 kHz, with a 100 kHz carrier.
- Tests three modulation indices for DSB-LC: μ = 0.5, 0.8, 1.0
- Plots time-domain waveforms with envelope overlay
- Plots frequency-domain magnitude spectra (dB scale)
- Measures 99% power bandwidth for all configurations
Output files: outs/part1_time_domain.png, outs/part1_frequency_domain.png
Key result: All configurations share ~8 kHz bandwidth (= 2 × message bandwidth). DSB-LC shows a discrete carrier spike at f_c; DSB-SC does not.
Studies the effect of μ using a two-tone message signal m(t) = cos(2π·500t) + cos(2π·1200t).
- Tests μ = 0.3, 0.5, 0.8, 1.0, 1.2
- Computes power efficiency:
η = Pm / (Ac² + Pm) × 100% - Highlights overmodulation (μ > 1) with shaded regions
Output files:
outs/part2_fig1_time_domain_all_mu.png— all five waveformsouts/part2_fig2_waveforms_subset.png— μ = 0.5, 1.0, 1.2 side-by-sideouts/part2_fig3_efficiency_vs_mu.png— efficiency vs. modulation index curve
| μ | Ac | η (%) | Status |
|---|---|---|---|
| 0.3 | 3.33 | 2.2% | Normal |
| 0.5 | 2.00 | 5.9% | Normal |
| 0.8 | 1.25 | 13.8% | Normal (recommended) |
| 1.0 | 1.00 | 20.0% | Critical |
| 1.2 | 0.83 | 26.5% | Overmodulated |
Implements an envelope detector for DSB-LC (μ = 0.8):
- Rectify:
|s(t)| - Low-pass filter to remove carrier ripple
- DC removal (subtract mean)
- Compares three LPF cutoff frequencies: 1 kHz (too low), 15 kHz (optimal), 150 kHz (too high)
- Demonstrates why envelope detection fails on DSB-SC
Output files:
outs/part3_fig1_optimal.png— demodulated vs. original (15 kHz LPF)outs/part3_fig2_cutoff_comparison.png— effect of cutoff frequencyouts/part3_fig3_dsbsc_fails.png— DSB-LC success vs. DSB-SC failure
Implements coherent detection for both DSB-SC and DSB-LC:
- Multiply by
2·cos(2πf_c t) - Low-pass filter
- DC removal (for DSB-LC only)
Compares coherent and envelope detector performance using MSE.
Output files:
outs/part4_fig1_coherent_sc_lc.png— coherent demodulation for both schemesouts/part4_fig2_coherent_vs_envelope.png— coherent vs. envelope detector
| Detector | MSE |
|---|---|
| Coherent (DSB-SC) | ~0.000003 |
| Coherent (DSB-LC) | ~0.000007 |
| Envelope (DSB-LC, 8 kHz) | ~0.001044 |
numpy
scipy
matplotlib
Install with:
pip install numpy scipy matplotlibPlace your audio file at src/voice-sample.wav (mono WAV, 5–10 seconds), then run each part independently:
python part1_modulation.py
python part2_modulation_index.py
python part3_envelope_detector.py
python part4_coherent.pyPlots are saved automatically to the outs/ directory.
| Parameter | Value |
|---|---|
| Carrier frequency | 100 kHz |
| Message bandwidth | 4 kHz |
| Sample rate (P1) | 1 MHz |
| Sample rate (P2–4) | 500 kHz |
| Modulation index | μ = 0.8 (default) |