FM Modulation with Python: Code and Explanation

fm modulation
python
analog modulation
signal processing
communication system

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.

frequency modulation

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:

e_FM=Acsin[Wct+mfsin(Wmt)]e\_{FM} = A_c \cdot sin[W_c \cdot t + m_f \cdot sin(W_m \cdot t)]

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.

FM modulation python plots

AM Modulation Simulation with Python

AM Modulation Simulation with Python

Simulate Amplitude Modulation (AM) and demodulation using Python. Includes code for generating AM modulated data and demonstrating AM demodulation.

am modulation
signal processing
python
FSK Modulation Implementation in Python

FSK Modulation Implementation in Python

This article provides Python code for Frequency Shift Keying (FSK) modulation, generating an FSK modulated waveform from binary data.

fsk
modulation
python
Communication Systems in Electronics: An Overview

Communication Systems in Electronics: An Overview

Explore the fundamentals of communication systems in electronics, covering types, components, and applications in wireless and wired technologies.

communication system
wireless network
signal processing
ASK Modulation in Python: Code and Explanation

ASK Modulation in Python: Code and Explanation

Explore Amplitude Shift Keying (ASK) modulation using Python. Includes code, explanation of principles, and waveform visualizations for digital data transmission.

ask modulation
python
signal processing