Digital Communication - 06082025.EXPERIMENT - 2
Digital Communication - 06082025.EXPERIMENT - 2
DATE: 06-08-2025
AIM:
Write a python code to get one binary stream as input and generate Waveforms of
Unipolar NRZ, Unipolar RZ, Polar NRZ, Polar RZ, Alternate Mark Inversion and
Manchester line codes. Generate the spectrum in frequency domain for each of the above
codes as well.
SOFTWARE USED:
Google Colab
THEORY:
In digital communication systems, binary data must be represented in the form of electrical
waveforms for transmission over a medium. This process is achieved using line coding
techniques, which convert a binary sequence into a suitable format of voltage pulses. Different
line codes have unique characteristics in terms of bandwidth requirement, synchronization
capability, error detection, and DC content.
● Unipolar NRZ represents a logic ‘1’ by a constant positive voltage and logic ‘0’ by zero
voltage throughout the bit duration.
● Unipolar RZ uses a positive voltage for ‘1’ only in the first half of the bit interval and
returns to zero in the second half, ensuring a mid-bit transition.
● Polar NRZ assigns positive voltage to ‘1’ and negative voltage to ‘0’ for the entire bit
duration.
● Polar RZ uses positive or negative voltage for the first half of the bit duration depending
on the bit value, and returns to zero for the second half.
● Alternate Mark Inversion (AMI) represents binary ‘1’ by alternating between positive
and negative voltages, while ‘0’ is represented by zero. This reduces DC content.
CODE:
import numpy as np
import matplotlib.pyplot as plt
# Time axis
t = np.linspace(0, len(binary_stream), len(binary_stream) * samples,
endpoint=False)
def unipolar_rz(data):
signal = np.zeros(len(data) * samples)
for i, bit in enumerate(data):
if bit == 1:
signal[i*samples : i*samples + samples//2] = 1
return signal
def polar_nrz(data):
signal = np.repeat([1 if bit == 1 else -1 for bit in data],
samples)
return signal
def polar_rz(data):
signal = np.zeros(len(data) * samples)
for i, bit in enumerate(data):
if bit == 1:
signal[i*samples : i*samples + samples//2] = 1
else:
signal[i*samples : i*samples + samples//2] = -1
return signal
def ami(data):
signal = np.zeros(len(data) * samples)
polarity = 1
for i, bit in enumerate(data):
if bit == 1:
signal[i*samples : i*samples + samples] = polarity
polarity *= -1
return signal
def manchester(data):
signal = np.zeros(len(data) * samples)
for i, bit in enumerate(data):
if bit == 1:
signal[i*samples : i*samples + samples//2] = 1
signal[i*samples + samples//2 : (i+1)*samples] = -1
else:
signal[i*samples : i*samples + samples//2] = -1
signal[i*samples + samples//2 : (i+1)*samples] = 1
return signal
plt.figure(figsize=(12, 16))
# Frequency domain
plt.subplot(len(codes), 2, 2*idx+2)
plot_spectrum(signal, samples, name)
plt.tight_layout()
plt.show()
RESULT:
CONCLUSION:
In this experiment, various line coding techniques such as Unipolar NRZ, Unipolar RZ, Polar
NRZ, Polar RZ, Alternate Mark Inversion (AMI), and Manchester coding were successfully
implemented using Python. The corresponding time-domain waveforms were generated for a
given binary input, and their frequency-domain spectra were also plotted. From the results, it can
be observed that each coding scheme has distinct waveform characteristics and spectral
properties, making them suitable for different communication scenarios. This experiment
highlights the importance of line coding in digital communication systems for reliable
transmission and efficient bandwidth utilization.