Skip to content

Instantly share code, notes, and snippets.

@kumanna
Created March 27, 2025 04:23
Show Gist options
  • Save kumanna/4b5472410065607434dd30f57a34a7fd to your computer and use it in GitHub Desktop.
Save kumanna/4b5472410065607434dd30f57a34a7fd to your computer and use it in GitHub Desktop.
import numpy as np
NFFT = 16
NCP = 4
# Generate QPSK symbols
symbols = np.sign(np.random.randn(NFFT)) + 1j * np.sign(np.random.randn(NFFT))
# LTI channel
# Generate h according to a power delay profile
# h = [h_0, h_1, h_2]
# h_0 = sqrt(var0) * (randn + 1j * randn / 2)
# h_1 = sqrt(var1) * (randn + 1j * randn / 2)
# Power delay profile = [1, 0.5, 0.25]
h = [0.4 + 0.3j, 0.2 - 0.1j, 0.1 + 0.05j]
# Take IDFT
x = np.fft.ifft(symbols)
# Add cyclic prefix
x_cp = np.concatenate([x[-NCP:], x])
# Perform linear convolution
y_recv = np.convolve(h, x_cp)
y = y_recv[NCP:NFFT+NCP]
# Take FFT
Y = np.fft.fft(y)
# Recover symbols by zero forcing
x_hat = Y / np.fft.fft(h, NFFT)
print(np.max(np.abs(x_hat - symbols)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment