diff --git a/channel.py b/channel.py index 562d1b0..caf2d0f 100644 --- a/channel.py +++ b/channel.py @@ -2,12 +2,22 @@ import numpy as np channel_response = np.array([0, 0, 0, 1, 0, 0, 0]) +# 15dB seems to be around the minimum for error-free transmission +snr_db = 15 + def sim(in_data): out_data = np.ndarray((len(in_data), len(in_data[0])), dtype=np.csingle) + # noise stuff is straight copied from the DSP illustrations article for i in range(len(in_data)): convolved = np.convolve(channel_response, in_data[i], mode='same') - out_data[i] = convolved + + signal_power = np.mean(abs(convolved**2)) + noise_power = signal_power * 10**(-snr_db/10) + + noise = np.sqrt(noise_power / 2) * (np.random.randn(*convolved.shape) + 1j*np.random.randn(*convolved.shape)) + + out_data[i] = convolved + noise return out_data diff --git a/main.py b/main.py index 0a2f56a..7f319f8 100755 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ Hopefully eventually this modem design makes it onto an fpga. TODO: Add comments for functions Explain what the main function is doing - Finish doing the channel simulation stuff (add noise, and verify channel response) + Add more errors, like a shifted signal Add support for 16-QAM, 64-QAM, etc... Add channel estimation via pilot carriers Add some sort of payload support, i.e. be able to drop the padding at the end @@ -48,7 +48,7 @@ if __name__ == '__main__': bytes = bytearray(data, 'utf8') - parallel = parallelise(16, bytes) + parallel = parallelise(64, bytes) modulated = qam.modulate(parallel) @@ -66,6 +66,6 @@ if __name__ == '__main__': to_serialise = qam.demodulate(to_decode) - data = serialise(16, to_serialise) + data = serialise(64, to_serialise) print(data)