(Aug-25-2021, 03:13 AM)Larz60+ Wrote: Thanks for sharing solutionYou'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 continueIn 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.

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], ...