📄 sim.c
字号:
tx_src(out_I,out_Q,182,tx_filt,I_SRC,Q_SRC);/* produce 4X oversampled filtered tx vectors */
jkch(724,I_SRC,Q_SRC, cap_t); /* introduce multipath fading */
/* Note : This model does not work well */
/* when v_speed = 0.0 */
noise(724,I_SRC,Q_SRC,Sc_fact); /* introduce noise */
j = sync_corr(I_SRC,Q_SRC,filt4); /* Obtain sync point in resultant data */
rx_src(I_SRC,Q_SRC,j,filt4,out_I,out_Q); /* Filter receive data */
diff(out_I,out_Q,rx_slot); /* Differentially detect receive symbols */
get_slot_data( rx_slot, rx_idata ); /* Extract receive slot data */
deinterleave( rx_idata, rx_data ); /* De-interleave receive slot data */
extract_slot_bits(cl2,cc0,cc1,rx_data); /* Obtain cl2[], cc0[] & cc1[] bits from rx data */
if (frame_num > 0)
{
vitdec(cc0,cc1,cl1); /* Viterbi decode -> obtain cl1[] from cc0 & cc1[] */
get_vselp(cl1,cl2,vselp); /* Produce VSELP from cl1[] and cl2[] */
crc_error_state = errorchk( crc_error_state, vselp ); /* Verify receive CRC */
vselpout(spoutput,vselp); /* dump receive VSELP parameters */
}
berr_count( tx_slot+32, rx_slot, crc_error_state, BERR_UPDATE );
frame++;
printf("Processed Frame %d\n", frame_num);
}
/******************************/
/* END OF MAIN LOOP */
/******************************/
berr_count( tx_slot+32, rx_slot, crc_error_state, BERR_REPORT );
}
/************************************************************************/
/* */
/* Function : berr_count() */
/* */
/* Procedure : This function keeps track of the bit errors between */
/* raw transmit and receive slots. It is passed pointers */
/* to two 324-bit arrays representing the transmitted and */
/* received slot bits in addition to a receive CRC error */
/* state and a command on what to do. */
/* */
/* Commands : */
/* BERR_INIT : Clear all static counters. */
/* */
/* BERR_UPDATE : If the receive CRC is valid, */
/* the parameter "slot_count" is */
/* incremented and the transmit and */
/* receive slots are compared while */
/* updating the individual slot field */
/* BERR counters. */
/* If the CRC is invalid, the slots are */
/* not compared, and the parameter */
/* "bad_slot_count" is incremented. */
/* */
/* BERR_REPORT : In this case the static BERR counters */
/* are used to calculate raw bit-error */
/* rate over each field, and the results */
/* are displayed to the screen. */
/* */
/* Static Data : */
/* (All of the following data is cleared when command = BERR_INIT) */
/* */
/* slot_count : Number of CRC valid slots */
/* */
/* bad_slot_count : Number of CRC invalid slots */
/* */
/* sync_errs : Number of bit errors over the SYNC field of */
/* all CRC-valid slots. */
/* */
/* sacch_errs : Number of bit errors over the SACCH field of */
/* all CRC-valid slots. */
/* */
/* data1_errs : Number of bit errors over the 1st DATA field of*/
/* all CRC-valid slots. */
/* */
/* cdvcc_errs : Number of bit errors over the CDVCC field of */
/* all CRC-valid slots. */
/* */
/* data2_errs : Number of bit errors over the 2nd DATA field of*/
/* all CRC-valid slots. */
/* */
/* rsvd_errs : Number of bit errors over the RSVD field of */
/* all CRC-valid slots. */
/* */
/* */
/* Inputs : */
/* tx_slot : Pointer to a 324-bit array containing the raw */
/* transmit slot bits for the current slot. */
/* (elements are assumed binary, i.e. 0 or 1 only) */
/* Note that this is only used when command = */
/* BERR_UPDATE and crc_error = 0. */
/* */
/* rx_slot : Pointer to a 324-bit array containing the raw */
/* receive slot bits for the current slot. */
/* (elements are assumed binary, i.e. 0 or 1 only) */
/* Note that this is only used when command = */
/* BERR_UPDATE and crc_error = 0. */
/* */
/* crc_error : CRC error state for current slot. (0 = no error) */
/* Note that this is only used when command = */
/* BERR_UPDATE. */
/* */
/* command : Command on what to do. Valid command are the */
/* following : */
/* BERR_INIT */
/* BERR_UPDATE */
/* BERR_REPORT */
/* */
/* Outputs : */
/* When command == BERR_REPORT, the bit-error results are */
/* printed to the console window. */
/* */
/* Return Value : */
/* NONE */
/* */
/************************************************************************/
void berr_count( unsigned *tx_slot, unsigned *rx_slot, int crc_error, int command )
{
static long slot_count, sync_errs, sacch_errs, data1_errs,
data2_errs, cdvcc_errs, rsvd_errs, bad_slot_count;
int i;
float berr;
/********************************/
/* Clear Static Counters */
/********************************/
if( command == BERR_INIT )
{
slot_count = 0;
bad_slot_count = 0;
sync_errs = 0;
sacch_errs = 0;
data1_errs = 0;
data2_errs = 0;
cdvcc_errs = 0;
rsvd_errs = 0;
}
/********************************/
/* Update BERR Counters */
/********************************/
else if( command == BERR_UPDATE )
{
if( crc_error == 0 )
{
slot_count++;
for( i = 0; i < 28; i++ ) if( *(tx_slot++) != *(rx_slot++) ) sync_errs++;
for( i = 0; i < 12; i++ ) if( *(tx_slot++) != *(rx_slot++) ) sacch_errs++;
for( i = 0; i < 130; i++ ) if( *(tx_slot++) != *(rx_slot++) ) data1_errs++;
for( i = 0; i < 12; i++ ) if( *(tx_slot++) != *(rx_slot++) ) cdvcc_errs++;
for( i = 0; i < 130; i++ ) if( *(tx_slot++) != *(rx_slot++) ) data2_errs++;
for( i = 0; i < 12; i++ ) if( *(tx_slot++) != *(rx_slot++) ) rsvd_errs++;
}
else
bad_slot_count++;
}
/********************************/
/* Display BERR Results */
/********************************/
else if( command == BERR_REPORT )
{
if( slot_count == 0 )
printf("\nNo CRC Error-Free Slots have been obtained\n");
else
{
printf("\nTotal Number of Slots : %ld", (slot_count + bad_slot_count));
printf("\n CRC Valid Slots : %ld", slot_count);
printf("\n CRC Invalid Slots : %ld", bad_slot_count);
printf("\n");
berr = (((float) sync_errs) / (28 * (float) slot_count));
printf("\nSync Field Errors = %4ld,\tBER = %e", sync_errs, berr);
berr = (((float) sacch_errs) / (12 * (float) slot_count));
printf("\nSACCH Field Errors = %4ld,\tBER = %e", sacch_errs, berr);
berr = (((float) data1_errs) / (130 * (float) slot_count));
printf("\nDATA1 Field Errors = %4ld,\tBER = %e", data1_errs, berr);
berr = (((float) cdvcc_errs) / (12 * (float) slot_count));
printf("\nCDVCC Field Errors = %4ld,\tBER = %e", cdvcc_errs, berr);
berr = (((float) data2_errs) / (130 * (float) slot_count));
printf("\nDATA2 Field Errors = %4ld,\tBER = %e", data2_errs, berr);
berr = (((float) rsvd_errs) / (12 * (float) slot_count));
printf("\nRSVD Field Errors = %4ld,\tBER = %e", rsvd_errs, berr);
berr = (((float)data1_errs +(float)data2_errs)/(260*(float)slot_count));
printf("\n\n\tRaw BER (Data Fields) = %e\n", berr);
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -