In [42]:
%load_ext autoreload
%autoreload 2
In [43]:
import matplotlib
matplotlib.use('nbagg')
import numpy as np
import matplotlib.pyplot as plt
In [44]:
from errsim import *
In [45]:
# Simulated PMF: pe=1e-2, pb=0.5, m=4, n=15, nblks=1e6
np.random.seed(42)
spmf_1em2_0p5_4_15 = errhist(1e-2, 0.5, 4, 15, int(1e6)) / 1e6
# Analytical PMF: pe=1e-2, pb=0.5, m=4, n=15
apmf_1em2_0p5_4_15 = errpmf(1e-2, 0.5, 15, 4)
# BSC: pe=1e-2, m=4, n=15
bpmf_1em2_4_15 = errpmf(1e-2, 1e-2, 15, 4)
In [47]:
x = np.arange(16)
fig, ax = plt.subplots()
ax.plot(x, bpmf_1em2_4_15[x], color='black', label='$p_X(x)$ BSC 1e-2, 4, 15')
ax.plot(x, apmf_1em2_0p5_4_15[x], color='blue', label='$p_X(x)$ analytical 1e-2, 0.5, 4, 15')
ax.scatter(x, spmf_1em2_0p5_4_15[x], color='red', label='$p_X(x)$ simulation 1e-2, 0.5, 4, 15')
ax.set_yscale('log')
ax.set_title('P(x, n) = Prob{x symbol errors in n symbol block}')
ax.set_xlabel('Symbols, x')
ax.set_ylabel('Probability')
ax.legend()
ax.grid()
plt.show()
In [31]:
#plt.close(fig)
In [32]:
# Simulated PMF: pe=1e-6, pb=0.5, m=5, n=24, nblks=1e6
np.random.seed(42)
spmf_1em6_0p5_5_24 = errhist(1e-6, 0.5, 5, 25, int(1e6)) / 1e6
# Analytical PMF: pe=1e-6, pb=0.5, m=5, n=24
apmf_1em6_0p5_5_24 = errpmf(1e-6, 0.5, 24, 5)
# Simulated PMF: pe=1e-6, pb=0.5, m=8, n=255, nblks=1e8
hist_1em6_0p5_8_255 = np.load('errhist-1e-6-0.5-8-255-1e8.npy')
spmf_1em6_0p5_8_255 = hist_1em6_0p5_8_255 / 1e8
# Analytical PMF: pe=1e-6, pb=0.5, m=8, n=255
apmf_1em6_0p5_8_255 = errpmf(1e-6, 0.5, 255, 8)
# PMF: pe=1e-12, pb=0.5, m=5, n=24
pmf_1em12_0p5_5_24 = errpmf(pe=1e-12, pb=0.5, n=24, m=5)
# BSC: pe=1e-6, m=8, n=255
bpmf_1em6_8_255 = errpmf(1e-6, 1e-6, 255, 8)
In [33]:
x = np.arange(16)
fig, ax = plt.subplots()
ax.plot(x, bpmf_1em6_8_255[x], color='black', label='$p_X(x)$ BSC 1e-6, 8, 255')
ax.plot(x, apmf_1em6_0p5_5_24[x], color='blue', label='$p_X(x)$ analytical 1e-6, 0.5, 5, 24')
ax.scatter(x, spmf_1em6_0p5_5_24[x], color='red', label='$p_X(x)$ simulation 1e-6, 0.5, 5, 24')
ax.plot(x, apmf_1em6_0p5_8_255[x], color='green', label='$p_X(x)$ analytical 1e-6, 0.5, 8, 255')
ax.scatter(x, spmf_1em6_0p5_8_255[x], color='orange', label='$p_X(x)$ simulation 1e-6, 0.5, 8, 255')
ax.plot(x, pmf_1em12_0p5_5_24[x], color='lightblue', lw=2, label='$p_X(x)$ analytical 1e-12, 0.5, 5, 24')
ax.axhline(1e-15, color='black', linestyle='dashed')
#ax.set_xlim(0, 15)
ax.set_ylim(1e-25, 1e-1)
ax.set_yscale('log')
ax.set_title('P(x, n) = Prob{x symbol errors in n symbol block}')
ax.set_xlabel('Symbols, x')
ax.set_ylabel('Probability')
ax.legend()
ax.grid(True)
plt.show()
In [34]:
params = [
# GBMM
dict(pe=1e-6, pb=0.5, m=8, n=124),
dict(pe=1e-6, pb=0.5, m=8, n=248),
dict(pe=1e-6, pb=0.5, m=10, n=264),
dict(pe=1e-6, pb=0.5, m=10, n=528),
# BSC
dict(pe=1e-6, pb=None, m=8, n=124),
dict(pe=1e-6, pb=None, m=8, n=248)]
def plot_x_vs_pmf(ax, x, param, **plotargs):
if param['pb'] is None:
param['pb'] = param['pe']
label = 'BSC pe={pe} m={m} n={n}'.format(**param)
else:
label = 'GBMM pe={pe} pb={pb} m={m} n={n}'.format(**param)
pmf = errpmf(**param)
if 'label' not in plotargs:
plotargs['label'] = label
ax.plot(x, pmf[x], **plotargs)
plt.close('all')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=plt.figaspect(1/2))
x = np.arange(16)
for param in params:
plot_x_vs_pmf(ax, x, param, lw=1.5)
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_yscale('log')
#ax.set_xlim(x[0], x[-1])
ax.set_xticks(x)
ax.set_ylim(1e-25, 1e-1)
ax.set_xlabel('Number of Symbols, $x$')
ax.set_ylabel('Symbol Error PMF, $p_X(x)$')
ax.set_title('Symbol Error PMF')
ax.legend(fontsize=12)
ax.grid(True)
fig.savefig('plots/symbol_error_pmf.png')
plt.show()
In [35]:
params = [
# GBMM
dict(pe=1e-6, pb=0.5, m=8, n=124),
dict(pe=1e-6, pb=0.5, m=8, n=248),
dict(pe=1e-6, pb=0.5, m=10, n=264),
dict(pe=1e-6, pb=0.5, m=10, n=528),
# BSC
dict(pe=1e-6, pb=None, m=8, n=124),
dict(pe=1e-6, pb=None, m=8, n=248)]
def plot_t_vs_pndc(ax, x, param, **plotargs):
if param['pb'] is None:
param['pb'] = param['pe']
label = 'BSC pe={pe} m={m} n={n}'.format(**param)
else:
label = 'GBMM pe={pe} pb={pb} m={m} n={n}'.format(**param)
pmf = errpmf(**param)
pndc = prob_ndc(pmf)
if 'label' not in plotargs:
plotargs['label'] = label
ax.plot(x, pndc[x], **plotargs)
plt.close('all')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=plt.figaspect(1/2))
x = np.arange(16)
for param in params:
plot_t_vs_pndc(ax, x, param, lw=1.5)
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_yscale('log')
#ax.set_xlim(x[0], x[-1])
ax.set_xticks(x)
ax.set_ylim(1e-25, 1e-1)
ax.set_xlabel('Number of Symbols Corrected, $t$')
ax.set_ylabel('$P_{ndc}(t)$')
ax.set_title('Probability of not-decoding-correctly')
ax.legend(fontsize=12)
ax.grid(True)
fig.savefig('plots/probability_of_not_decoding_correctly.png')
plt.show()
In [ ]:
params = [
# GBMM
dict(pe=1e-6, pb=0.5, m=8, n=124),
dict(pe=1e-6, pb=0.5, m=8, n=248),
dict(pe=1e-6, pb=0.5, m=10, n=264),
dict(pe=1e-6, pb=0.5, m=10, n=528),
# BSC
dict(pe=1e-6, pb=None, m=8, n=124),
dict(pe=1e-6, pb=None, m=8, n=248)]
def plot_t_vs_ober(ax, x, param, **plotargs):
if param['pb'] is None:
param['pb'] = param['pe']
label = 'BSC pe={pe} m={m} n={n}'.format(**param)
else:
label = 'GBMM pe={pe} pb={pb} m={m} n={n}'.format(**param)
pmf = errpmf(**param)
ober = ber_out(param['pe'], param['pb'], pmf)
if 'label' not in plotargs:
plotargs['label'] = label
ax.plot(x, ober[x], **plotargs)
plt.close('all')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=plt.figaspect(1/2))
x = np.arange(16)
for param in params:
plot_t_vs_ober(ax, x, param, lw=1.5)
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_yscale('log')
#ax.set_xlim(x[0], x[-1])
ax.set_xticks(x)
ax.set_ylim(1e-25, 1e-1)
ax.set_xlabel('Number of Symbols Corrected, $t$')
ax.set_ylabel('Output BER, $BER_o$')
ax.set_title('Number of Symbols Corrected vs. Output BER')
ax.legend(fontsize=12)
ax.grid(True)
fig.savefig('plots/number_of_symbols_corrected_vs_output_ber.png')
plt.show()
In [37]:
params = [
# GBMM
dict(pe=1e-6, pb=0.5, m=8, n=124),
dict(pe=1e-6, pb=0.5, m=8, n=248),
dict(pe=1e-6, pb=0.5, m=10, n=264),
dict(pe=1e-6, pb=0.5, m=10, n=528),
# BSC
dict(pe=1e-6, pb=None, m=8, n=124),
dict(pe=1e-6, pb=None, m=8, n=248)]
def plot_r_vs_ober(axes, t, param, **plotargs):
if param['pb'] is None:
param['pb'] = param['pe']
label = 'BSC pe={pe} m={m} n={n}'.format(**param)
else:
label = 'GBMM pe={pe} pb={pb} m={m} n={n}'.format(**param)
pmf = errpmf(**param)
ober = ber_out(param['pe'], param['pb'], pmf)
if 'label' not in plotargs:
plotargs['label'] = label
n = param['n']
frac_t = 100 * t / n
k = n - 2 * t
r = k / n
axes[0].plot(frac_t, ober[t], **plotargs)
axes[1].plot(r, ober[t], **plotargs)
plt.close('all')
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=plt.figaspect(1/2))
t = np.arange(16)
for param in params:
plot_r_vs_ober(axes, t, param, lw=1.5)
for ax in axes:
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_ylim(1e-25, 1e-5)
ax.set_ylabel('Output BER, $BER_o$')
ax.set_yscale('log')
ax.grid(True)
axes[0].set_xlim(0, 10)
axes[0].set_xlabel('Fraction of Symbols corrected, $t/n$ [%]')
axes[0].set_title('Fraction of Symbols corrected vs. Output BER')
axes[0].legend(loc='upper right', fontsize=12)
axes[1].set_xlim(0.8, 1.0)
axes[1].set_xlabel('Coding Rate, $R = k/n = (n - 2t)/n$')
axes[1].set_title('Coding Rate vs. Output BER')
axes[1].legend(loc='upper left', fontsize=12)
plt.tight_layout()
fig.savefig('plots/coding_rate_vs_output_ber.png')
plt.show()
In [38]:
plt.close('all')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=plt.figaspect(1/2))
pe = 10.0 ** np.arange(-15, -0.5, 0.5)
ober = pe_vs_ober(pe=pe, pb=0.5, n=248, m=8, t=4)
ax.plot(pe, ober, lw=1.5, label='t=4')
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlim(pe[0], pe[-1])
ax.set_ylim(1e-25, 1e-1)
ax.set_xlabel('Input BER, $BER_i$')
ax.set_ylabel('Output BER, $BER_o$')
ax.set_title('Input vs. Output BER')
ax.legend(loc='upper left', fontsize=12)
ax.grid(True)
#fig.savefig('plots/pe_vs_ober.png')
plt.show()
In [41]:
plt.close('all')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=plt.figaspect(1/2))
pe = 10.0 ** np.arange(-30, -0.5, 0.5)
snr = pe2snr(pe)
iber = ber_in(pe=pe, pb=0.5)
ax.plot(snr, iber, lw=1.5, color='black', label='Uncoded')
ober = pe_vs_ober(pe=pe, pb=0.5, n=248, m=8, t=4)
ax.plot(snr, ober, lw=1.5, label='t=4')
ober = pe_vs_ober(pe=pe, pb=0.5, n=248, m=8, t=6)
ax.plot(snr, ober, lw=1.5, label='t=6')
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_yscale('log')
ax.set_xlim(8, 20)
ax.set_ylim(1e-25, 1e-1)
ax.set_xlabel('Input SNR [dB]')
ax.set_ylabel('Output BER, $BER_o$')
ax.set_title('Input SNR vs. Output BER')
ax.legend(fontsize=12)
ax.grid(True)
#fig.savefig('plots/snr_vs_ober.png')
plt.show()
In [48]:
plt.close('all')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=plt.figaspect(1/2))
ebn0 = np.arange(8, 20.5, 0.5)
pe = esn02pe(ebn0)
iber = ber_in(pe=pe, pb=0.5)
#ax.plot(ebn0, iber, lw=1.5, color='black', label='Uncoded')
ax.plot(ebn0, pe, lw=1.5, color='black', label='Uncoded BSC')
ax.plot(ebn0, iber, lw=1.5, color='black', linestyle='dashed', label='Uncoded GBMM(pb=0.5)')
pb=0.5; m = 8; n = 248; t = 4; R = (n - 2 * t)/n
esn0 = ebn0 * R
pe = esn02pe(esn0)
ober = pe_vs_ober(pe=pe, pb=pb, n=n, m=m, t=t)
ax.plot(ebn0, ober, lw=1.5, label='n=248, t=4')
pb=0.5; m = 8; n = 248; t = 6; R = (n - 2 * t)/n
esn0 = ebn0 * R
pe = esn02pe(esn0)
ober = pe_vs_ober(pe=pe, pb=pb, n=n, m=m, t=t)
ax.plot(ebn0, ober, lw=1.5, label='n=248, t=6')
pb=0.5; m = 8; n = 124; t = 6; R = (n - 2 * t)/n
esn0 = ebn0 * R
pe = esn02pe(esn0)
ober = pe_vs_ober(pe=pe, pb=pb, n=n, m=m, t=t)
ax.plot(ebn0, ober, lw=1.5, label='n=124, t=6')
ax.axhline(1e-15, color='black', linestyle='dashed')
ax.set_yscale('log')
ax.set_xlim(8, 20)
ax.set_ylim(1e-25, 1e-1)
ax.set_xlabel('$E_b/N_0$ [dB]')
ax.set_ylabel('Output BER, $BER_o$')
ax.set_title('Eb/N0 vs. Output BER')
ax.legend(fontsize=12)
ax.grid(True)
#fig.savefig('plots/ebn0_vs_ober.png')
plt.show()
In [71]:
plt.close('all')
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=plt.figaspect(1/2))
flitsz = 128
flits_per_packet = [1, 32]
for i, ax in enumerate(axes):
n = flitsz * flits_per_packet[i]
x = np.arange(n + 1)
y = errpmf(pe=1e-12, pb=0.5, m=1, n=n)
ax.plot(x, y, label='m=1, n={}'.format(n))
ax.set_yscale('log')
ax.set_xlim(0, 128)
ax.set_ylim(1e-25, 1e-1)
ax.legend(fontsize=12)
ax.grid(True)
print('Pr{{X > 5}} = {:e}'.format(y[6:].sum()))
print('Pr{{X > 25}} = {:e}'.format(y[26:].sum()))
plt.show()
In [ ]: