"Feature complete" but has issues
This commit is contained in:
parent
0cdb4b0176
commit
9b1353b4ef
12
channel.py
Normal file
12
channel.py
Normal 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])
|
||||
|
||||
|
||||
|
31
main.py
31
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)
|
||||
|
4
qam.py
4
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
|
||||
|
Loading…
Reference in New Issue
Block a user