Skip to content

Commit 21c090f

Browse files
committed
Update links to test coded messages.
1 parent 0748d3b commit 21c090f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

commpy/links.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"""
1515
from __future__ import division # Python 2 compatibility
1616

17+
import math
18+
1719
import numpy as np
1820

1921
from commpy.channels import MIMOFlatChannel
@@ -61,14 +63,7 @@ def link_performance(link_model, SNRs, send_max, err_min, send_chunk=None, code_
6163
divider = link_model.num_bits_symbol * link_model.channel.nb_tx
6264
send_chunk = max(divider, send_chunk // divider * divider)
6365

64-
# Evaluate the size of each reception
65-
msg = np.random.choice((0, 1), link_model.channel.nb_tx)
66-
link_model.channel.noise_std = 0
67-
symbs = link_model.modulate(msg)
68-
channel_output = link_model.channel.propagate(symbs)
69-
received_msg = link_model.receive(channel_output[0], link_model.channel.channel_gains[0],
70-
link_model.constellation, link_model.channel.noise_std ** 2)
71-
receive_size = len(received_msg)
66+
receive_size = link_model.channel.nb_tx * link_model.num_bits_symbol
7267

7368
# Computations
7469
for id_SNR in range(len(SNRs)):
@@ -84,7 +79,7 @@ def link_performance(link_model, SNRs, send_max, err_min, send_chunk=None, code_
8479
# Deals with MIMO channel
8580
if isinstance(link_model.channel, MIMOFlatChannel):
8681
nb_symb_vector = len(channel_output)
87-
received_msg = np.empty_like(msg, int)
82+
received_msg = np.empty(int(math.ceil(len(msg) / link_model.rate)), int)
8883
for i in range(nb_symb_vector):
8984
received_msg[receive_size * i:receive_size * (i + 1)] = \
9085
link_model.receive(channel_output[i], link_model.channel.channel_gains[i],
@@ -93,7 +88,7 @@ def link_performance(link_model, SNRs, send_max, err_min, send_chunk=None, code_
9388
received_msg = link_model.receive(channel_output, link_model.channel.channel_gains,
9489
link_model.constellation, link_model.channel.noise_std ** 2)
9590
# Count errors
96-
bit_err += (msg != received_msg).sum()
91+
bit_err += (msg != link_model.decoder(received_msg)).sum()
9792
bit_send += send_chunk
9893
BERs[id_SNR] = bit_err / bit_send
9994
return BERs
@@ -129,6 +124,9 @@ class LinkModel:
129124
Average energy per symbols.
130125
*Default* Es=1.
131126
127+
decoder : function with prototype decoder(binary array) that return a binary array.
128+
*Default* is no process.
129+
132130
Attributes
133131
----------
134132
modulate : function with same prototype as Modem.modulate
@@ -153,10 +151,16 @@ class LinkModel:
153151
*Default* Es=1.
154152
"""
155153

156-
def __init__(self, modulate, channel, receive, num_bits_symbol, constellation, Es=1):
154+
def __init__(self, modulate, channel, receive, num_bits_symbol, constellation, Es=1, decoder=None, rate=1):
157155
self.modulate = modulate
158156
self.channel = channel
159157
self.receive = receive
160158
self.num_bits_symbol = num_bits_symbol
161159
self.constellation = constellation
162160
self.Es = Es
161+
self.rate = rate
162+
163+
if decoder is None:
164+
self.decoder = lambda msg: msg
165+
else:
166+
self.decoder = decoder

0 commit comments

Comments
 (0)