0% found this document useful (0 votes)
7 views14 pages

Binary Signal Modulation Techniques

The document contains multiple source code snippets that demonstrate various digital signaling techniques including Unipolar NRZ, Polar NRZ, Unipolar RZ, Bipolar RZ, Manchester encoding, and modulation techniques like ASK, FSK, PSK, and QPSK. Each code snippet generates a corresponding signal based on binary input data and visualizes it using matplotlib. The document serves as a practical guide for understanding and implementing different digital communication methods.

Uploaded by

hossainemon5821
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Binary Signal Modulation Techniques

The document contains multiple source code snippets that demonstrate various digital signaling techniques including Unipolar NRZ, Polar NRZ, Unipolar RZ, Bipolar RZ, Manchester encoding, and modulation techniques like ASK, FSK, PSK, and QPSK. Each code snippet generates a corresponding signal based on binary input data and visualizes it using matplotlib. The document serves as a practical guide for understanding and implementing different digital communication methods.

Uploaded by

hossainemon5821
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Source code:

import numpy as np
import [Link] as plt

# Binary input (you can change this)


data = [1, 0, 1, 1, 0, 0, 1]

# Duration setup
bit_duration = 1 # 1 second per bit (for simplicity)
samples_per_bit = 100 # Resolution (samples per bit)
total_samples = len(data) * samples_per_bit

# Time axis
t = [Link](0, len(data) * bit_duration, total_samples)

# Signal generation
signal = []

for bit in data:


if bit == 1:
[Link]([1] * samples_per_bit)
else:
[Link]([0] * samples_per_bit)

# Plotting
[Link](figsize=(10, 3))
[Link](t, signal, linewidth=2, color='blue')
[Link]("Unipolar NRZ Signaling")
[Link]("Time")
[Link]("Amplitude")
[Link](-1.5, 1.5)
[Link](True)
# [Link]([Link](0, len(data) + 1, 1))
# [Link]([0, 1])
[Link]()
Source Code:

import numpy as np
import [Link] as plt

# Input binary data


data = [1, 0, 1, 1, 0, 0, 1]
bit_duration = 1 # Assume 1 second per bit
samples_per_bit = 100
t = [Link](0, bit_duration * len(data), samples_per_bit * len(data))

# Generate Polar NRZ signal


signal = [Link](len(t))
for i, bit in enumerate(data):
start = i * samples_per_bit
end = start + samples_per_bit
if bit == 1:
signal[start:end] = 1
else:
signal[start:end] = -1

# Plot the waveform


[Link](figsize=(10, 3))
[Link](t, signal, linewidth=2)
[Link]("Polar NRZ Signaling")
[Link]("Time")
[Link]("Amplitude")
[Link]([-1.5, 1.5])
[Link](True)
[Link]([Link](0, len(data)+1, 1))
[Link]([-1, 0, 1])
[Link]()
Source Code:

import numpy as np
import [Link] as plt

# Binary input (you can change this)


data = [1, 0, 1, 1, 0, 0, 1]

# Parameters
bit_duration = 1 # seconds per bit
samples_per_bit = 100 # resolution
total_samples = len(data) * samples_per_bit
t = [Link](0, len(data) * bit_duration, total_samples)

# Signal generation
signal = []

for bit in data:


