📄 enc.c
字号:
/* ENC.C - Encoding procedures. */
/* Copyright (c) 2000, 2001 by Radford M. Neal
*
* Permission is granted for anyone to copy, use, or modify this program
* for purposes of research or education, provided this copyright notice
* is retained, and note is made of any changes that have been made.
*
* This program is distributed without any warranty, express or implied.
* As this program was written for research purposes only, it has not been
* tested to the degree that would be advisable in any important application.
* All use of this program is entirely at the user's own risk.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "rand.h"
#include "alloc.h"
#include "mod2sparse.h"
#include "rcode.h"
#include "enc.h"
/* The procedures in this module obtain the generator matrix to use for
encoding from the global variables declared in rcode.h */
/* ENCODE A BLOCK USING A SPARSE REPRESENTATION OF THE GENERATOR MATRIX. */
//使用生成矩阵的稀疏矩阵表示编码一个分组
void sparse_encode
( int *sblk, //源比特(N-M)
int *cblk //编码比特N
)
{
int i, j;
mod2entry *e;
int *x, *y;
x = chk_alloc (M, sizeof *x);
y = chk_alloc (M, sizeof *y);
/* Multiply the vector of source bits by the systematic columns of the
parity check matrix, giving x. Also copy these bits to the coded block. */
for (i = 0; i<M; i++) x[i] = 0;
for (j = M; j<N; j++)
{
cblk[cols[j]] = sblk[j-M];
if (sblk[j-M]==1)
{ for (e = mod2sparse_first_in_col(H,cols[j]);
!mod2sparse_at_end(e);
e = mod2sparse_next_in_col(e))
{ x[mod2sparse_row(e)] ^= 1;
}
}
}
/* Solve Ly=x for y by forward substitution, then U(cblk)=y by backward
substitution. */
if (!mod2sparse_forward_sub(L,rows,x,y)
|| !mod2sparse_backward_sub(U,cols,y,cblk))
{
abort(); /* Shouldn't occur, even if the parity check matrix has
redundant rows */
}
free(x);
free(y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -