26 lines
No EOL
554 B
Python
26 lines
No EOL
554 B
Python
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
|
|
|
|
if __name__ == "__main__":
|
|
x = np.loadtxt("input.txt")
|
|
y = channel(x)
|
|
np.savetxt("output.txt", y)
|
|
print("Channel output written to output.txt") |