diff --git a/channel.py b/channel.py index 19cb34a..b62e927 100644 --- a/channel.py +++ b/channel.py @@ -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") diff --git a/main.py b/main.py index 198011d..abcd16b 100755 --- a/main.py +++ b/main.py @@ -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) diff --git a/qam.py b/qam.py index 876ea88..827513f 100644 --- a/qam.py +++ b/qam.py @@ -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,