Fixed SNR amplitude; Fixed BER calculation
This commit is contained in:
parent
74ee1cc4db
commit
be6ded2162
@ -19,15 +19,16 @@ def _get_noise_amp_from_SNR(SNR: float, signal_amp: float = 1) -> float:
|
||||
return noise_amp
|
||||
|
||||
|
||||
def add_awgn(c: np.array, SNR: float) -> np.array:
|
||||
def add_awgn(c: np.array, SNR: float, signal_amp: float = 1) -> np.array:
|
||||
"""Add Additive White Gaussian Noise to a data vector. As this function adds random noise to the input,
|
||||
the output changes, even if it is called multiple times with the same input.
|
||||
|
||||
:param c: Binary vector representing the data to be transmitted
|
||||
:param SNR: Signal-to-Noise-Ratio in dB
|
||||
:param signal_amp: Amplitude of the signal. Used for the noise amplitude calculation
|
||||
:return: Data vector with added noise
|
||||
"""
|
||||
noise_amp = _get_noise_amp_from_SNR(SNR, signal_amp=1)
|
||||
noise_amp = _get_noise_amp_from_SNR(SNR, signal_amp=signal_amp)
|
||||
y = c + np.random.normal(scale=noise_amp, size=c.size)
|
||||
return y
|
||||
|
||||
@ -66,6 +67,7 @@ def test_decoder(decoder: typing.Any,
|
||||
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}"):
|
||||
|
||||
total_bit_errors = 0
|
||||
total_bits = 0
|
||||
|
||||
for n in tqdm(range(N_max), desc=f"Simulating for SNR = {SNR} dB",
|
||||
position=1,
|
||||
@ -74,15 +76,15 @@ def test_decoder(decoder: typing.Any,
|
||||
|
||||
# TODO: Is this a valid simulation? Can we just add AWGN to the codeword, ignoring and modulation and (
|
||||
# e.g. matched) filtering?
|
||||
y = add_awgn(x, SNR)
|
||||
y = add_awgn(x, SNR, signal_amp=(1 / np.sqrt(2)))
|
||||
y_hat = decoder.decode(y)
|
||||
|
||||
total_bit_errors += count_bit_errors(c, y_hat)
|
||||
total_bits += c.size
|
||||
|
||||
if total_bit_errors >= target_bit_errors:
|
||||
break
|
||||
|
||||
total_bits = c.size * N_max
|
||||
BERs.append(total_bit_errors / total_bits)
|
||||
|
||||
return np.array(SNRs), np.array(BERs)
|
||||
|
||||
@ -21,7 +21,7 @@ def main():
|
||||
|
||||
# Test decoder
|
||||
|
||||
d = np.array([0, 1, 0, 1])
|
||||
d = np.array([0, 1, 1, 1])
|
||||
c = np.dot(G.transpose(), d) % 2
|
||||
|
||||
print(f"Simulating with c = {c}")
|
||||
@ -33,7 +33,8 @@ def main():
|
||||
|
||||
ax = sns.lineplot(data=data, x="SNR", y="BER")
|
||||
ax.set(yscale="log")
|
||||
#ax.set_ylim([10e-6, 10e0])
|
||||
ax.set_yticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 10e0])
|
||||
# ax.set_ylim([10e-6, 10e0])
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user