QPSK Mapper and Demapper Python Code
Advertisement
This document provides Python code for QPSK mapping and QPSK demapping, which are fundamental processes in digital communication systems.
Introduction:
QPSK, or Quadrature Phase Shift Keying, is a digital modulation technique used to increase data rate by transmitting two bits per symbol. This is achieved by mapping two binary digits onto a single RF carrier.
QPSK mapper
The figure above illustrates the QPSK data constellation and the QPSK mapping process. The QPSK demapper performs the inverse operation of the QPSK mapper, recovering the original binary data.
QPSK Mapping and Demapping Python Script
The following Python code implements QPSK mapping and demapping, allowing you to map digital binary data to QPSK constellation points and vice versa.
import random
import numpy as np
import matplotlib.pyplot as plt
len1 = 48 # length of input data
mode = 2 # QPSK 2 bits per sub carrier
mapping_table = {
0: 0.7071 + 0.7071j,
1: -0.7071 + 0.7071j,
2: 0.7071 - 0.7071j,
3: -0.7071 - 0.7071j
}
dec_binary = {
0: '00',
1: '01',
2: '10',
3: '11'
}
# Binary random data generator (1s and 0s)
input_data = ""
for i in range(len1):
temp1 = str(random.randint(0, 1))
input_data += temp1
print("Mapper IN, Input Binary string :", input_data)
# Conversion of bits to dual bits and integer list
s1 = input_data
s2_user1 = []
chunks = [s1[i:i+mode] for i in range(0, len(s1), mode)]
for piece in chunks:
temp = int(piece, 2)
s2_user1.append(temp)
print("Input integer list :", s2_user1)
# QPSK mapping part
Q = np.zeros((24,), dtype=complex)
j = 0
for val in s2_user1:
Q[j] = mapping_table[val]
j += 1
print("QPSK mapper output complex list", Q)
# QPSK de-mapping part
Q1 = np.zeros((24,), dtype=int)
j = 0
for i in Q:
if i == 0.7071+0.7071j:
Q1[j] = 0
elif i == -0.7071+0.7071j:
Q1[j] = 1
elif i == 0.7071-0.7071j:
Q1[j] = 2
elif i == -0.7071-0.7071j:
Q1[j] = 3
else:
print("improper i value")
j += 1
print("De-mapper Output integer list:", Q1)
# Converting integer to bits
output_data = ""
j = 0
for val in Q1:
output_data += dec_binary[val]
j += 1
print("De-mapper OUT, Output Binary String:", output_data)
plt.plot(s2_user1-Q1)
plt.title("Difference between input and output integer data")
plt.show()
QPSK Mapper Python Output and Plots
The following showcases the outputs generated by the QPSK Python code at various stages. It illustrates the mapper’s binary input, corresponding integer list, the QPSK mapped output, the de-mapper’s integer output, and the final de-mapper’s binary output.

The plot below demonstrates the difference between the mapper’s input (integer array list) and the demapper’s output (integer array list). As the plot indicates, the output remains at zero, signifying that both inputs and outputs have matching values.

Explore Python Codes on Wireless Communication & Modulation Simulations
- AM Modulation Simulation in Python
- FM Modulation in Python
- PM Modulation with Python
- ASK Modulation in Python
- FSK Modulation in Python
- PSK Modulation in Python
- BPSK, QPSK, QAM Modulation in Python
- OFDM Transmitter Simulation in Python (WiMAX)
- Generalized OFDMA Simulation with Python
Continue Learning Python Basics
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
