UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ldpc-matrix.cpp
Go to the documentation of this file.
1/*
2 * =====================================================================================
3 *
4 * Filename: ldpc-matrix.c
5 *
6 * Description: Generates LDPC Staircase matrix
7 *
8 * Version: 1.0
9 * Created: 04/14/2012 10:50:43 PM
10 * Revision: none
11 * Compiler: gcc
12 *
13 * Author: Milan Kabat (), kabat@ics.muni.cz
14 * Company: FI MUNI
15 *
16 * =====================================================================================
17 */
18
19#include <time.h>
20#include <stdlib.h>
21
22#include "ldpc-matrix.h"
23#include "rand_pmms.h"
24
25
26/* Computes degree of a given row of the given matrix */
27int degree_of_row ( char **matrix, int row, int column_num )
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}
38
39
40void left_matrix_init ( char **matrix, int k, int n, int N1, int seed )
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}
102
103void right_matrix_staircase_init ( char **matrix, int k, int n )
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}
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
void right_matrix_staircase_init(char **matrix, int k, int n)
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)
#define LDGM_MAX_K
Definition ldpc-matrix.h:19