FM Modulation with Python: Code and Explanation
Advertisement
This article provides a guide to simulating Frequency Modulation (FM) using Python. It includes both the FM modulation and demodulation Python code.
Introduction
Modulation techniques are broadly classified into two categories:
- Analog Modulation: The baseband information or message signal is analog in nature.
- Digital Modulation: The baseband information or message signal is digital in nature (i.e., binary).
Common analog modulation types include AM, FM, and PM. Digital modulation types include ASK, FSK, and PSK.
Unlike Frequency-Shift Keying (FSK), FM modulation utilizes an analog message signal. FSK, on the other hand, uses binary digital data as input.

The figure above illustrates the frequency modulation process. As shown, it uses an analog signal as the modulating, message, or baseband signal. It produces an FM modulated signal where the frequency of the RF carrier varies according to the frequency of the modulating signal. To illustrate this concept in a Python simulation, we will create a modulating signal with two distinct frequencies, ‘F1’ and ‘F2’.
The following formula describes the FM modulation process:
FM Modulation and Demodulation Python Script
The following Python script can be used to generate FM modulated data. The script also includes FM demodulation functionality.
# FM Modulation Python Script
import numpy as np
import matplotlib.pyplot as plt
from math import pi
plt.close('all')
# Setting up FM modulation simulation parameters
Fs = 2000 # Sampling Frequency
t = np.arange(0,0.2,1/Fs) # Time vector
fc = 100 # carrier frequency
fm1 = 30 # Signal frequency-1 to construct message signal
fm2 = 45 # Signal frequency-2 to construct message signal
b = 1 # modulation index
# Creating the message signal
m_signal = np.sin(2*pi*fm1*t) + np.sin(2*pi*fm2*t)
# Creating the carrier signal
carrier_signal = np.sin(2 * pi * fc * t)
# Generate Frequency modulated signal
fmd = np.sin(2*pi*fc*t + b*m_signal)
# Plots
plt.subplot(3,1,1)
plt.plot(t, m_signal)
plt.title("Analog Message signal")
plt.subplot(3,1,2)
plt.plot(t, carrier_signal)
plt.title("RF carrier signal")
plt.subplot(3,1,3)
plt.plot(t, fmd)
plt.title("Frequency Modulated Signal")
plt.tight_layout()
plt.show()
Output Plots of FM Modulation Python Code
The following are the output plots generated by the FM modulation Python script shown above.

Explore Python Codes on Wireless Communication & Modulation Simulations
- AM Modulation Simulation in Python
- PM Modulation with Python
- ASK Modulation in Python
- FSK Modulation in Python
- PSK Modulation in Python
- BPSK, QPSK, QAM Modulation in Python
- QPSK Mapper / Demapper Python Code
- OFDM Transmitter Simulation in Python (WiMAX)
- Generalized OFDMA Simulation with Python
Continue Learning Modulation Types
- AM Vs. FM Vs. PM : Difference between Analog Modulation Techniques
- ASK Vs. FSK Vs. PSK : Difference between Digital Modulation Techniques
- PAM Vs. PWM Vs. PPM : Difference between Pulse Modulation Techniques
- BPSK Vs. QPSK : Key Differences
- 16-QAM Vs. 64-QAM Vs. 256-QAM : Key Differences
- 512-QAM Vs. 1024-QAM Vs. 2048-QAM Vs. 4096-QAM
- 4096QAM Modulation Used in Wi-Fi 7
- MSK Vs. GMSK : Modulation Technique used in GSM
- LORa Modulation Used in LoRaWAN
- 10% ASK & 100% ASK Modulation used in NFC
- OOK Vs. VPPM Vs. CSK : Visible Light Communication (VLC) Modulation Techniques
- QPSK Vs. OQPSK Vs. PI/4 QPSK
- PAM4 Modulation Used in Gigabit Ethernet
- CCK Vs. DSSS Vs. OFDM Used in WLAN (Wi-Fi) Standards
