Removed N_max from simulations.test_decoder()
This commit is contained in:
parent
0f8de32e3f
commit
3e02dcf17c
@ -22,8 +22,7 @@ def test_decoder(n: int,
|
|||||||
k: int,
|
k: int,
|
||||||
decoder: typing.Any,
|
decoder: typing.Any,
|
||||||
SNRs: typing.Sequence[float] = np.linspace(1, 7, 7),
|
SNRs: typing.Sequence[float] = np.linspace(1, 7, 7),
|
||||||
target_frame_errors: int = 100,
|
target_frame_errors: int = 100) \
|
||||||
N_max: int = 10000) \
|
|
||||||
-> typing.Tuple[np.array, np.array]:
|
-> typing.Tuple[np.array, np.array]:
|
||||||
"""Calculate the Bit Error Rate (BER) for a given decoder for a number of SNRs.
|
"""Calculate the Bit Error Rate (BER) for a given decoder for a number of SNRs.
|
||||||
|
|
||||||
@ -52,12 +51,13 @@ def test_decoder(n: int,
|
|||||||
total_bits = 0
|
total_bits = 0
|
||||||
total_frame_errors = 0
|
total_frame_errors = 0
|
||||||
|
|
||||||
for i in tqdm(range(N_max),
|
pbar = tqdm(total=target_frame_errors,
|
||||||
desc=f"Simulating for SNR = {SNR} dB",
|
desc=f"Simulating for SNR = {SNR} dB",
|
||||||
position=2,
|
position=2,
|
||||||
leave=False,
|
leave=False,
|
||||||
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}"):
|
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]")
|
||||||
|
|
||||||
|
while total_frame_errors < target_frame_errors:
|
||||||
# Simulate channel
|
# Simulate channel
|
||||||
y = noise.add_awgn(x_bpsk, SNR, n, k)
|
y = noise.add_awgn(x_bpsk, SNR, n, k)
|
||||||
|
|
||||||
@ -65,12 +65,15 @@ def test_decoder(n: int,
|
|||||||
x_hat = decoder.decode(y)
|
x_hat = decoder.decode(y)
|
||||||
|
|
||||||
# Calculate statistics
|
# Calculate statistics
|
||||||
total_bit_errors += count_bit_errors(x, x_hat)
|
bit_errors = count_bit_errors(x, x_hat)
|
||||||
total_bits += x.size
|
total_bits += x.size
|
||||||
total_frame_errors += 1 if total_bit_errors > 0 else 0
|
|
||||||
|
|
||||||
if total_frame_errors >= target_frame_errors:
|
if bit_errors > 0:
|
||||||
break
|
total_frame_errors += 1
|
||||||
|
total_bit_errors += bit_errors
|
||||||
|
pbar.update(1)
|
||||||
|
|
||||||
|
pbar.close()
|
||||||
|
|
||||||
BERs.append(total_bit_errors / total_bits)
|
BERs.append(total_bit_errors / total_bits)
|
||||||
|
|
||||||
@ -81,8 +84,7 @@ def test_decoders(n: int,
|
|||||||
k: int,
|
k: int,
|
||||||
decoders: typing.List,
|
decoders: typing.List,
|
||||||
SNRs: typing.Sequence[float] = np.linspace(1, 7, 7),
|
SNRs: typing.Sequence[float] = np.linspace(1, 7, 7),
|
||||||
target_frame_errors: int = 100,
|
target_frame_errors: int = 100) \
|
||||||
N_max: int = 10000) \
|
|
||||||
-> typing.Tuple[np.array, np.array]:
|
-> typing.Tuple[np.array, np.array]:
|
||||||
"""Calculate the Bit Error Rate (BER) for a number of given decoders for a number of SNRs.
|
"""Calculate the Bit Error Rate (BER) for a number of given decoders for a number of SNRs.
|
||||||
|
|
||||||
@ -93,7 +95,6 @@ def test_decoders(n: int,
|
|||||||
:param decoders: List of decoder objects to be tested
|
:param decoders: List of decoder objects to be tested
|
||||||
:param SNRs: List of SNRs for which the BER should be calculated
|
:param SNRs: List of SNRs for which the BER should be calculated
|
||||||
:param target_frame_errors: Number of frame errors after which to stop the simulation
|
:param target_frame_errors: Number of frame errors after which to stop the simulation
|
||||||
:param N_max: Maximum number of iterations to perform for each SNR
|
|
||||||
:return: Tuple of the form (SNRs, [BERs_1, BERs_2, ...]) where SNR and BERs_x are numpy arrays
|
:return: Tuple of the form (SNRs, [BERs_1, BERs_2, ...]) where SNR and BERs_x are numpy arrays
|
||||||
"""
|
"""
|
||||||
result_BERs = []
|
result_BERs = []
|
||||||
@ -105,7 +106,7 @@ def test_decoders(n: int,
|
|||||||
position=0,
|
position=0,
|
||||||
leave=False,
|
leave=False,
|
||||||
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}"):
|
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}"):
|
||||||
_, BERs = test_decoder(n, k, decoder, SNRs, target_frame_errors, N_max)
|
_, BERs = test_decoder(n, k, decoder, SNRs, target_frame_errors)
|
||||||
result_BERs.append(BERs)
|
result_BERs.append(BERs)
|
||||||
|
|
||||||
end_time = default_timer()
|
end_time = default_timer()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user