if bit == 1:
# First half high, second half zero
[Link]([1] * (samples_per_bit // 2))
[Link]([0] * (samples_per_bit // 2))
else:
# Full bit duration zero
[Link]([0] * samples_per_bit)

# Plotting
[Link](figsize=(10, 3))
[Link](t, signal, linewidth=2, color='green')
[Link]("Unipolar RZ (Return-to-Zero) Signaling")
[Link]("Time")
[Link]("Amplitude")
[Link](-0.5, 1.5)
[Link](True)
[Link]([Link](0, len(data) + 1, 1))
[Link]([0, 1])
[Link]()
Source Code:

import numpy as np
import [Link] as plt

# Input binary data


data = [1, 0, 1, 1, 0, 0, 1]
bit_duration = 1 # Assume 1 second for simplicity
samples_per_bit = 100
t = [Link](0, bit_duration * len(data), samples_per_bit * len(data))

# Generate bipolar RZ signal


signal = [Link](len(t))
polarity = 1 # Start with positive voltage for first '1'
for i, bit in enumerate(data):
start = i * samples_per_bit
mid = start + samples_per_bit // 2
if bit == 1:
signal[start:mid] = polarity
polarity *= -1 # Alternate polarity for next 1

# Plot the waveform


[Link](figsize=(10, 3))
[Link](t, signal, linewidth=2)
[Link]("Bipolar RZ Signaling")
[Link]("Time")
[Link]("Amplitude")
[Link]([-1.5, 1.5])
[Link](True)
[Link]([Link](0, len(data)+1, 1))
[Link]([-1, 0, 1])
[Link]()
Source Code:

import numpy as np
import [Link] as plt

# Input binary data


data = [1, 0, 1, 1, 0, 0, 1]
bit_duration = 1 # Duration of one bit (in seconds)
samples_per_bit = 100 # Number of samples per bit

# Time vector for entire signal


t = [Link](0, bit_duration * len(data), samples_per_bit * len(data))

# Generate Manchester encoded signal


signal = [Link](len(t))
for i, bit in enumerate(data):
start = i * samples_per_bit
mid = start + samples_per_bit // 2
end = start + samples_per_bit
if bit == 1:
# For '1': High-to-Low transition
signal[start:mid] = 1
signal[mid:end] = -1
else:
# For '0': Low-to-High transition
signal[start:mid] = -1
signal[mid:end] = 1

# Plotting the Manchester waveform


[Link](figsize=(10, 3))
[Link](t, signal, linewidth=2)
[Link]("Split-Phase (Manchester) Signaling")
[Link]("Time")
[Link]("Amplitude")
[Link]([-1.5, 1.5])
[Link](True)
[Link]([Link](0, len(data) + 1, 1))
[Link]([-1, 0, 1])
[Link]()
Source Code:

import numpy as np
import [Link] as plt

data_str = input("Enter binary data (e.g., 1010101): ")


x = [int(bit) for bit in data_str if bit in '01']

bp = 1e-6
A1, A2 = 10, 5
f = (1 / bp) * 10
samples = 100
t_bit = [Link](0, bp, samples)
t_total = [Link](0, bp * len(x), len(x) * samples)
digital_signal = [Link](x, samples)
modulated = [Link]([
(A1 if bit else A2) * [Link](2 * [Link] * f * t_bit)
for bit in x
])
carrier = [Link](2 * [Link] * f * t_bit)
recovered = [
1 if (2 * [Link](modulated[i:i+samples] * carrier, t_bit) / bp) > 7.5 else 0
for i in range(0, len(modulated), samples)
]
received_signal = [Link](recovered, samples)

[Link](figsize=(12, 8))
[Link](3, 1, 1)
[Link](t_total, digital_signal, lw=2.5)
[Link]("Transmitting Information as Digital Signal")
[Link]("Amplitude"); [Link](True); [Link](-0.5, 1.5)

[Link](3, 1, 2)
[Link](t_total, modulated)
[Link]("Waveform for Binary ASK Modulation")
[Link]("Amplitude"); [Link](True)

[Link](3, 1, 3)
[Link](t_total, received_signal, lw=2.5)
[Link]("Received Information as Digital Signal")
[Link]("Time (sec)"); [Link]("Amplitude"); [Link](True); [Link](-0.5, 1.5)

plt.tight_layout()
[Link]()

print("Transmitted Data: ", x)


print("Received Data: ", recovered)
Source Code:

import numpy as np
import [Link] as plt

data_str = input("Enter binary data (e.g., 1011001): ")


x = [int(bit) for bit in data_str if bit in '01']

bp = 1e-6
A=5
f1 = 10 / bp
f2 = 5 / bp
samples = 100
t_bit = [Link](0, bp, samples, endpoint=False)
t_total = [Link](0, bp * len(x), len(x) * samples, endpoint=False)

digital_signal = [Link](x, samples)

modulated = [Link]([
A * [Link](2 * [Link] * (f1 if bit else f2) * t_bit) for bit in x
])

recovered = []
for i in range(0, len(modulated), samples):
segment = modulated[i:i+samples]
corr1 = [Link](segment * [Link](2 * [Link] * f1 * t_bit), t_bit)
corr2 = [Link](segment * [Link](2 * [Link] * f2 * t_bit), t_bit)
[Link](1 if corr1 > corr2 else 0)

received_signal = [Link](recovered, samples)

[Link](figsize=(12, 8))

[Link](3, 1, 1)
[Link](t_total, digital_signal, lw=2.5)
[Link]("Transmitting Information as Digital Signal")
[Link]("Amplitude")
[Link](True)
[Link](-0.5, 1.5)

[Link](3, 1, 2)
[Link](t_total, modulated)
[Link]("Waveform for Binary FSK Modulation")
[Link]("Amplitude")
[Link](True)

[Link](3, 1, 3)
[Link](t_total, received_signal, lw=2.5)
[Link]("Received Information as Digital Signal")
[Link]("Time (sec)")
[Link]("Amplitude")
[Link](True)
[Link](-0.5, 1.5)

plt.tight_layout()
[Link]()

print("Transmitted Data: ", x)


print("Received Data: ", recovered)
Source Code:

import numpy as np
import [Link] as plt

data_str = input("Enter binary data (e.g., 1100101): ")


x = [int(bit) for bit in data_str if bit in '01']

bp = 1e-6
A=5
fc = 2 / bp
samples = 100
t_bit = [Link](0, bp, samples, endpoint=False)
t_total = [Link](0, bp * len(x), len(x) * samples, endpoint=False)

digital_signal = [Link](x, samples)

modulated = [Link]([
A * [Link](2 * [Link] * fc * t_bit) if bit == 1 else
-A * [Link](2 * [Link] * fc * t_bit) for bit in x
])

recovered = []
for i in range(0, len(modulated), samples):
segment = modulated[i:i+samples]
ref = A * [Link](2 * [Link] * fc * t_bit)
product = segment * ref
integral = [Link](product, t_bit)
[Link](1 if integral > 0 else 0)

received_signal = [Link](recovered, samples)

[Link](figsize=(12, 8))

[Link](3, 1, 1)
[Link](t_total, digital_signal, lw=2.5)
[Link]("Transmitting Information as Digital Signal")
[Link]("Amplitude")
[Link](True)
[Link](-0.5, 1.5)

[Link](3, 1, 2)
[Link](t_total, modulated)
[Link]("Waveform for Binary PSK Modulation")
[Link]("Amplitude")
[Link](True)

[Link](3, 1, 3)
[Link](t_total, received_signal, lw=2.5)
[Link]("Received Information as Digital Signal")
[Link]("Time (sec)")
[Link]("Amplitude")
[Link](True)
[Link](-0.5, 1.5)

plt.tight_layout()
[Link]()

print("Transmitted Data: ", x)


print("Received Data: ", recovered)
Source Code:

import numpy as np
import [Link] as plt

binary_input = input("Enter binary data (e.g., 10100101): ")


x = [Link]([int(bit) for bit in binary_input])
print("Input bits:", x)

p = [Link](x == 0, -1, 1)

even_seq = p[::2]
odd_seq = p[1::2]

bit_duration = 2
t = [Link](0, len(p), 0.01)
even_ps = np.zeros_like(t)
odd_ps = np.zeros_like(t)

for i in range(len(even_seq)):
start = int((bit_duration * i) / 0.01)
end = int((bit_duration * (i + 1)) / 0.01)
even_ps[start:end] = even_seq[i]

for i in range(len(odd_seq)):
start = int((bit_duration * i) / 0.01)
end = int((bit_duration * (i + 1)) / 0.01)
odd_ps[start:end] = odd_seq[i]

[Link](figsize=(10, 6))

[Link](2,1,1)
[Link](t, even_ps, 'r')
[Link]('NRZ Polar Line Coded Signal - Even Bits')
[Link]('Amplitude')
[Link](True)

[Link](2,1,2)
[Link](t, odd_ps, 'b')
[Link]('NRZ Polar Line Coded Signal - Odd Bits')
[Link]('Time')
[Link]('Amplitude')
[Link](True)

plt.tight_layout()
[Link]()
c1 = [Link](2 * [Link] * 1 * t)
c2 = [Link](2 * [Link] * 1 * t)

[Link](figsize=(10, 4))

[Link](2,1,1)
[Link](t, c1, 'r')
[Link]('Cosine Carrier Signal')
[Link](True)

[Link](2,1,2)
[Link](t, c2, 'b')
[Link]('Sine Carrier Signal')
[Link](True)

plt.tight_layout()
[Link]()

r1 = even_ps * c1
r2 = odd_ps * c2
qpsk = r1 - r2

[Link](figsize=(10, 6))

[Link](3,1,1)
[Link](t, r1, 'r')
[Link]('I-component (Even × Cosine)')
[Link](True)

[Link](3,1,2)
[Link](t, r2, 'b')
[Link]('Q-component (Odd × Sine)')
[Link](True)

[Link](3,1,3)
[Link](t, qpsk, 'k')
[Link]('QPSK Signal (I - Q)')
[Link]('Time')
[Link](True)

plt.tight_layout()
[Link]()
Source Code:

import numpy as np
import [Link] as plt

# Define parameters
fs = 1000 # Sampling frequency
t = [Link](0, 1, 1/fs) # Time vector
fm = 5 # Message signal frequency
fc = 50 # Carrier signal frequency

# Generate message signal (sine wave)


message_signal = [Link](2 * [Link] * fm * t)

# Generate carrier signal (pulse train)


carrier_signal = np.zeros_like(t)
pulse_width = 0.01 # Adjust pulse width as needed
for i in range(len(t)):
if t[i] % (1/fc) < pulse_width:
carrier_signal[i] = 1

# Perform PAM
pam_signal = message_signal * carrier_signal

# Plot signals
[Link](figsize=(12, 6))

[Link](3, 1, 1)
[Link](t, message_signal)
[Link]('Message Signal')
[Link]('Time (s)')
[Link]('Amplitude')

[Link](3, 1, 2)
[Link](t, carrier_signal)
[Link]('Carrier Signal (Pulse Train)')
[Link]('Time (s)')
[Link]('Amplitude')

[Link](3, 1, 3)
[Link](t, pam_signal)
[Link]('PAM Signal')
[Link]('Time (s)')
[Link]('Amplitude')

plt.tight_layout()
[Link]()

You might also like