45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
import seaborn as sns
|
|
import pandas as pd
|
|
|
|
from decoders import proximal
|
|
from decoders import naive_soft_decision
|
|
from decoders import utility
|
|
|
|
|
|
def main():
|
|
# Hamming(7,4) code
|
|
|
|
G = np.array([[1, 1, 1, 0, 0, 0, 0],
|
|
[1, 0, 0, 1, 1, 0, 0],
|
|
[0, 1, 0, 1, 0, 1, 0],
|
|
[1, 1, 0, 1, 0, 0, 1]])
|
|
|
|
H = np.array([[1, 0, 1, 0, 1, 0, 1],
|
|
[0, 1, 1, 0, 0, 1, 1],
|
|
[0, 0, 0, 1, 1, 1, 1]])
|
|
|
|
# Test decoder
|
|
|
|
d = np.array([0, 0, 0, 0])
|
|
c = np.dot(G.transpose(), d) % 2
|
|
|
|
print(f"Simulating with c = {c}")
|
|
|
|
# decoder = proximal.ProximalDecoder(H, K=100, gamma=0.01)
|
|
decoder = naive_soft_decision.SoftDecisionDecoder(G, H)
|
|
SNRs, BERs = utility.test_decoder(decoder, d, c, SNRs=np.linspace(1, 7, 9), target_bit_errors=500, N_max=10000)
|
|
|
|
data = pd.DataFrame({"SNR": SNRs, "BER": BERs})
|
|
|
|
ax = sns.lineplot(data=data, x="SNR", y="BER")
|
|
ax.set(yscale="log")
|
|
ax.set_yticks([10e-5, 10e-4, 10e-3, 10e-2, 10e-1, 10e0])
|
|
# ax.set_ylim([10e-6, 10e0])
|
|
plt.show()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|