📄 common.c
字号:
+ r2[((i-1)*S+laststate_matrix[2*j+1])*2+1];
a2[i*S+j] = g(t0, t1);
}
}//end of computing alfa2
//compute the beta2
for(i=L-1; i>0; i--)
{
for(j=0; j<S; j++)
{
t0 = b2[(i+1)*S+nextstate_matrix[2*j+0]]
+ r2[(i*S+j)*2+0];
t1 = b2[(i+1)*S+nextstate_matrix[2*j+1]]
+ r2[(i*S+j)*2+1];
b2[i*S+j] = g(t0,t1);
}
}//end of computing beta2
for(i=0; i<L; i++)
{
nom = a2[i*S+0] + rc2[(i*S+0)*2+1]
+ b2[(i+1)*S+nextstate_matrix[2*0+1]];
denom = a2[i*S+0] + rc2[(i*S+0)*2+0]
+ b2[(i+1)*S+nextstate_matrix[2*0+0]];
for(j=1; j<S; j++)
{
nom = g(nom, a2[i*S+j] + rc2[(i*S+j)*2+1]
+ b2[(i+1)*S+nextstate_matrix[2*j+1]]);
denom = g(denom, a2[i*S+j] + rc2[(i*S+j)*2+0]
+ b2[(i+1)*S+nextstate_matrix[2*j+0]]);
}
L2[i] = nom - denom;
if (L2[i] < -0.001*inf)
{
L2[i] = -0.001*inf;
}
if (L2[i] > 0.001*inf)
{
L2[i] = 0.001*inf;
}
}
//end of D2 process
deinterleave_double(temp_L, L2, Len, interleave_table);
for(i=0; i<L; i++)
{
L2[i] = temp_L[i];
new_llr[i] = L2[i];
}
deinterleave_double(temp_L, L1, Len, interleave_table);
for(i=0; i<L; i++)
{
L1[i] = temp_L[i];
}
}//end of iteration
for(i=0; i<L; i++)
{
t0 = a1[i*S+0] + r1[(i*S+0)*2+0] - rc1[(i*S+0)*2+0] + b1[(i+1)*S+nextstate_matrix[2*0+0]];
t1 = a1[i*S+0] + r1[(i*S+0)*2+1] - rc1[(i*S+0)*2+1] + b1[(i+1)*S+nextstate_matrix[2*0+1]];
if (output_matrix[2*0+0] == 1)
{
nom = t0;
denom = t1;
}
else
{
nom = t1;
denom = t0;
}
for(j=1; j<S; j++)
{
t0 = a1[i*S+j] + r1[(i*S+j)*2+0] - rc1[(i*S+j)*2+0] + b1[(i+1)*S+nextstate_matrix[2*j+0]];
t1 = a1[i*S+j] + r1[(i*S+j)*2+1] - rc1[(i*S+j)*2+1] + b1[(i+1)*S+nextstate_matrix[2*j+1]];
if (output_matrix[2*j+0] == 1)
{
nom = g(nom, t0);
denom = g(denom, t1);
}
else
{
nom = g(nom, t1);
denom = g(denom, t0);
}
}
llrp1[i] = nom - denom;
if (llrp1[i] < -0.001*inf)
{
llrp1[i] = -0.001*inf;
}
if (llrp1[i] > 0.001*inf)
{
llrp1[i] = 0.001*inf;
}
}
for(i=0; i<Len; i++)
{
t0 = a2[i*S+0] + r2[(i*S+0)*2+0] - rc2[(i*S+0)*2+0] + b2[(i+1)*S+nextstate_matrix[2*0+0]];
t1 = a2[i*S+0] + r2[(i*S+0)*2+1] - rc2[(i*S+0)*2+1] + b2[(i+1)*S+nextstate_matrix[2*0+1]];
if (output_matrix[2*0+0] == 1)
{
nom = t0;
denom = t1;
}
else
{
nom = t1;
denom = t0;
}
for(j=1; j<S; j++)
{
t0 = a2[i*S+j] + r2[(i*S+j)*2+0] - rc2[(i*S+j)*2+0] + b2[(i+1)*S+nextstate_matrix[2*j+0]];
t1 = a2[i*S+j] + r2[(i*S+j)*2+1] - rc2[(i*S+j)*2+1] + b2[(i+1)*S+nextstate_matrix[2*j+1]];
if (output_matrix[2*j+0] == 1)
{
nom = g(nom, t0);
denom = g(denom, t1);
}
else
{
nom = g(nom, t1);
denom = g(denom, t0);
}
}
llrp2[i] = nom - denom;
if (llrp2[i] < -0.001*inf)
{
llrp2[i] = -0.001*inf;
}
if (llrp2[i] > 0.001*inf)
{
llrp2[i] = 0.001*inf;
}
}
//decision: Just Output Decoded InfoBit(Not include TailBit).
for(i=0; i<L-Mem; i++)
{
decoded[i] = (msg[i] + L1[i] + L2[i] > 0) ? 1 : 0;
}
for(i=0; i<L; i++)
{
if (puncture)
{
//llr_all[2*i] = L1[i] + L2[i];
//llr_all[2*i+1] = (i%2) ? llrp2[i] : llrp1[i];
llr_all[2*i] = msg[i] + L1[i] + L2[i];
llr_all[2*i+1] = (i%2) ? (parity2[i]+llrp2[i]) : (parity1[i]+llrp1[i]);
}
else
{
//llr_all[3*i] = L1[i] + L2[i];
//llr_all[3*i+1] = llrp1[i];
//llr_all[3*i+2] = llrp2[i];
llr_all[3*i] = msg[i] + L1[i] + L2[i];
llr_all[3*i+1] = parity1[i] + llrp1[i];
llr_all[3*i+2] = parity2[i] + llrp2[i];
}
}
//free the memory
free(msg);
free(imsg);
free(parity1);
free(parity2);
free(L1);
free(L2);
free(llrp1);
free(llrp2);
free(temp_L);
free(a1);
free(a2);
free(b1);
free(b2);
free(r1);
free(r2);
free(rc1);
free(rc2);
free(ru1);
free(ru2);
free(output_matrix);
free(nextstate_matrix);
free(laststate_matrix);
free(tail_bit);
}
int TurboEncoder(short * p_InfoBit, int * p_CodedBit, CODE_PARAMETER * p_code_parm, int * p_CodeInlvTable)
{
int i;
int Len = p_code_parm->n_InfoBit_length;
int Mem = p_code_parm->n_CodeMemLength;
int g0 = p_code_parm->Code_Poly[0];
int g1 = p_code_parm->Code_Poly[1];
int pun = p_code_parm->n_puncture;
int * p_tmpInfoBit;
Len += Mem;
p_tmpInfoBit = (int *)malloc(Len*sizeof(int));
for(i=0; i<Len-Mem; i++)
{
*(p_tmpInfoBit+i) = (int)(*(p_InfoBit+i));
}
for(; i<Len; i++)
{
*(p_tmpInfoBit+i) = 0;
}
turbo_encode(p_tmpInfoBit, p_CodedBit, pun, Len, g0, g1, Mem, p_CodeInlvTable);
free(p_tmpInfoBit);
return 1;
}
int TurboDecoder(double * p_InfoBitLLR, double * p_CodedBitLLR, short * p_DecodedBit, CODE_PARAMETER * p_code_parm, int * p_CodeInlvTable, int n_IterNum)
{
int Len = p_code_parm->n_InfoBit_length;
int Mem = p_code_parm->n_CodeMemLength;
int g0 = p_code_parm->Code_Poly[0];
int g1 = p_code_parm->Code_Poly[1];
int pun = p_code_parm->n_puncture;
Len += Mem;
turbo_decode(p_DecodedBit, p_InfoBitLLR, p_InfoBitLLR, p_CodedBitLLR, p_CodedBitLLR, pun, Len, n_IterNum, p_CodeInlvTable, g0, g1, Mem);
return Len;
}
/* END _CODE_C_ */
///////////////////////////////////////////////////////////
/* _ASSEMBLE_FRAME_ */
int AssembleFrame(COMPLEX * p_ModedSym, COMPLEX * p_txSignal, BASEBAND_PARM * p_Baseband_Parm, int n_TxAntenna)
{
int i;
int n_slot;
int n_subslot;
int n_InPos = 0;
int n_OutPos = 0;
COMPLEX cmx_Pilot[PILOT_LENGTH];
COMPLEX cmx_Guard[GUARD_LENGTH];
GenerateGP(cmx_Pilot, cmx_Guard, n_TxAntenna);
for(n_slot=0; n_slot<p_Baseband_Parm->FRAME_SLOTNUM; n_slot++)
{
for(n_subslot=0; n_subslot<SUBSLOT_NUM; n_subslot++)
{
for(i=0; i<GUARD_LENGTH; i++)
{
(p_txSignal+n_OutPos)->real = cmx_Guard[i].real;
(p_txSignal+n_OutPos)->image = cmx_Guard[i].image;
n_OutPos++;
}
for(i=0; i<PILOT_LENGTH; i++)
{
(p_txSignal+n_OutPos)->real = cmx_Pilot[i].real;
(p_txSignal+n_OutPos)->image = cmx_Pilot[i].image;
n_OutPos++;
}
for(i=0; i<SUBSLOTDATA_LENGTH; i++)
{
(p_txSignal+n_OutPos)->real = (p_ModedSym+(n_slot*SUBSLOT_NUM+n_subslot)*SUBSLOTDATA_LENGTH+i)->real;
(p_txSignal+n_OutPos)->image = (p_ModedSym+(n_slot*SUBSLOT_NUM+n_subslot)*SUBSLOTDATA_LENGTH+i)->image;
n_OutPos++;
n_InPos++;
}
}
for(i=0; i<GUARD_LENGTH; i++)
{
(p_txSignal+n_OutPos)->real = cmx_Guard[i].real;
(p_txSignal+n_OutPos)->image = cmx_Guard[i].image;
n_OutPos++;
}
for(i=0; i<PILOT_LENGTH; i++)
{
(p_txSignal+n_OutPos)->real = cmx_Pilot[i].real;
(p_txSignal+n_OutPos)->image = cmx_Pilot[i].image;
n_OutPos++;
}
}
return n_OutPos;
}
int GenerateGP(COMPLEX * p_cmx_Pilot, COMPLEX * p_cmx_Guard, int n_TxAntenna)
{
int i;
int index;
// COMPLEX org_sequence[]={{1,0},{0,1},{1,0},{-1,0},{1,0},{1,0},{-1,0},{0,-1},{1,0},{0,-1},{1,0},{1,0},{1,0},{-1,0},{-1,0},{0,1}};
COMPLEX org_sequence[]={
{ 1.00000000000000, 0},{ 1.00000000000000, 0},{ 1.00000000000000, 0},{ 1.00000000000000, 0},
{ 0.70710678118655, -0.70710678118655},{ -1.00000000000000, 0},{ 0.70710678118655, 0.70710678118655},{ 0, -1.00000000000000},
{ 0, 1.00000000000000},{ -1.00000000000000, 0},{ 0, -1.00000000000000},{ 1.00000000000000, 0},
{ 0.70710678118655, 0.70710678118655},{ 1.00000000000000, 0},{ 0.70710678118655, -0.70710678118655},{ 0, -1.00000000000000},
{ -1.00000000000000, 0},{ 1.00000000000000, 0},{ -1.00000000000000, 0},{ 1.00000000000000, 0},
{ -0.70710678118655, 0.70710678118655},{ -1.00000000000000, 0},{ -0.70710678118655, -0.70710678118655},{ 0, -1.00000000000000},
{ 0, -1.00000000000000},{ -1.00000000000000, 0},{ 0, 1.00000000000000},{ 1.00000000000000, 0},
{ -0.70710678118655, -0.70710678118655},{ 1.00000000000000, 0},{ -0.70710678118655, 0.70710678118655},{ 0, -1.00000000000000}};
for(i=0; i<PILOT_LENGTH; i++)
{
index = (i-n_TxAntenna*PATH_NUM+PILOT_LENGTH)%PILOT_LENGTH;
p_cmx_Pilot[i].real = org_sequence[index].real;
p_cmx_Pilot[i].image = org_sequence[index].image;
}
for(i=0; i<GUARD_LENGTH; i++)
{
p_cmx_Guard[i].real = p_cmx_Pilot[i+PILOT_LENGTH-GUARD_LENGTH].real;
p_cmx_Guard[i].image = p_cmx_Pilot[i+PILOT_LENGTH-GUARD_LENGTH].image;
}
return (i+PILOT_LENGTH);
}
/* END _ASSEMBLE_FRAME_ */
///////////////////////////////////////////////////////////
/* _RAKE_CHEST_C_ */
int vec_cyc_cov(COMPLEX * x, int n_Len_x, COMPLEX * h, int n_Len_h, COMPLEX * y)
{
int i;
int n_SupDomain;
int n_Path;
int n_TxAntenna;
int n_RxAntenna;
int Index_h;
//Intialization
for(i=0; i<TxANTENNA_NUM*SUBSLOTDATA_LENGTH; i++)
{
(y+i)->real = (y+i)->image = 0;
}
//Rake Combine (Maybe the cycle order can be rearranged. TBD.)
for(n_Path=0; n_Path<PATH_NUM; n_Path++)
{
for(n_TxAntenna=0; n_TxAntenna<TxANTENNA_NUM; n_TxAntenna++)
{
for(n_SupDomain=0; n_SupDomain<MAXSUPDOM; n_SupDomain++)
{
for(i=SUP_DOM[n_SupDomain]; i<SUP_DOM[n_SupDomain+1]; i++)
{
for(n_RxAntenna=0; n_RxAntenna<RxANTENNA_NUM; n_RxAntenna++)
{
Index_h = n_SupDomain*RxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM + n_RxAntenna*TxANTENNA_NUM*PATH_NUM + n_Path*TxANTENNA_NUM + n_TxAntenna;
*(y+n_TxAntenna*SUBSLOTDATA_LENGTH+i) = add_cmx( *(y+n_TxAntenna*SUBSLOTDATA_LENGTH+i), mul_cmx( conj_cmx( *(h+Index_h) ), *(x+n_RxAntenna*(SUBSLOTDATA_LENGTH+PATH_NUM-1)+n_Path+i) ) );
}
}
}
}
}
return (n_TxAntenna*i);
}
int vec_self_cov(COMPLEX * h, int n_Len_h, COMPLEX * y, int Ns)
{
int i;
int n_Path;
int n_RxAntenna;
int n_TxAntenna;
int Lh = n_Len_h/RxANTENNA_NUM/Ns; //i.e. Path_number
int Ly = n_Len_h/RxANTENNA_NUM;
for(i=0; i<Ns*Ly; i++)
{
(y+i)->real = (y+i)->image = 0;
}
for(n_Path=0; n_Path<Lh; n_Path++)
{
for(n_TxAntenna=0; n_TxAntenna<Ns; n_TxAntenna++)
{
for(i=0; i<(Ly-n_Path*Ns); i++)
{
for(n_RxAntenna=0; n_RxAntenna<RxANTENNA_NUM; n_RxAntenna++)
{
*(y+n_TxAntenna*Ly+i) = add_cmx( *(y+n_TxAntenna*Ly+i), mul_cmx( conj_cmx( *(h+(n_RxAntenna*Lh+n_Path)*Ns+n_TxAntenna) ), *(h+(n_RxAntenna*Lh+n_Path)*Ns+i) ) );
}
}
}
}
return ((n_Path*Ns+i)*n_TxAntenna);
}
int SpaceTimeCombine(COMPLEX * p_rxSignal, int n_rxSignalLen, COMPLEX * p_RakeSignal, COMPLEX * p_h_half, double * Noise_variance, BASEBAND_PARM * p_Baseband_Parm)
{
int i;
int result;
int n_slot;
int n_subslot;
int n_RxAntenna;
int n_Block;
int OutLenPerRx = n_rxSignalLen/RxANTENNA_NUM;
//Pointer
COMPLEX * p_CurFirstCHEst;
COMPLEX * p_CurCHEstimate;
COMPLEX * p_CurRakeSignal;
COMPLEX * p_Cur_h_half;
//Memory
COMPLEX * p_FirstCHEst;
COMPLEX * p_Rhh;
double * p_PathGainEst;
COMPLEX * p_CombineMtx;
COMPLEX * p_CHEstimate;
COMPLEX * p_rxSignalPerSubslot;
//Allocate memory
p_FirstCHEst = (COMPLEX *)malloc(RxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM*(SUBSLOT_NUM+1)*(p_Baseband_Parm->FRAME_SLOTNUM)*sizeof(COMPLEX));
p_Rhh = (COMPLEX *)malloc((SUBSLOT_NUM+1)*(SUBSLOT_NUM+1)*sizeof(COMPLEX));
p_PathGainEst = (double *)malloc(PATH_NUM*sizeof(double));
p_CombineMtx = (COMPLEX *)malloc(PATH_NUM*(SUBSLOT_NUM+1)*(SUBSLOT_NUM+1)*sizeof(COMPLEX));
p_CHEstimate = (COMPLEX *)malloc(RxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM*(INTERP_FACTOR*SUBSLOT_NUM+1)*sizeof(COMPLEX));
p_rxSignalPerSubslot = (COMPLEX *)malloc(RxANTENNA_NUM*(SUBSLOTDATA_LENGTH+PATH_NUM-1)*sizeof(COMPLEX));
//First channel estimation
result = FirstCHEstimate(p_rxSignal, n_rxSignalLen, p_FirstCHEst, p_Rhh, p_PathGainEst, p_Baseband_Parm);
result = GetCombineMtx(p_Rhh, (SUBSLOT_NUM+1)*(SUBSLOT_NUM+1), p_PathGainEst, p_CombineMtx, Noise_variance);
//Second channel estimation and space-time combination
for(n_slot=0; n_slot<p_Baseband_Parm->FRAME_SLOTNUM; n_slot++)
{
p_CurFirstCHEst = p_FirstCHEst + n_slot*RxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM*(SUBSLOT_NUM+1);
result = SecondCHEstimate(p_CurFirstCHEst, RxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM*(SUBSLOT_NUM+1), p_CombineMtx, p_CHEstimate, INTERP_FACTOR);
for(n_subslot=0; n_subslot<SUBSLOT_NUM; n_subslot++)
{
p_CurCHEstimate = p_CHEstimate + n_subslot*INTERP_FACTOR*(TxANTENNA_NUM*RxANTENNA_NUM*PATH_NUM);
p_CurRakeSignal = p_RakeSignal + (n_slot*SUBSLOT_NUM+n_subslot)*(TxANTENNA_NUM*SUBSLOTDATA_LENGTH);
//Get the received signal for current subslot
for(n_RxAntenna=0; n_RxAntenna<RxANTENNA_NUM; n_RxAntenna++)
{
for(i=0; i<SUBSLOTDATA_LENGTH+PATH_NUM-1; i++)
{
(p_rxSignalPerSubslot+n_RxAntenna*(SUBSLOTDATA_LENGTH+PATH_NUM-1)+i)->real = (p_rxSignal+n_RxAntenna*OutLenPerRx+n_slot*SLOT_LENGTH+n_subslot*SUBSLOT_LENGTH+PILOT_LENGTH+GUARD_LENGTH+i)->real;
(p_rxSignalPerSubslot+n_RxAntenna*(SUBSLOTDATA_LENGTH+PATH_NUM-1)+i)->image = (p_rxSignal+n_RxAntenna*OutLenPerRx+n_slot*SLOT_LENGTH+n_subslot*SUBSLOT_LENGTH+PILOT_LENGTH+GUARD_LENGTH+i)->image;
}
}
result = vec_cyc_cov(p_rxSignalPerSubslot, RxANTENNA_NUM*(SUBSLOTDATA_LENGTH+PATH_NUM-1), p_CurCHEstimate, (INTERP_FACTOR+1)*(TxANTENNA_NUM*RxANTENNA_NUM*PATH_NUM), p_CurRakeSignal);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -