UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ldpc-matrix.cpp File Reference
#include <time.h>
#include <stdlib.h>
#include "ldpc-matrix.h"
#include "rand_pmms.h"
Include dependency graph for ldpc-matrix.cpp:

Go to the source code of this file.

Functions

int degree_of_row (char **matrix, int row, int column_num)
 
void left_matrix_init (char **matrix, int k, int n, int N1, int seed)
 
void right_matrix_staircase_init (char **matrix, int k, int n)
 

Function Documentation

◆ degree_of_row()

int degree_of_row ( char ** matrix,
int row,
int column_num )

Definition at line 27 of file ldpc-matrix.cpp.

28{
29 int j = 0;
30 int deg = 0;
31
32 for ( j = 0; j < column_num; j++ )
33 if ( matrix[row][j] )
34 deg++;
35
36 return deg;
37}

Referenced by left_matrix_init().

◆ left_matrix_init()

void left_matrix_init ( char ** matrix,
int k,
int n,
int N1,
int seed )

Definition at line 40 of file ldpc-matrix.cpp.

41{
42 int i; /* Row index */
43 int j; /* Column index */
44 int h; /* Temporary variable */
45 int t; /* Left limit within the list of possible choices u[] */
46 int u[3*LDGM_MAX_K]; /* A table used to have a homogenous 1 distribution. */
47
48 Rand_pmms rand_gen;
49 rand_gen.seedi(seed);
50
51 for ( h = N1*k - 1; h >= 0; h--)
52 {
53 u[h] = h % (n-k);
54 }
55
56 /* Initialize the matrix with N1 "1s" per column, homogenously */
57 t = 0;
58 for ( j = 0; j < k; j++ ) /* for each source symbol column */
59 {
60 for ( h = 0; h < N1; h++ ) /* put N1 "1s" */
61 {
62 /* Check wether valid available choices remain */
63 for ( i = t; i < N1*k && matrix [u[i]] [j] ; i++);
64 if ( i < N1*k )
65 {
66 /* Choose one index from possible choices */
67 do {
68 i = t + rand_gen.pmms_rand ( N1*k - t);
69 } while ( matrix [u[i]] [j]);
70 matrix [u[i]] [j] = 1;
71
72 /* Replace with u[t] */
73 u[i] = u[t];
74 t++;
75 } else {
76 /* No available choices, pick at random */
77 do {
78 i = rand_gen.pmms_rand ( n-k );
79 } while ( matrix[i][j] );
80 matrix[i][j] = 1;
81 }
82 }
83 }
84
85 /* Add extra bits to avoid rows with less than two "1s". */
86 for ( i = 0; i < n-k; i++ )
87 {
88 if ( degree_of_row ( matrix, i, k ) == 0 )
89 {
90 j = rand_gen.pmms_rand(k);
91 matrix[i][j] = 1;
92 }
93 if ( degree_of_row ( matrix, i, k ) == 1 )
94 {
95 do {
96 j = rand_gen.pmms_rand(k);
97 } while ( matrix[i][j] );
98 matrix[i][j] = 1;
99 }
100 }
101}
void seedi(unsigned long int s)
Definition rand_pmms.h:28
unsigned long int pmms_rand(unsigned long int maxv)
Definition rand_pmms.h:35
int degree_of_row(char **matrix, int row, int column_num)
#define LDGM_MAX_K
Definition ldpc-matrix.h:19

References degree_of_row(), LDGM_MAX_K, Rand_pmms::pmms_rand(), and Rand_pmms::seedi().

Referenced by generate_ldgm_matrix().

Here is the call graph for this function:

◆ right_matrix_staircase_init()

void right_matrix_staircase_init ( char ** matrix,
int k,
int n )

Definition at line 103 of file ldpc-matrix.cpp.

104{
105 int i;
106
107 matrix[0][k] = 1;
108 for ( i = 1; i < n-k; i++)
109 {
110 matrix[i][k+i] = 1;
111 matrix[i][k+i-1] = 1;
112 }
113}