diff --git a/channel.py b/channel.py new file mode 100644 index 0000000..e86a3c9 --- /dev/null +++ b/channel.py @@ -0,0 +1,20 @@ +import numpy as np +import random + +def channel(x): + G = 10 + sigma2 = 10 + s = random.choice([1, 2]) + + n = x.size + Y = np.random.normal(0, np.sqrt(sigma2), n) + if s == 1: + x_even = np.array(x[::2]) * np.sqrt(G) + x_odd = x[1::2] + else: + x_even = np.array(x[::2]) + x_odd = x[1::2] * np.sqrt(G) + + Y[::2] += x_even + Y[1::2] += x_odd + return Y diff --git a/main.py b/main.py new file mode 100644 index 0000000..7d1eb25 --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +import numpy as np +from transmitter import transmitter +from receiver import receiver +from channel import channel + +# Define the alphabet +alphabet = ( + 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '0123456789 .' +) + +# Example 40-character message +test_message = 'ERROR 404. Motivation not found. Retry .' + +# Transmit +x = transmitter(test_message) + +# Simulate channel +Y = channel(x) + +# Receive +decoded_message = receiver(Y) + +# Print results +print(f"Original message: {test_message}") +print(f"Decoded message: {decoded_message}") +print(f"Bit error rate: {(np.array(list(test_message)) != np.array(list(decoded_message))).mean():.4f}") \ No newline at end of file