Advertisement
makispaiktis

Test.m

Jan 23rd, 2022
1,023
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %% Close all figures, clear workspace and console
  2. close all;
  3. clear;
  4. clc;
  5.  
  6. %% Application - Hamming Code
  7. %l_max = 3;
  8. %r_max = 6;
  9. l_optimum = [0.3, 0.5, 0.2];        
  10. r_optimum = [0.2, 0.2, 0.1, 0.1, 0.3, 0.1];
  11. n = 201;
  12. [H, num_variables, num_checks]= LDPC_simulation(n, l_optimum, r_optimum);
  13.  
  14. if isnan(H)
  15.     disp("Unavailable to use this n")
  16.     return
  17. end
  18.  
  19. er = 0.1;
  20.  
  21.  
  22. %% BEC
  23. % Message is the zero codeword (49) - codeword = x (200)
  24. x = zeros(1, n);
  25. [y, err] = bec(x, er);
  26. disp("x = " + num2str(x))
  27. disp("y = " + num2str(y))
  28. disp("Initial errors: " + num2str(sum(err)));      
  29.                                  
  30.  
  31.  
  32. %% Implementing the Graph
  33.  
  34. var_nodes = cell(1, num_variables);
  35.  
  36. for i = 1:num_variables
  37.    
  38.    var_nodes{i} = connections(H,i,y);
  39.    
  40. end
  41.  
  42. check_nodes = cell(1,num_checks);
  43.  
  44. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. % WS EDW OK
  46.  
  47. for i = 1:num_checks
  48.    
  49.    check_nodes{i} = var2check(H,i,y,1);
  50.  
  51. end
  52.  
  53. % Iterations
  54. limit = 100;
  55. counter = 0;
  56. SUM_ALL = Inf;
  57. while (counter <= limit) && SUM_ALL == Inf
  58.    
  59.     counter = counter + 1;
  60.    
  61.     if counter > 1
  62.         for i = 1:num_checks
  63.  
  64.             check_nodes =...
  65.             var2check_updated(var_nodes,check_nodes,y,i);
  66.  
  67.         end
  68.     end
  69.    
  70.     check_to_var = check2var(check_nodes, num_checks);
  71.     var_nodes = edges_values(var_nodes, check_to_var);
  72.     var_rec_sum = var_rec(var_nodes, y);
  73.     SUM_ALL = sum(var_rec_sum);
  74.    
  75.    
  76. end
  77.  
  78. var_values = var_rec_sum;
  79.  
  80. disp(' ')
  81. disp("x^ = " + num2str(var_values));
  82. % disp("Initial errors: " + num2str(sum(err)));
  83. disp("Final errors: " + length(nonzeros(abs(x-var_values))))
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement