📄 eid.c
字号:
FEReid = open_eid(fer,gamma); /* Open EID for frame erasure */ if (FEReid==(SCD_EID *)0) HARAKIRI(" Could not create EID for frame erasure module!?",1); /* -------------------------------------------------------------------------- *//* Allocate memory for I/O-buffer *//* -------------------------------------------------------------------------- */ printf("_found frame length on input file: ......... %d\n",lseg); /* -------------------------------------------------------------------------- *//* a) buffer for data from input file: */ xbuff = (short *)malloc((1+lseg)*sizeof(short)); if (xbuff==(short *)0) HARAKIRI(" Could not allocate memory for input bit stream buffer",1); /* -------------------------------------------------------------------------- *//* b) buffer for output bit stream: */ ybuff = (short *)malloc((1+lseg)*sizeof(short)); if (ybuff==(short *)0) HARAKIRI(" Could not allocate memory for output bit stream buffer",1); /* -------------------------------------------------------------------------- *//* Now process input file *//* -------------------------------------------------------------------------- *//* initialize counters fro computing bit error rate/frame erasure rate */ ersfrms = 0.0; /* number of erased frames */ prcfrms = 0.0; /* number of processed frames */ /* ---------------------------------------------------------------------- */ /* Read file with input bit stream (segments of lenght "lseg+1") */ /* ---------------------------------------------------------------------- */ EOF_detected=0; /* Flag, to mark END OF FILE */ t1 = clock(); /* measure CPU-time */ while( (lread=fread(xbuff,2,lseg+1,ifilptr)) == lseg+1) { if (xbuff[0]==SYNCword && EOF_detected==0) { /* ------------------------------------------------------------------ */ /* Frame erasure */ /* ------------------------------------------------------------------ */ fer1 = FER_module(FEReid,lseg+1,xbuff,ybuff); ersfrms += fer1; /* count number of erased frames */ prcfrms += (double)1; /* count number of processed frames */ /* ------------------------------------------------------------------ */ /* Write (erased) frames to file */ /* ------------------------------------------------------------------ */ lread=fwrite(ybuff[0],2,lseg+1,ofilptr); } else /* if the next SYNC-word is missed */ { EOF_detected=1; } } if (EOF_detected==1) printf(" --- end of file detected (no SYNCword match) ---\n"); printf("\n"); t2 = clock(); t = (t2 - t1) / (double) CLOCKS_PER_SEC; printf("CPU-time %f sec\r\n\n",t); /* -------------------------------------------------------------------------- *//* Print message with measured bit error rate *//* -------------------------------------------------------------------------- */ if (prcfrms>0) { printf("measured frame erasure rate: %f (%ld of %ld frames erased)\n", ersfrms/prcfrms,(long)ersfrms,(long)prcfrms); } exit(0);}#endif/* *********************** END OF EXAMPLES ON USAGE *********************** */ #ifdef PORT_TEST int PORTABILITY_TEST_OPERATION = 1;#endif /* ......... Include of general definitions .........*/ #include <time.h>#include <math.h>#include <stdlib.h>#include <ctype.h>#include <stdio.h>/* ......... Include of EID prototypes and definitions .........*/ #include "eid.h"/* Local function prototypes and definitions .........*/ double EID_random ARGS((unsigned long *seed));void update_EID_random ARGS((long len_register, long *shift_register));long GEC_init ARGS((SCD_EID *EID, double ber, double gamma));/* ......... Global variable: Bellcore Model ......... */CONST double prob[MODEL_NUMBER][MODEL_SIZE] = { /* 1% */ { 0.0023, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.6, 0.45, 0.0},/* 3% */ { 0.0070, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.6, 0.45, 0.0},/* 5% */ { 0.0119, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.6, 0.45, 0.0},/* 10% */ { 0.0258, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.6, 0.45, 0.0},/* 15% */ { 0.0380, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.6, 0.45, 0.0}}; /* * ...................... BEGIN OF FUNCTIONS ......................... */ /* ============================================================================ SCD_EID *open_eid (double ber, double gamma); ~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Allocate memory for EID struct and setup the transission matrix according the select bit error rate. Parameters: ~~~~~~~~~~~ ber: ..... (In) bit error rate gamma: ... (In) burst factor Return value: ~~~~~~~~~~~~~ Returns a pointer to struct SCD_EID; Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/SCD_EID *open_eid (ber, gamma)double ber,gamma;{ SCD_EID *EID; time_t t1; /* Allocate EID structure */ if ((EID=(SCD_EID *)malloc(sizeof(SCD_EID)))==0L) return((SCD_EID *)0); /* Preset of the random generator seed with current system time */#ifdef PORT_TEST t1 = 314159265;#else time(&t1);#endif EID->seed = (unsigned long) t1; /* Initialize Gilbert-Elliot Channel model */ if (GEC_init(EID,ber,gamma)==0L) return((SCD_EID *)0); /* Store ber/gamma in struct */ EID->usrber = ber; /* user defined bit error rate */ EID->usrgamma = gamma; /* user defined correlation factor */ /* Return initialized structure */ return(EID);} /* ....................... End of open_eid() ....................... */ /* ============================================================================ void close_eid (SCD_EID *EID); ~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Release the memory previously allocated by open_eid() for an EID struct. Parameters: ~~~~~~~~~~~ eid: ..... (InOut) pointer to struct SCD_EID Return value: ~~~~~~~~~~~~~ None. Author: <tdsimao@venus.cpqd.ansp.br> ~~~~~~~ History: ~~~~~~~~ 23.Apr.92 v1.0 Release of 1st version <tdsimao@venus.cpqd.ansp.br> ============================================================================*/void close_eid (EID) SCD_EID *EID;{ long i; /* Free state transition matrix columns */ for (i=0; i<EID->nstates; i++) free((char *)EID->matrix[i]); /* Free state transition matrix rows */ free((char *)EID->matrix); /* Free memory of bit error array */ free((char *)EID->ber); /* Free EID structure */ free((char *)EID);} /* ....................... End of close_eid() ....................... */ /* ============================================================================ double BER_generator (SCD_EID *EID, long lseg, short *EPbuff); ~~~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Generates bit error pattern according to the selected channel model. Parameters: ~~~~~~~~~~~ EID: ...... (In/Out) struct with channel model lseg: ..... (In) length of current frame EPbuff: ... (Out) bit error pattern (softbits) Return value: ~~~~~~~~~~~~~ Returns the bit error rate in the current frame as a double. Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> ============================================================================*/double BER_generator (EID, lseg,EPbuff)SCD_EID *EID;long lseg;short *EPbuff;{ long i,n; /* value of random generator */ double RAN, ber; /* aux. for computing bit error rate */ /* Return if no samples are to be processed */ if (lseg==(long)0) return(0.0); /* Generate random bits */ ber = 0.0; for (i=0; i<lseg; i++) { /* Get next random number */ RAN = EID_random(&(EID->seed)); /* ... check the new channel state */ for (n=0; n<EID->nstates; n++) { if (RAN < EID->matrix[EID->current_state][n]) { EID->current_state = n; /* goto to the selected state */ n = EID->nstates; /* -> aborts loop */ } } /* * ......... COMPUTE BIT ERROR IN CURRENT STATE ......... */ /* Get next random number */ RAN = EID_random(&(EID->seed)); /* If random number is below the threshold (bit error rate in current state), insert soft decision information for 'error' */ if (RAN < EID->ber[EID->current_state]) { EPbuff[i] = (short)0x0081; ber += 1.0; /* increment number of errors */ } /* otherwise insert soft decision information for 'no error' */ else { EPbuff[i] = (short)0x007F; } } return(ber); /* return number of error bits */} /* ....................... End of BER_generator() ....................... */ /* ============================================================================ void BER_insertion_stl92 (long lseg, short *xbuff, short *ybuff, ~~~~~~~~~~~~~~~~~~~~~~~~ short *error_pattern); Description: ~~~~~~~~~~~~ Disturbing an input bitstream according stored error patterns. --------------------------------------------------------------- NOTES on Data Representation: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Each individual bit is stored in one location of a short-array, where in location 0 the SYNC-word is stored (SYNC-word = 0x6B21, 0x6B22, ... 0x6B2F). To allow the processing of 'soft-bits' (see separate ITU-T-paper) in future applications, the following definitions have been made: a) input signal: 'hard' bit '0' must be represented as 0x007F 'hard' bit '1' must be represented as 0x0081 b) error pattern: * probability for undisturbed transmission: 0x0001 ... 0x007F (0x0001: lowest probability that the or 1 ... 127 dec. transmission has been indeed undisturbed) * probability for disturbed transmission: 0x00FF ... 0x0081 (0x00FF: lowest probability that the or 255 ... 129 dec. transmission has been really disturbed) c) output signal computation: For input '1' (0x0081): * if error pattern 0x00FF ... 0x0081 (255 ... 129), then output = 0x0001 ... 0x007F ( 1 ... 127); * if error pattern 0x0001 ... 0x007F ( 1 ... 127), then output = 0x00FF ... 0x0081 (255 ... 129). For input '0' (0x007F): * if error pattern 0x00FF ... 0x0081 (255 ... 129), then output = 0x00FF ... 0x0081 (255 ... 129); * if error pattern 0x0001 ... 0x007F ( 1 ... 127), then output = 0x0001 ... 0x007F ( 1 ... 127). --------------------------------------------------------------- Parameters: ~~~~~~~~~~~ lseg: ..... length of current frame (with SYNC-word) xbuff: .... buffer with input bitstream (length = "lseg") ybuff: .... buffer with output bitstream (length = "lseg") EPbuff: ... buffer with error pattern (without SYNC-word) (length = "lseg-1") Return value: ~~~~~~~~~~~~~ None. Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 28.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> 06.Jun.95 v1.1 Changed self-documentation to align the EID module
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -