Channel estimation is not working at all.

Maybe a math problem with how I did things? Almost definitely
This commit is contained in:
David Lenfesty 2019-09-05 10:31:18 -06:00
parent dbdf45ef05
commit 2b395b458a
3 changed files with 22 additions and 10 deletions

View File

@ -4,8 +4,8 @@ import scipy.interpolate
import matplotlib.pyplot as plt
# Dirac delta function response, no change
channel_response = np.array([0, 0, 0, 1, 0, 0, 0])
#channel_response = np.array([-1 + 1j, 0, 1, 0.5, 0.25])
#channel_response = np.array([0, 0, 0, 1, 0, 0, 0])
channel_response = np.array([1, 0, 0.3+0.3j])
# How do I sync this across two files?
@ -78,7 +78,7 @@ def estimate(in_data, pilots=0):
print(pilot_carriers)
# start averaging
H_est = 0
#H_est = 0
# for i in range(len(in_data)):
# # Obtain channel response at pilot carriers
@ -98,6 +98,8 @@ def estimate(in_data, pilots=0):
# Obtain channel response at pilot carriers
for i in pilot_carriers:
H_est_pilots[j] = in_data[0][i] / pilot_value
print("Value: " + str(in_data[0][i]))
print("Pilot estimate: " + str(H_est_pilots[j]))
j += 1
@ -106,7 +108,7 @@ def estimate(in_data, pilots=0):
H_est_phase = scipy.interpolate.interp1d(pilot_carriers, np.angle(H_est_pilots), kind='linear', fill_value='extrapolate')(all_carriers)
# Take angular form and turn into rectangular form
H_est += H_est_abs * np.exp(1j*H_est_phase)
H_est = H_est_abs * np.exp(1j*H_est_phase)
# for an average channel estimate
# H_est = H_est / len(in_data)
@ -114,11 +116,6 @@ def estimate(in_data, pilots=0):
# Exact channel response
H_exact = np.fft.fft(channel_response, len(in_data[0]))
for i in range(3):
plt.plot(abs(in_data[i]), "b")
plt.plot(np.abs(in_data[i]), "r")
plt.show(block=True)
plt.plot(all_carriers, np.real(H_exact), "b")
plt.plot(all_carriers, np.real(H_est), "r")
plt.plot(pilot_carriers, np.real(H_est_pilots), "go")

15
main.py
View File

@ -56,6 +56,15 @@ def cp_remove(in_data, prefix_len):
return out_data
def check_theoretical_channel(tx):
H_exact = np.fft.fft([1, 0, 0.3 + 0.3j], len(tx[0]))
rx = np.ndarray((len(tx[0])), dtype=np.csingle)
for i in range(len(tx[0])):
rx[i] = H_exact[i] * tx[0][i]
return rx
if __name__ == '__main__':
@ -76,9 +85,15 @@ if __name__ == '__main__':
# Add cyclic prefix to each symbol
tx = cp_add(ofdm_time, 16)
theoretical_rx = check_theoretical_channel(tx)
# Simulate effects of a multipath channel
rx = channel.sim(tx)
plt.plot(rx[0], "b")
plt.plot(theoretical_rx, "r")
plt.show(block=True)
# Remove cyclic prefix from incoming symbols
ofdm_cp_removed = cp_remove(rx, 16)

2
qam.py
View File

@ -1,7 +1,7 @@
import numpy as np
from scipy.spatial.distance import euclidean
pilot_value = 5 + 5j
pilot_value = 1 + 1j
qam_mapping_table = {
0 : 1 + 1j,