Skip to content

Instantly share code, notes, and snippets.

@kumanna
Created February 5, 2026 05:38
Show Gist options
  • Select an option

  • Save kumanna/d3193777884b38b5357871e904435f3e to your computer and use it in GitHub Desktop.

Select an option

Save kumanna/d3193777884b38b5357871e904435f3e to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
N = 2048
N_CP = 3
h = [1, 0.4-0.3j, 0.2+0.4j, -0.3+0.4j]
# Generate N random QPSK symbols
x = np.sign(np.random.randn(N)) + 1j * np.sign(np.random.randn(N))
# Step 1: Take IDFT
X = np.fft.ifft(x) * np.sqrt(N)
# Step 2: Add cyclic prefix
X_with_cp = np.concatenate([X[-N_CP:], X])
Y = np.convolve(X_with_cp, h)
y = np.fft.fft(Y[N_CP:N+N_CP]) / np.sqrt(N)
x_hat = y / np.fft.fft(h, N)
assert(np.max(np.abs(x - x_hat)) < 1e-9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment