Advertisement
makispaiktis

test_with_stats_and_plots.m

Jan 23rd, 2022
1,045
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.  
  7. %% Application - LDPC CODE
  8. %l_max = 3;
  9. %r_max = 6;
  10. l_optimum = [0.3, 0.5, 0.2];        
  11. r_optimum = [0.2, 0.2, 0.1, 0.1, 0.3, 0.1];
  12.  
  13.  
  14. begin_n = 101;
  15. end_n = 201;
  16. step_n = 5;
  17. n_list = begin_n : step_n : end_n;
  18. all_n = floor((end_n - begin_n) / step_n) + 1;
  19.  
  20.  
  21.  
  22.  
  23. for index = 1:length(n_list)
  24.     n = n_list(index);
  25.     [H, num_variables, num_checks, num_edges, rate_expected, counter_tries, initial_errors, final_errors]= LDPC_simulation_stats_plots(n, l_optimum, r_optimum, "find_appropriate_n");
  26.     if isnan(H)
  27.         n_list(index) = 0;
  28.     end
  29. end
  30.  
  31.  
  32.  
  33.  
  34. %% Our data - stats variables
  35. n_list = nonzeros(n_list);
  36. LEN = length(n_list);
  37. er = 0.1;
  38. var_num_list = zeros(1, LEN);
  39. check_num_list = zeros(1, LEN);
  40. edges_num_list = zeros(1, LEN);
  41. rates_list = zeros(1, LEN);
  42. tries_list = zeros(1, LEN);
  43. initial_list = zeros(1, LEN);
  44. final_list = zeros(1, LEN);
  45.  
  46.  
  47.  
  48.  
  49. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. for INDEX = 1:LEN
  52.    
  53.    
  54.    
  55.     n = n_list(INDEX);
  56.     [H, num_variables, num_checks, num_edges, rate_expected, counter_tries, initial_errors, final_errors]= LDPC_simulation_stats_plots(n, l_optimum, r_optimum, "anakyklwseis");
  57.    
  58.    
  59.    
  60.    
  61.     %% Implementing the BEC and Graph
  62.     x = zeros(1, n);
  63.     [y, err] = bec(x, er);
  64.     var_nodes = cell(1, num_variables);
  65.  
  66.     for i = 1:num_variables    
  67.        var_nodes{i} = connections(H,i,y);    
  68.     end
  69.  
  70.     check_nodes = cell(1,num_checks);
  71.  
  72.     for i = 1:num_checks  
  73.        check_nodes{i} = var2check(H,i,y,1);
  74.     end
  75.  
  76.     % Iterations
  77.     limit = 100;
  78.     counter = 0;
  79.     SUM_ALL = Inf;
  80.     while (counter <= limit) && SUM_ALL == Inf
  81.  
  82.         counter = counter + 1;    
  83.         if counter > 1
  84.             for i = 1:num_checks
  85.                 check_nodes =...
  86.                 var2check_updated(var_nodes,check_nodes,y,i);
  87.             end
  88.         end
  89.  
  90.         check_to_var = check2var(check_nodes, num_checks);
  91.         var_nodes = edges_values(var_nodes, check_to_var);
  92.         var_rec_sum = var_rec(var_nodes, y);
  93.         SUM_ALL = sum(var_rec_sum);
  94.  
  95.  
  96.     end
  97.  
  98.    
  99.    
  100.    
  101.     var_values = var_rec_sum;
  102.     initial_errors = sum(err);
  103.     final_errors = length(nonzeros(abs(x-var_values)));
  104.    
  105.     % FOR STATISTICS PURPOSE
  106.     var_num_list(INDEX) = num_variables;
  107.     check_num_list(INDEX) = num_checks;
  108.     edges_num_list(INDEX) = num_edges;
  109.     rates_list(INDEX) = rate_expected;
  110.     tries_list(INDEX) = counter_tries;
  111.     initial_list(INDEX) = initial_errors;
  112.     final_list(INDEX) = final_errors;
  113.    
  114.    
  115.    
  116. end
  117. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127. %% STATS
  128. display(' ');
  129. display(' ');
  130. pretty_display("      Appropriate n list:      ", n_list');
  131. pretty_display("Num of variables nodes list:   ", var_num_list);
  132. pretty_display("   Num of check nodes list:    ", check_num_list);
  133. pretty_display("      Num of edges list:       ", edges_num_list);
  134. pretty_display("     Expected rate list:       ", rates_list);
  135. pretty_display("Tries to find NO RECYCLE list: ", tries_list);
  136. pretty_display("       Initial errors list:    ", initial_list);
  137. pretty_display("       Final errors list:      ", final_list);
  138. display(' ');
  139.  
  140. appropriate_n = length(n_list);
  141. perc100 = round(100 * appropriate_n / all_n, 2);
  142. disp("In the interval [" + num2str(begin_n) + ", " + num2str(end_n) + "] with step = " + num2str(step_n) + ": ");
  143. disp("There are " + num2str(appropriate_n) + "/" + num2str(all_n) + ...
  144.     " values of 'n', that can be used for this LDPC code.");
  145. disp("Percentage = " + num2str(perc100) + "%");
  146.  
  147.    
  148. %% PLOTS
  149. figure(1);
  150. plot(n_list, var_num_list, 'black');
  151. title("Graph characteristics");
  152. xlabel("n = message length (variables)");
  153. ylabel("Var, check, edges");
  154. hold on
  155. plot(n_list, check_num_list, 'blue');
  156. hold on
  157. plot(n_list, edges_num_list, 'red');
  158. legend("Variables", "Checks", "Edges");
  159.  
  160. figure(2);
  161. plot(n_list, rates_list, 'black');
  162. title("Transmission rate 'r'");
  163. xlabel("n = message length (variables)");
  164. ylabel("Rate = r = r(n)");
  165.  
  166. figure(3);
  167. plot(n_list, tries_list, 'black');
  168. title("Tries until perfect graph");
  169. xlabel("n = message length (variables)");
  170. ylabel("Tries = Tries(n)");
  171.  
  172. figure(4);
  173. plot(n_list, initial_list, 'black');
  174. hold on
  175. plot(n_list, final_list, 'blue');
  176. title("Initial and final codeword errors");
  177. xlabel("n = message length (variables)");
  178. ylabel("Errors in codeword");
  179. legend("Initial errors", "Final errors");
  180. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  181. % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  182.  
  183.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement