feat: add channel and main
This commit is contained in:
parent
becd9cb96d
commit
c4e3392d3e
2 changed files with 48 additions and 0 deletions
20
channel.py
Normal file
20
channel.py
Normal file
|
@ -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
|
28
main.py
Normal file
28
main.py
Normal file
|
@ -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}")
|
Loading…
Add table
Reference in a new issue