📄 sim.c
字号:
/***********************************************************************************/
/* IS54 Baseband Simulation Software */
/* */
/* File Description : IS54 Baseband Simulation Executive Module */
/* File Name : sim.c */
/* Date : 1/4/94 */
/* : July, 20001 - Modified for TMS320C55x project */
/* */
/* This module contains the executive routine and various utility */
/* routines to execute the IS54 baseband simulation. */
/* */
/* Functions: */
/* main() : IS54 Baseband Simulation Executive */
/* */
/* memory() : Utility routine used to allocate/deallocate */
/* buffer memory for main(). */
/* */
/* file_open() : Utility routine to open files an display */
/* error messages in case an error occurs. */
/* */
/* dump_bits() : Utility routine which dumps bit data to a file. */
/* */
/* berr_count() : Utility routine which keeps track of the bit errors */
/* between raw transmit and receive frames during the */
/* simulation. */
/* */
/***********************************************************************************/
/* Include Files */
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include "vselp.h"
/* Defines */
#define YES 1
#define NO 0
#define BERR_INIT 0
#define BERR_UPDATE 1
#define BERR_REPORT 2
/* Function Prototypes */
void main( void );
void berr_count( unsigned*, unsigned*, int, int );
/* External Function Prototypes */
extern void vselpin( unsigned int*, unsigned* ); /* Defined in vselp_io.c */
extern void vselpout( unsigned int*, unsigned* ); /* Defined in vselp_io.c */
extern void crcgen( unsigned* ); /* Defined in crcgen.c */
extern void convenc( unsigned*, unsigned*, unsigned* ); /* Defined in convenc.c */
extern void diffenc( unsigned*, int*, int* ); /* Defined in diffenc.c */
extern void noise( int, int*, int*, int ); /* Defined in noise.c */
extern int noise_init( float ); /* Defined in noise.c */
extern void jkch( int, int*, int*, float); /* Defined in jkch.c */
extern float jkch_init( float, float, int); /* Defined in jkch.c */
extern void diff( int*, int*, unsigned* ); /* Defined in diff.c */
extern int errorchk( int, unsigned* ); /* Defined in errorchk.c */
extern void get_cl1_cl2( unsigned*, unsigned*, unsigned* ); /* Defined in slotbits.c */
extern void get_vselp( unsigned*, unsigned*, unsigned* ); /* Defined in slotbits.c */
extern void extract_slot_bits( unsigned*, unsigned*, unsigned*, unsigned* ); /* Defined in slotbits.c */
extern void build_slot_data( unsigned*, unsigned*, unsigned*, unsigned* ); /* Defined in slotbits.c */
extern void build_slot( unsigned*, unsigned* ); /* Defined in slotbits.c */
extern void get_slot_data( unsigned*, unsigned* ); /* Defined in slotbits.c */
extern void interleave_init( void ); /* Defined in interlev.c */
extern void interleave( unsigned*, unsigned* ); /* Defined in interlev.c */
extern void deinterleave( unsigned*, unsigned* ); /* Defined in interlev.c */
extern void rx_src( int*, int*, int, int*, int*, int* ); /* Defined in rx_src.c */
extern int sync_corr( int*, int*, int* ); /* Defined in sync_cor.c */
extern void tx_src( int*, int*, int, int*, int*, int* ); /* Defined in tx_src.c */
extern void vitdec( unsigned*, unsigned*, unsigned* ); /* Defined in vitham.c */
/* Data */
#define DATALEN 401
#include "speech.dat"
unsigned int spoutput[DATALEN];
int filt4[48]={ /* Receiver filter coefficient table in Q15 format */
-0x30,-0x25,0x16,0x4b,0x3d,-0x13,-0x5f,-0x54, /* -0.001461,-0.001122,0.000679,0.002294,0.001873,-0.000586,-0.002901,-0.002562, */
0x11,0x6d,0x4e,-0x4e,-0xd0,-0x79,0xd2,0x217, /* 0.000504,0.003323,0.002387,-0.002387,-0.006358,-0.003694,0.006399,0.016327, */
0x1d4,-0xb5,-0x453,-0x609,-0x2b5,0x69e,0x1372,0x1ea0, /* 0.014270,-0.005515,-0.033786,-0.047150,-0.021163,0.051708,0.151934,0.239280, */
0x2304,0x1ea0,0x1372,0x69e,-0x2b5,-0x609,-0x453,-0xb5,/* 0.273560,0.239280,0.151934,0.051708,-0.021163,-0.047150,-0.033786,-0.005515, */
0x1d4,0x217,0xd2,-0x79,-0xd0,-0x4e,0x4e,0x6d, /* 0.014270,0.016327,0.006399,-0.003694,-0.006358,-0.002387,0.002387,0.003323, */
0x11,-0x54,-0x5f,-0x13,0x3d,0x4b,0x16,-0x25}; /* 0.000504,-0.002562,-0.002901,-0.000586,0.001873,0.002294,0.000679,-0.001122}; */
int tx_filt[48]={ /* Transmit filter coefficient table in Q15 format thai is normalized to the max floating-point number 1.094239 */
0x113,-0x133,-0x11e,0x7a4,-0x1610,0x6ff5,0x1832,-0x295, /* 0.009177,-0.010247,-0.009547,0.065309,-0.188601,0.957119,0.206831,-0.022058, */
-0x1ba,0x18e,-0.002346,-0x46,0x51,-0x15c,0x11e,0x2ff, /* -0.014774,0.013292,-0.002346,-0.004486,0.002716,-0.011605,0.009547,0.025597, */
-0xfcf,0x4717,0x4717,-0xfcf,0x2ff,0x11e,-0x15c,0x51, /* -0.135144,0.607737,0.607737,-0.135144,0.025597,0.009547,-0.011605,0.002716, */
-0x86,-0x46,0x18e,-0x1ba,-0x295,0x1832,0x6ff5,-0x1610, /* -0.004486,-0.002346,0.013292,-0.014774,-0.022058,0.206831,0.957119,-0.188601, */
0x7a4,-0x11e,-0x133,0x113,-0xaf,0xe0,0x3c,-0x2fa, /* 0.065309,-0.009547,-0.010247,0.009177,-0.005844,0.007490,0.002016,-0.025432, */
0x6ad,-0x9e7,0x7fff,-0x9e6,0x6ad,-0x2fa,0x3c,0xe0}; /* 0.057078,-0.084650,1.094239,-0.084650,0.057078,-0.025432,0.002016,0.007490}; */
/* Simulation condition parameters */
float SNR = 50.0, /* Signal-to-noise ratio (dB) */
v_speed = 60.0, /* Vehicle speed (mps) */
Fc=850.0; /* Carrier frequency (MHz) */
/* External Data */
/* Code */
/************************************************************************/
/* Function : main() */
/* */
/* Procedure : */
/* This is the IS54 Baseband simulation executive module. */
/* Operation is as follows: */
/* */
/* [INITIALIZATION] */
/* Allocate Memory for data buffers */
/* */
/* Open file "src_filt.dat" and read in 48 SRC */
/* filter coefficients. Store these filter */
/* coefficients into "filt" array and store */
/* permutations of these coefficients into */
/* "filt4" and "tx_filt" arrays. */
/* */
/* Pack end of "tx_slot" with sync word for slot #2. */
/* Note that this will never be overwritten. */
/* */
/* Clear BERR counters. */
/* */
/* [MAIN LOOP - Execute once per slot] */
/* */
/* Read in VSELP data from speech file, store */
/* in vselp[] parameter array. */
/* */
/* If more data exists in speech file : */
/* { */
/* Generate and store new CRC value from */
/* VSELP parameters. */
/* Obtain cl1[] and cl2[] bits from VSELP */
/* parameters. (Dump these bits to */
/* "cltxbits.out") */
/* Convolutionally encode the cl1[] bits into */
/* cc0[] and cc1[] bits. */
/* } */
/* Else */
/* { */
/* Set flag to exit at end of loop. */
/* } */
/* */
/* Build 260-bit slot data into "tx_data" from */
/* cc0[], cc1[] and cl2[] bits. */
/* */
/* Interleave bits from current frame (tx_data) */
/* with those from previous frame and store */
/* interleaved 260-bit slot data in "tx_idata". */
/* */
/* Build a 384-bit transmit slot from "tx_idata" and */
/* the sync word for slot #1, and store into */
/* buffer "tx_slot". Note that 60 "extra" bits */
/* are added to this transmit slot. The 1st */
/* 32 bits are zeroes, the next 324 bits */
/* the actual transmit slot, and the last 28 bits */
/* contains the sync word for slot #2. (Dump the */
/* 324 bits for the actual slot to "rawtxbits.out")*/
/* */
/* Differentially encode the 384 transmit slot bits */
/* into 192 DQPSK modulation I,Q vector pairs. */
/* (store them into out_I[] and out_Q[]). */
/* */
/* Generate SRC filtered I,Q data streams at 4X */
/* sample rate from out_I[], out_Q[] and store */
/* into I_SRC[],Q_SRC[]. Note that since the SRC */
/* filters consist of 4 banks of 12 taps and that */
/* 192 I,Q sample pairs were present at input, */
/* 728 output interpolated sample pairs are stored */
/* at I_SRC[] and Q_SRC[]. */
/* */
/* Corrupt the first 724 samples of I_SRC[] and Q_SRC[]*/
/* with multipath fading using Jakes' algorithm. */
/* Take vehicle speed (v_speed), carrier freq (Fc) */
/* and oversampling rate (4) into account. */
/* */
/* Corrupt the first 724 samples of I_SRC[] and Q_SRC[]*/
/* with Gaussian distributed random noise */
/* corresponding to current signal-to-noise ratio */
/* ration (SNR). */
/* */
/* Perform a complex-cartesian correlation between */
/* filtered versions of I_SRC[], Q_SRC[] (we want */
/* raised-cosine vesions) and the phase */
/* representation of the sync word for slot #1. */
/* Search for a correlation peak in the data */
/* between sample #8 and sample #16 (4 symbols). */
/* */
/* Take the DQPSK encoded square-root raised cosine */
/* samples at 4X symbol rate (I_SRC[],Q_SRC[]), */
/* the synchonization point determined above, and */
/* the receive SRC filter, and produce raised */
/* cosine (RC) I,Q data streams at 1X symbol rate */
/* and store resultant 193 vectors into out_I[] */
/* and out_Q[] buffers. */
/* */
/* Differentially decode the resultant modulation */
/* vectors into out_I[] and out_Q[] into 324 slot */
/* bits (162 symbols) and store result into */
/* rx_slot[]. (Dump these 324 bits to the file */
/* "rawrxbits.out") */
/* */
/* Extract the 260-bit interleaved slot data from */
/* "rx_slot" and store into "rx_idata". */
/* */
/* De-Interleave the receive slot data in "rx_idata" */
/* into "rx_data" (also 260 bits). */
/* */
/* Extract the cc0[], cc1[] and cl2[] bits from */
/* "rx_data". */
/* */
/* If ( this is not the first frame ) */
/* { */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -