# include<ittc/ittc_comm/ittc_ldpc.h>
static const double infinity_llr = 1e20;
static void creat_logexp_table(ittc_vec *table, int Dint1, int Dint2, int Dint3)
{
// by default Dint1 = 12, Dint2 = 300; Dint3 = 7;
// Dint1 Determine the relation between LLR represented as real number and as integer. The relation is
// QLLR = round(2^Dint1 * LLR)
// Dint2 Number of entries in the table. If this is zero, then logmap becomes logmax.
// Dint3 Determines the table resolution. The spacing between each entry is
// 2^(-(Dint1-Dint3))
ittc_assert(table != NULL,"creat_logexp_table: null point");
ittc_assert(table->size == Dint2, "creat_logexp_table: not matched size");
for(int i = 0; i < Dint2; i++)
{
double x = pow(2.0, (double)(Dint3-Dint1) )*i;
ittc_vec_set(table, i, log(1+exp(-x)));
}
}
static double llr_logexp(double x, ittc_vec *table, int Dint1, int Dint2, int Dint3)
{
// return log(1+exp(-x))
int ind = (int)((x*(1<<(Dint1-Dint3)))+0.5);
if(ind<0 || ind >=Dint2)
{
ind = Dint2-1;
}
return ittc_vec_get(table,ind);
}
static double max_star(double x1, double x2, ittc_vec *logexp_table, int Dint1, int Dint2, int Dint3)
{
double res = 0;
res = (x1 > x2)?x1:x2;
res += llr_logexp(fabs(x1-x2), logexp_table, Dint1, Dint2, Dint3);
return res;// res = max(x1,x2) + ln(1+exp(-|x1-x2|))
}
static double max_star(double x1, double x2)
{
double res = 0;
res = (x1 > x2)?x1:x2;
res += log(1+exp(-fabs(x1-x2)));
return res;// res = max(x1,x2) + ln(1+exp(-|x1-x2|))
}
ittc_ldpc_code *ittc_ldpc_code_alloc(ittc_sparse_imat * H_sps)
{
ittc_assert(H_sps!=NULL,"ittc_ldpc_code_alloc: null pointer");
ittc_assert(H_sps->col!=NULL,"ittc_ldpc_code_alloc: null pointer");
ittc_ldpc_code *ldpc = (ittc_ldpc_code *)malloc(sizeof(ittc_ldpc_code));
ittc_assert(ldpc!=NULL,"ittc_ldpc_code_alloc: ran out of memory");
/* construct an sparse representation of parity-check matrix */
int m = H_sps->n_rows;
int n = H_sps->n_cols;
ldpc->H = (ittc_parity_check_matrix *)malloc(sizeof(ittc_parity_check_matrix));
ittc_assert(ldpc->H!=NULL,"ittc_ldpc_code_alloc: ran out of memory");
ldpc->H->num_check = m;
ldpc->H->num_symbol = n;
ldpc->H->cn = (ittc_ldpc_check_node *)malloc(m*sizeof(ittc_ldpc_check_node));
ittc_assert(ldpc->H->cn!=NULL,"ittc_ldpc_code_alloc: ran out of memory");
for(int i = 0; i < ldpc->H->num_check; i++)
{
ldpc->H->cn[i].right = NULL;
}
ldpc->H->sn = (ittc_ldpc_symbol_node *)malloc(n*sizeof(ittc_ldpc_symbol_node));
ittc_assert(ldpc->H->sn!=NULL,"ittc_ldpc_code_alloc: ran out of memory");
for(int i = 0; i < ldpc->H->num_symbol; i++)
{
ldpc->H->sn[i].down = NULL;
}
ldpc->H->num_zeros = 0;
// count the number of nonzero elements
for(int j = 0; j < n; j++)
{
ittc_assert(H_sps->col[j]!=NULL, "ittc_ldpc_code_alloc: null pointer");
for(int ii = 0; ii < H_sps->col[j]->used_size; ii++)
{
if(H_sps->col[j]->dat[ii]!=0)
{
++ldpc->H->num_zeros;
}
}
}
ldpc->H->list = (ittc_ldpc_node*)malloc( ldpc->H->num_zeros * sizeof(ittc_ldpc_node));
ittc_assert(ldpc->H->list!=NULL,"ittc_ldpc_code_alloc: ran out of memory");
for(int i = 0; i < ldpc->H->num_zeros; i++)
{
ldpc->H->list[i].down = NULL;
ldpc->H->list[i].right = NULL;
}
// construct the sparse-structured H
int lst_ind = 0;
ittc_ldpc_node *cp; // point to current node
ittc_ldpc_node *np; // point to next node
for(int j = 0; j < n; j++)
{
for(int ii = 0; ii < H_sps->col[j]->used_size; ii++)
{
if(H_sps->col[j]->dat[ii]!=0)
{
int i = H_sps->col[j]->index[ii];
cp = &ldpc->H->list[lst_ind];
++lst_ind;
/* vertical */
np = ldpc->H->sn[j].down;
if(np==NULL)/* this is the first nonzero element under sn[j] */
{
ldpc->H->sn[j].down = cp;
}
else
{
while(np->down!=NULL)/* point np to the last element of sn[j] */
{
np = np->down;
}
np->down = cp;
}
/* horizontal link */
np = ldpc->H->cn[i].right;
if(np==NULL)/* this is the first nonzero element under cn[i] */
{
ldpc->H->cn[i].right = cp;
}
else
{
while(np->right!=NULL)/* point np to the last element of cn[i] */
{
np = np->right;
}
np->right = cp;
}
/* record the position */
cp->i = i;
cp->j = j;
cp->right = NULL;
cp->down = NULL;
}//endif: end of recording current node.
}
}
ldpc->flag_dec_init = 0;
ldpc->G_sps = NULL;
ldpc->Gt_sps = NULL;
//ldpc->H_den = ittc_imat_alloc(m,n);
//ittc_imat_memcpy(H_den, ldpc->H_den);
//ldpc->H_den = NULL;
ldpc->H_sps = ittc_sparse_imat_alloc(m,n,1);
ittc_sparse_imat_memcpy(H_sps, ldpc->H_sps );
ldpc->Ht_sps = ittc_sparse_imat_alloc(n,m,1);
ittc_sparse_imat_T(ldpc->H_sps, ldpc->Ht_sps);
ldpc->max_iterations = 10000;//default value
ldpc->num_coded = n;
ldpc->num_uncoded = n-m;
ldpc->rate = (n-m)/n;
ldpc->bit_order = NULL;
ldpc->Dint1 = 12;
ldpc->Dint2 = 1000;
ldpc->Dint3 = 7;
ldpc->logexp_table = ittc_vec_alloc(ldpc->Dint2);
creat_logexp_table(ldpc->logexp_table, ldpc->Dint1, ldpc->Dint2, ldpc->Dint3);
return ldpc;
}
void ittc_ldpc_code_free(ittc_ldpc_code *ldpc)
{
ittc_assert(ldpc!=NULL,"ittc_ldpc_code_free: null pointer");
if(ldpc->G_sps!=NULL)
ittc_sparse_imat_zap(&ldpc->G_sps);
if(ldpc->Gt_sps!=NULL)
ittc_sparse_imat_zap(&ldpc->Gt_sps);
if(ldpc->H_sps!=NULL)
ittc_sparse_imat_zap(&ldpc->H_sps);
if(ldpc->Ht_sps!=NULL)
ittc_sparse_imat_zap(&ldpc->Ht_sps);
if(ldpc->H!=NULL)
{
if(ldpc->H->cn!=NULL)
free(ldpc->H->cn);
if(ldpc->H->sn!=NULL)
free(ldpc->H->sn);
if(ldpc->H->list!=NULL)
free(ldpc->H->list);
}
free(ldpc->H);
if(ldpc->logexp_table!=NULL)
ittc_vec_free(ldpc->logexp_table);
if(ldpc->bit_order!=NULL)
ittc_ivec_free(ldpc->bit_order);
free(ldpc);
}
void ittc_ldpc_load_gmat(ittc_ldpc_code *ldpc, ittc_sparse_imat *g)
{
ittc_assert(ldpc!=NULL, "ittc_ldpc_load_gmat: null pointer");
ittc_assert(g!=NULL, "ittc_ldpc_load_gmat: null pointer");
ittc_assert(g->n_cols==ldpc->num_coded && g->n_rows==ldpc->num_uncoded, "ittc_ldpc_load_gmat: not matched size");
if(ldpc->G_sps==NULL)
{
ldpc->G_sps = ittc_sparse_imat_alloc(g->n_rows, g->n_cols, 3);
}
if(ldpc->Gt_sps==NULL)
{
ldpc->Gt_sps = ittc_sparse_imat_alloc(g->n_cols, g->n_rows, 3);
}
ittc_sparse_imat_memcpy(g, ldpc->G_sps);
ittc_sparse_imat_T(ldpc->G_sps, ldpc->Gt_sps);
}
void ittc_ldpc_encoding(ittc_ivec *uncoded, ittc_ivec *coded, ittc_ldpc_code *ldpc)
{
ittc_assert(uncoded!=NULL, "ittc_ldpc_encoder: null pointer");
ittc_assert(coded!=NULL, "ittc_ldpc_encoder: null pointer");
ittc_assert(uncoded!=NULL, "ittc_ldpc_encoder: null pointer");
ittc_assert(ldpc!=NULL, "ittc_ldpc_encoder: null pointer");
ittc_assert(ldpc->G_sps!=NULL, "ittc_ldpc_encoder: generate matrix has not been loaded");
int k = uncoded->size;
int n = coded->size;
ittc_assert(k==ldpc->num_uncoded, "ittc_ldpc_encoder: not proper size of uncoded sequence");
ittc_assert(n==ldpc->num_coded, "ittc_ldpc_encoder: not proper size of coded sequence");
int tmp;
if(ldpc->G_sps!=NULL)
{
for(int j = 0; j < n; j++ )
{
tmp = 0;
for(int ii = 0; ii < ldpc->G_sps->col[j]->used_size; ii++)
{
int i = ldpc->G_sps->col[j]->index[ii];
int gv = ldpc->G_sps->col[j]->dat[ii];
tmp += gv*ittc_ivec_get(uncoded,i);
}
tmp &= 1;
ittc_ivec_set(coded, j, tmp);
}
}
else
{
ittc_assert(0,"ittc_ldpc_encoder: not possible error");
}
}
void ittc_ldpc_bpsk_mapper(ittc_ivec *seq_in, ittc_vec *seq_out)
{
ittc_assert(seq_in!=NULL,"ittc_ldpc_bpsk_mapper: null pointer");
ittc_assert(seq_out!=NULL,"ittc_ldpc_bpsk_mapper: null pointer");
ittc_assert(seq_in->size==seq_out->size,"ittc_ldpc_bpsk_mapper: not matched size");
for(int i = 0
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ittc.rar (95个子文件)
ittc
ittc_comm
ittc_rsc_code.h 4KB
ittc_ovsf.cpp 3KB
sources.mk 1KB
ittc_sequence.h 4KB
ittc_ldpc.cpp 49KB
ittc_turbo.cpp 19KB
ittc_mimo_channel.h 2KB
ittc_fading.cpp 28KB
ittc_grake.h 2KB
ittc_spreading.h 2KB
ittc_modulator.h 1KB
ittc_interleaver.cpp 18KB
ittc_modulator.cpp 7KB
ittc_spreading.cpp 3KB
ittc_wcdma
ittc_hspar9_ccpch.h 269B
sources.mk 1KB
ittc_hspar9_scrambler.cpp 5KB
ittc_hspar9_sim_hsdpa.cpp 43KB
ittc_hspar9_hsdsch.cpp 46KB
ittc_hspar9_hsdsch.h 4KB
ittc_hspar9_modulator.h 957B
ittc_hspar9_hspdsch.cpp 11KB
Makefile.am 314B
ittc_hspar9_modulator.cpp 11KB
ittc_hspar9_sim_hsdpa.h 2KB
Makefile.in 28KB
ittc_hspar9_hspdsch.h 2KB
ittc_hspar9_cpich.h 255B
ittc_hspar9_scrambler.h 1KB
ittc_hspar9_cpich.cpp 2KB
ittc_hspar9.h 479B
ittc_hspar9_ccpch.cpp 2KB
ittc_turbo.h 3KB
Makefile.am 385B
ittc_llr.h 730B
ittc_rsc_code.cpp 38KB
ittc_channel.h 4KB
Makefile.in 39KB
ittc_channel.cpp 7KB
ittc_grake.cpp 18KB
ittc_interleaver.h 2KB
ittc_fading.h 4KB
ittc_ovsf.h 392B
ittc_sequence.cpp 6KB
ittc_mimo_channel.cpp 10KB
ittc_ldpc.h 7KB
ittc_llr.cpp 4KB
sources.mk 152B
ittc_comm.h 964B
config.h.in 4KB
.ctagsdb 164KB
ittc_signal
sources.mk 445B
ittc_transform.cpp 6KB
ittc_filter.cpp 9KB
ittc_sigfun.h 835B
ittc_transform.h 847B
Makefile.am 288B
Makefile.in 22KB
ittc_window.h 123B
ittc_sigfun.cpp 4KB
ittc_window.cpp 391B
ittc_filter.h 2KB
config_msvc.h 5KB
Makefile.am 1KB
ittc_base
ittc_galois.h 889B
ittc_assert.cpp 388B
sources.mk 913B
ittc_algebra.cpp 14KB
ittc_vec.h 11KB
ittc_math.h 1KB
ittc_algebra.h 5KB
ittc_mat.cpp 48KB
ittc_array.h 6KB
ittc_vec.cpp 31KB
Makefile.am 307B
ittc_mat.h 13KB
ittc_random.cpp 7KB
Makefile.in 33KB
ittc_complex.h 2KB
ittc_blas.h 5KB
ittc_array.cpp 12KB
ittc_lapack.h 9KB
ittc_math.cpp 4KB
ittc_assert.h 3KB
ittc_galois.cpp 5KB
ittc_random.h 4KB
Makefile.in 25KB
ittc_signal.h 352B
ittc_base.h 2KB
ittc_ann.h 96B
ittc_ann
sources.mk 146B
ittc_transfun.h 461B
Makefile.am 284B
Makefile.in 19KB
ittc_transfun.cpp 873B
共 95 条
- 1
资源评论
alvarocfc
- 粉丝: 109
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功