Source code
Source code
import numpy as np
import matplotlib.pyplot as plt
# 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 = np.linspace(0, len(data) * bit_duration, total_samples)
# Signal generation
signal = []
# Plotting
plt.figure(figsize=(10, 3))
plt.plot(t, signal, linewidth=2, color='blue')
plt.title("Unipolar NRZ Signaling")
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.ylim(-1.5, 1.5)
plt.grid(True)
# plt.xticks(np.arange(0, len(data) + 1, 1))
# plt.yticks([0, 1])
plt.show()
Source Code:
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
# Parameters
bit_duration = 1 # seconds per bit
samples_per_bit = 100 # resolution
total_samples = len(data) * samples_per_bit
t = np.linspace(0, len(data) * bit_duration, total_samples)
# Signal generation
signal = []
# Plotting
plt.figure(figsize=(10, 3))
plt.plot(t, signal, linewidth=2, color='green')
plt.title("Unipolar RZ (Return-to-Zero) Signaling")
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.ylim(-0.5, 1.5)
plt.grid(True)
plt.xticks(np.arange(0, len(data) + 1, 1))
plt.yticks([0, 1])
plt.show()
Source Code:
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
bp = 1e-6
A1, A2 = 10, 5
f = (1 / bp) * 10
samples = 100
t_bit = np.linspace(0, bp, samples)
t_total = np.linspace(0, bp * len(x), len(x) * samples)
digital_signal = np.repeat(x, samples)
modulated = np.concatenate([
(A1 if bit else A2) * np.cos(2 * np.pi * f * t_bit)
for bit in x
])
carrier = np.cos(2 * np.pi * f * t_bit)
recovered = [
1 if (2 * np.trapz(modulated[i:i+samples] * carrier, t_bit) / bp) > 7.5 else 0
for i in range(0, len(modulated), samples)
]
received_signal = np.repeat(recovered, samples)
plt.figure(figsize=(12, 8))
plt.subplot(3, 1, 1)
plt.plot(t_total, digital_signal, lw=2.5)
plt.title("Transmitting Information as Digital Signal")
plt.ylabel("Amplitude"); plt.grid(True); plt.ylim(-0.5, 1.5)
plt.subplot(3, 1, 2)
plt.plot(t_total, modulated)
plt.title("Waveform for Binary ASK Modulation")
plt.ylabel("Amplitude"); plt.grid(True)
plt.subplot(3, 1, 3)
plt.plot(t_total, received_signal, lw=2.5)
plt.title("Received Information as Digital Signal")
plt.xlabel("Time (sec)"); plt.ylabel("Amplitude"); plt.grid(True); plt.ylim(-0.5, 1.5)
plt.tight_layout()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
bp = 1e-6
A=5
f1 = 10 / bp
f2 = 5 / bp
samples = 100
t_bit = np.linspace(0, bp, samples, endpoint=False)
t_total = np.linspace(0, bp * len(x), len(x) * samples, endpoint=False)
modulated = np.concatenate([
A * np.cos(2 * np.pi * (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 = np.trapz(segment * np.cos(2 * np.pi * f1 * t_bit), t_bit)
corr2 = np.trapz(segment * np.cos(2 * np.pi * f2 * t_bit), t_bit)
recovered.append(1 if corr1 > corr2 else 0)
plt.figure(figsize=(12, 8))
plt.subplot(3, 1, 1)
plt.plot(t_total, digital_signal, lw=2.5)
plt.title("Transmitting Information as Digital Signal")
plt.ylabel("Amplitude")
plt.grid(True)
plt.ylim(-0.5, 1.5)
plt.subplot(3, 1, 2)
plt.plot(t_total, modulated)
plt.title("Waveform for Binary FSK Modulation")
plt.ylabel("Amplitude")
plt.grid(True)
plt.subplot(3, 1, 3)
plt.plot(t_total, received_signal, lw=2.5)
plt.title("Received Information as Digital Signal")
plt.xlabel("Time (sec)")
plt.ylabel("Amplitude")
plt.grid(True)
plt.ylim(-0.5, 1.5)
plt.tight_layout()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
bp = 1e-6
A=5
fc = 2 / bp
samples = 100
t_bit = np.linspace(0, bp, samples, endpoint=False)
t_total = np.linspace(0, bp * len(x), len(x) * samples, endpoint=False)
modulated = np.concatenate([
A * np.cos(2 * np.pi * fc * t_bit) if bit == 1 else
-A * np.cos(2 * np.pi * fc * t_bit) for bit in x
])
recovered = []
for i in range(0, len(modulated), samples):
segment = modulated[i:i+samples]
ref = A * np.cos(2 * np.pi * fc * t_bit)
product = segment * ref
integral = np.trapz(product, t_bit)
recovered.append(1 if integral > 0 else 0)
plt.figure(figsize=(12, 8))
plt.subplot(3, 1, 1)
plt.plot(t_total, digital_signal, lw=2.5)
plt.title("Transmitting Information as Digital Signal")
plt.ylabel("Amplitude")
plt.grid(True)
plt.ylim(-0.5, 1.5)
plt.subplot(3, 1, 2)
plt.plot(t_total, modulated)
plt.title("Waveform for Binary PSK Modulation")
plt.ylabel("Amplitude")
plt.grid(True)
plt.subplot(3, 1, 3)
plt.plot(t_total, received_signal, lw=2.5)
plt.title("Received Information as Digital Signal")
plt.xlabel("Time (sec)")
plt.ylabel("Amplitude")
plt.grid(True)
plt.ylim(-0.5, 1.5)
plt.tight_layout()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
p = np.where(x == 0, -1, 1)
even_seq = p[::2]
odd_seq = p[1::2]
bit_duration = 2
t = np.arange(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]
plt.figure(figsize=(10, 6))
plt.subplot(2,1,1)
plt.plot(t, even_ps, 'r')
plt.title('NRZ Polar Line Coded Signal - Even Bits')
plt.ylabel('Amplitude')
plt.grid(True)
plt.subplot(2,1,2)
plt.plot(t, odd_ps, 'b')
plt.title('NRZ Polar Line Coded Signal - Odd Bits')
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.grid(True)
plt.tight_layout()
plt.show()
c1 = np.cos(2 * np.pi * 1 * t)
c2 = np.sin(2 * np.pi * 1 * t)
plt.figure(figsize=(10, 4))
plt.subplot(2,1,1)
plt.plot(t, c1, 'r')
plt.title('Cosine Carrier Signal')
plt.grid(True)
plt.subplot(2,1,2)
plt.plot(t, c2, 'b')
plt.title('Sine Carrier Signal')
plt.grid(True)
plt.tight_layout()
plt.show()
r1 = even_ps * c1
r2 = odd_ps * c2
qpsk = r1 - r2
plt.figure(figsize=(10, 6))
plt.subplot(3,1,1)
plt.plot(t, r1, 'r')
plt.title('I-component (Even × Cosine)')
plt.grid(True)
plt.subplot(3,1,2)
plt.plot(t, r2, 'b')
plt.title('Q-component (Odd × Sine)')
plt.grid(True)
plt.subplot(3,1,3)
plt.plot(t, qpsk, 'k')
plt.title('QPSK Signal (I - Q)')
plt.xlabel('Time')
plt.grid(True)
plt.tight_layout()
plt.show()
Source Code:
import numpy as np
import matplotlib.pyplot as plt
# Define parameters
fs = 1000 # Sampling frequency
t = np.arange(0, 1, 1/fs) # Time vector
fm = 5 # Message signal frequency
fc = 50 # Carrier signal frequency
# Perform PAM
pam_signal = message_signal * carrier_signal
# Plot signals
plt.figure(figsize=(12, 6))
plt.subplot(3, 1, 1)
plt.plot(t, message_signal)
plt.title('Message Signal')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.subplot(3, 1, 2)
plt.plot(t, carrier_signal)
plt.title('Carrier Signal (Pulse Train)')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.subplot(3, 1, 3)
plt.plot(t, pam_signal)
plt.title('PAM Signal')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.tight_layout()
plt.show()