diff --git a/channel.py b/channel.py new file mode 100644 index 0000000..32ef5c4 --- /dev/null +++ b/channel.py @@ -0,0 +1,12 @@ +import numpy as np + +channel_response = np.array([1, 0, 1 - 1j]) + +def sim(in_data): + out_data = np.ndarray((len(in_data), len(in_data[0])), dtype=np.csingle) + + for i in range(len(in_data)): + convolved = np.convolve(channel_response, in_data[i]) + + + diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..c953ffa --- /dev/null +++ b/data.txt @@ -0,0 +1 @@ +The quick brown fox jumped over the lazy dog. diff --git a/main.py b/main.py index d307470..5b43723 100755 --- a/main.py +++ b/main.py @@ -8,8 +8,23 @@ import qam from serpar import parallelise, serialise -def cyclic_prefix(n, in_data, prefix_len): - out_data = np.ndarray((len(in_data), n + prefix_len), dtype=np.csingle) +def cp_add(in_data, prefix_len): + out_data = np.ndarray((len(in_data), len(in_data[0]) + prefix_len), dtype=np.csingle) + + for i in range(len(in_data)): + cp = in_data[i][-prefix_len:] + out_data[i] = np.hstack([cp, in_data[i]]) + + return out_data + +def cp_remove(in_data, prefix_len): + out_data = np.ndarray((len(in_data), len(in_data[0]) - prefix_len), dtype=np.csingle) + + for i in range(len(in_data)): + out_data[i] = in_data[i][prefix_len:] + + return out_data + @@ -23,10 +38,18 @@ if __name__ == '__main__': modulated = qam.modulate(parallel) - tx = np.fft.ifft(modulated) + ofdm_time = np.fft.ifft(modulated) - rx = channel.sim(tx) - + ofdm_prefixed = cp_add(ofdm_time, 4) + # Put the channel simulator stuff here + ofdm_cp_removed = cp_remove(ofdm_prefixed, 4) + to_decode = np.fft.fft(ofdm_cp_removed) + + to_serialise = qam.demodulate(to_decode) + + data = serialise(to_serialise) + + print(data) diff --git a/qam.py b/qam.py index 47a51dd..a052442 100644 --- a/qam.py +++ b/qam.py @@ -30,7 +30,7 @@ def modulate(in_data): return out_data -def demodulate(n, in_data): +def demodulate(in_data): out_data = np.ndarray((len(in_data), len(in_data[0])), dtype=np.uint8) # Just pull the constellation array data out @@ -43,7 +43,7 @@ def demodulate(n, in_data): # Here we have to map to the closest constellation point, # because floating point error for k in range(len(constellation)): - distances[k] = euclidean(in_data[i][j], constellation[i][j]) + distances[k] = euclidean(in_data[i][j], constellation[k]) # output is the index of the constellation, essentially # this may have to change if I want to generalise