Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bit-flipping decoding
#11
(Aug-25-2021, 03:13 AM)Larz60+ Wrote: Thanks for sharing solution
You're welcome @Larz60. But I am too rush in posting the solution for this code. And after doing some testing (by changing the value of y = [0 0 1 0 1 1]), I found that the solution that I've posted is wrong. So here is the revision for the solution:

import numpy as np

#declaration of the parity-check matrix
H = np.array([[1, 1, 0, 1, 0, 0], [0, 1, 1, 0, 1, 0],
            [1, 0, 0, 0, 1, 1], [0, 0, 1, 1, 0, 1]])

#setting the input and output of the LDPC
c = np.array([0, 0, 1, 0, 1, 1])
y = np.array([0, 0, 1, 0, 1, 1])

#initialization of bit flipping decoding
w_r = 2
w_c = 3
m = np.size(H,0)
N = np.size(H,1)
M = y[::].copy()
M_i = np.zeros((6), dtype=int)
s = np.zeros((4), dtype=int)
E = np.zeros((m, N), dtype=int)
l_max = 150

#initializing value of B
B_j,B_i = np.where(H == 1)
B = [[],[],[],[]]
for temp_index in range(B_j.size):
    B[B_j[temp_index]].append(B_i[temp_index])

"""B_j = np.where(H == 1)
B = B_j[1].reshape(m, w_c)"""

#Iteration count
l = 0
while l <= l_max:

#Step 1: Check messages
    for j in range (m):
        for i in range (N):
            for i_prime in B[j]:
                if i != i_prime:
                    #E[j][i] = np.bitwise_xor(E[j][i], M[i_prime])
                    E[j][i] ^= M[i_prime]

#Step 2: Bit messages
    for i in range (N):
        for i_prime in B[j]:
            M_i[i] = (E[:, i] == 1). sum()
            if y[i] == 1 and M_i[i] < 2:
                M[i] = y[i] ^ 1
            elif y[i] == 0 and M_i[i] > 2:
                M[i] = y[i] ^ 1
            elif y[i] == 1 and M_i[i] < 2:
                M[i] = y[i] ^ 1
            elif y[i] == 0 and M_i[i] > 2:
                M[i] = y[i] ^ 1

#Stopping criteria
    for j in range (m):
        for i_prime in B[j]:
            s[j] ^= M[i_prime]

    count = np.sum(s)

    if count == 0:
        print ("The codeword is: ", M)
        print ("Found at step: ", l)
        break
    elif l == l_max:
        print ("The codeword is failed to obtain since Maximum iteration has achieved.")
        break
    elif count != 0:
        l = l + 1
        continue
In this code, even though I change the value of y (in line 9) into [0 0 1 0 1 1], the result is the same as the manually calculated equation. Please forgive me for being too hasty. Blush

P.S.:
you can change the value of y to any set of numbers such as [0 1 1 0 0 1], [1 0 1 0 1 1], ...
Reply


Messages In This Thread
bit-flipping decoding - by divon - Aug-18-2021, 08:16 AM
RE: bit-flipping decoding - by jefsummers - Aug-18-2021, 02:15 PM
RE: bit-flipping decoding - by divon - Aug-19-2021, 02:16 AM
RE: bit-flipping decoding - by Larz60+ - Aug-18-2021, 06:57 PM
RE: bit-flipping decoding - by divon - Aug-19-2021, 02:31 AM
RE: bit-flipping decoding - by divon - Aug-19-2021, 10:32 AM
RE: bit-flipping decoding - by divon - Aug-20-2021, 08:40 AM
RE: bit-flipping decoding - by divon - Aug-24-2021, 11:33 PM
RE: bit-flipping decoding - by divon - Aug-25-2021, 12:52 AM
RE: bit-flipping decoding - by Larz60+ - Aug-25-2021, 03:13 AM
RE: bit-flipping decoding - by divon - Aug-26-2021, 11:25 PM
RE: bit-flipping decoding - by Larz60+ - Aug-27-2021, 02:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  base64 decoding paul18fr 0 1,317 Mar-13-2022, 05:56 PM
Last Post: paul18fr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020