"Feature complete" but has issues

This commit is contained in:
David Lenfesty 2019-08-25 15:48:40 -06:00
parent 0cdb4b0176
commit 9b1353b4ef
4 changed files with 43 additions and 7 deletions

12
channel.py Normal file
View File

@ -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])

1
data.txt Normal file
View File

@ -0,0 +1 @@
The quick brown fox jumped over the lazy dog.

31
main.py
View File

@ -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)

4
qam.py
View File

@ -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