Practical BPSK Communication Python and Theory Part3
Practical BPSK Communication Python and Theory Part3
This chapter covers the core Python libraries and functions used in the BPSK simulation, with
illustrative code examples and plots.
python
CopyEdit
# Example: time vector for filter design
sps = 8
span = 10
N = span * sps
t = np.arange(-N, N+1) / float(sps)
print(t[:5], t[-5:]) # first and last five samples
Figure 2.1: Illustration of a NumPy arange array for filter time indices.
(Insert your generated plot here.)
python
CopyEdit
rng = np.random.default_rng(seed=42)
bits = rng.integers(0, 2, size=16)
noise = rng.standard_normal(size=1000)
python
CopyEdit
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2, figsize=(8, 6), constrained_layout=True)
axs = axs.flatten()
for ax in axs:
ax.grid(True)
plt.show()
python
CopyEdit
# Example: PSD line and markers
f = np.linspace(-0.5, 0.5, 512)
Pxx = np.abs(np.fft.fftshift(np.random.randn(512)))
axs[0].semilogy(f, Pxx, '-o', markersize=3)
python
CopyEdit
from scipy.signal import upfirdn
# Impulse train (h=[1])
imp = upfirdn([1], symbols, up=sps)
# Pulse shaping (h=rrc_taps)
tx = upfirdn(rrc_taps, symbols, up=sps)
python
CopyEdit
from scipy.signal import lfilter
mf_out = lfilter(rrc_taps, [1.0], rx_signal)