コード例 #1
0
def test_decoding_did_not_converge(systematic, sparse):
    n = 15
    d_v = 4
    d_c = 5
    seed = 0

    H, G = make_ldpc(n, d_v, d_c, seed=seed, systematic=systematic,
                     sparse=sparse)
    assert not binaryproduct(H, G).any()

    n, k = G.shape
    snr = 1

    v = np.arange(k) % 2
    y = encode(G, v, snr, seed=seed)

    with pytest.warns(UserWarning, match="stopped before convergence"):
        decode(H, y, snr, maxiter=1)
コード例 #2
0
ファイル: ldpc.py プロジェクト: mingyuyng/JSCC
    def dec(self, LLR):

        x = decode(self.H, LLR, maxiter=self.maxiter)

        if x.ndim == 1:
            d = get_message(self.G, x)
            return d[:self.K]
        else:
            d = []
            for i in range(x.shape[1]):
                d.append(get_message(self.G, x[:, i]))

            d = np.vstack(d)
            return d[:, :self.K]
コード例 #3
0
def test_decoding_random(systematic, sparse):
    n = 15
    d_v = 4
    d_c = 5
    seed = 0

    H, G = make_ldpc(n, d_v, d_c, seed=seed, systematic=systematic,
                     sparse=sparse)
    assert not binaryproduct(H, G).any()
    n, k = G.shape
    snr = 100

    v, y = encode_random_message(G, snr, seed)

    d = decode(H, y, snr)
    x = get_message(G, d)

    assert abs(v - x).sum() == 0
コード例 #4
0
def test_decoding(systematic, log, sparse):
    n = 15
    d_v = 4
    d_c = 5
    seed = 0

    H, G = make_ldpc(n,
                     d_v,
                     d_c,
                     seed=seed,
                     systematic=systematic,
                     sparse=sparse)
    assert not binaryproduct(H, G).any()

    n, k = G.shape
    snr = 100

    v = np.arange(k) % 2
    y = encode(G, v, snr, seed)

    d = decode(H, y, snr, maxiter=10, log=log)
    x = get_message(G, d)

    assert abs(v - x).sum() == 0
コード例 #5
0
H, G = make_ldpc(n, d_v, d_c, seed=seed, systematic=True, sparse=True)

n, k = G.shape
print("Number of coded bits:", k)

##################################################################
# Now we simulate transmission for different levels of noise and
# compute the percentage of errors using the bit-error-rate score
# To parallelize coding and decoding, simply stack the messages as columns:

errors = []
snrs = np.linspace(-2, 10, 20)
v = np.arange(k) % 2  # fixed k bits message
n_trials = 50  # number of transmissions with different noise
V = np.tile(v, (n_trials, 1)).T  # stack v in columns

for snr in snrs:
    y = encode(G, V, snr, seed=seed)
    D = decode(H, y, snr)
    error = 0.
    for i in range(n_trials):
        x = get_message(G, D[:, i])
        error += abs(v - x).sum() / (k * n_trials)
    errors.append(error)

plt.figure()
plt.plot(snrs, errors, color="indianred")
plt.ylabel("Bit error rate")
plt.xlabel("SNR")
plt.show()
コード例 #6
0
n_messages = np.arange(1, 20)
n_runs = 50
snr = 10
times_parallel = []
times_sequential = []

for pp in n_messages:
    t_parallel = 0
    t_seq = 0
    V = rng.randint(2, size=(k, pp))  # simulate messages
    Y = encode(G, V, snr, seed=seed)

    for _ in range(n_runs):
        t = time()
        decode(H, Y, snr)
        t_parallel += time() - t

        t = time()
        for y in Y.T:
            decode(H, y, snr)
        t_seq += time() - t
    times_sequential.append(t_seq / n_runs)
    times_parallel.append(t_parallel / n_runs)

plt.figure()
plt.plot(n_messages,
         times_sequential,
         color="indianred",
         lw=2,
         label="Sequential")
コード例 #7
0
ファイル: ldpc.py プロジェクト: mingyuyng/JSCC
    def dec(self, LLR):

        d = get_message(self.G, decode(self.H, LLR, maxiter=200))

        return d[:self.K]