📄 jkch.c
字号:
/***********************************************************************************/
/* IS54 Baseband Simulation Software */
/* */
/* File Description : Jakes' Fader */
/* File Name : jkch.c */
/* Date : 1/4/94 */
/* : July, 20001 - Modified for TMS320C55x project */
/* */
/* This is a subroutine implementation of a Jakes' fader. The method and */
/* design equations are found on p. 70 of Microwave Mobile Communications */
/* by William C. Jakes, Wiley 1974. Essentially the code is as straight- */
/* forward as I could make it, but I put in some flexibility as far as */
/* sample rate and the number of points generated. (This subroutine takes */
/* the oversampling rate into account by assuming that each symbol is */
/* 41.17 uS long). */
/* */
/* Inputs to this routine consist of vehicle speed, carrier frequency, */
/* number of I,Q input pairs to be corrupted, oversampling rate, and pointers */
/* to arrays of input I,Q vector pairs. */
/* */
/* This routine will produce fading vectors corresponding to the suppied */
/* inputs, and these vectors will be used to corrupt the I,Q input data */
/* in place. (i.e. the input I,Q arrays will be OVERWRITTEN with corrupted */
/* data). */
/* */
/* NOTE : THIS MODEL FAILS WHEN VEHICLE SPEED IS ZERO. */
/* */
/* INPUTS */
/* mph : Simulated vehicle speed in miles per hour */
/* fc : Simulated carrier frequency in MHz */
/* num_terms : The number of I,Q pairs to corrupt with multipath fading */
/* ovsamp : Oversampling rate: the number of samples per symbol */
/* I : Input (uncorrupted) I (in-phase) sample */
/* Q : Input (uncorrupted) Q (quadrature) sample */
/* */
/* OUTPUTS */
/* I : Output I (in-phase) sample corrupted with vector of cosine */
/* (in-phase) fading data */
/* Q : Output Q (quadrature) sample corrupted with vector of sine */
/* (quadrature) fading data */
/* */
/***********************************************************************************/
/* Includes */
#include <intrindefs.h>
/* Defines */
#define N0 8
#define N 34
#define USER_PI ((float)3.1415926)
/* Function Prototypes */
void jkch( int, int*, int*, float);
float jkch_init( float, float, int);
extern int cosine(int);
extern int rand_num(void);
/* External Function Prototypes */
/* Data */
int jkch_fn1[N0+1],jkch_fn2[N0+1];
float cosval[N0+1]={1.000000,0.982973,0.932472,0.850217,
0.739009,0.602635,0.445738,0.273663,0.092268};
#if 0
// Orginal array
float jkch_gs[N0+1]={1.000000,1.847759,1.414214,0.765367,
0.000000,-0.765367,-1.414213,-1.847759,-2.000000},
jkch_gc[N0+1]={1.000000,0.765367,1.414214,1.847759,
2.000000,1.847759,1.414214,0.765367,0.000000};
// Normalized array using: norm=0.3430, /* norm=1/sqrt(8.5) */
float jkch_gs[N0+1]={0.343000,0.633781,0.485075,0.262521,
0.000000,-0.262521,-0.485075,-0.633781,-0.686000},
jkch_gc[N0+1]={0.343000,0.262521,0.485075,0.633781,
0.686000,0.633781,0.485075,0.262521,0.000000};
#endif
// Q15 format array
int jkch_gsi[N0+1]={0x2BE7,0x511F,0x3E16,0x219A,0x0000,-0x219A,-0x3E16,-0x511F,-0x57CE},
jkch_gci[N0+1]={0x2BE7,0x219A,0x3E16,0x511F,0x57CE,0x511F,0x3E16,0x219A,0x0000};
/* External Data */
/* Code */
float jkch_init(float mph, float fc, int ovsamp)
{
float fm, cap_t, temp1, temp2;
int i;
fm = ((float)0.001490515247)*mph*fc;
for (i = 0 ; i <= N0 ; i++)
{
temp1 = (int)(fm*cosval[i]); // Integer
temp2 = fm*cosval[i];
temp2 -= temp1; // fraction
// Note:, the following arrys are in different format:
// jkch_fn1[i] is an integer array in deciaml format
// jkch_fn2[i] is a fractional array in Q15 format
jkch_fn1[i] = (int)temp1;
jkch_fn2[i] = (int)(temp2*32767.0);
}
cap_t = (float)1.0 / ((float)ovsamp * (float)24300.0);
return(cap_t);
}
#define SCALE 2 /* (divide by 4) */
void jkch(int num_terms, int *I, int *Q, float cap_t)
{
float t;
int i,j,xc,xs,angle,itemp,itemp2;
long lxc,lxs,ltemp,ltemp2;
t = (float)rand_num()/32767.0;
for (i = 0 ; i < num_terms ; i++)
{
t += cap_t;
lxc = 0;
lxs = 0;
itemp2 = (int)(t*32767.0);
for (j = 0 ; j <= N0 ; j++)
{
ltemp = _lsmpy(itemp2, jkch_fn1[j]); /* ltemp = jkch_fn1[j]*t; */
ltemp2 = _lsmpy(itemp2, jkch_fn2[j]); /* ltemp2 = jkch_fn2[j]*t; */
ltemp2 = _lsadd(ltemp, (ltemp2>>16)); /* ltemp = ltemp - (int)ltemp; */
angle = ((unsigned int)(ltemp2)>>1); /* angle = ltemp */
itemp = (cosine(angle)>>SCALE); /* itemp = cos(angle)*SCALE */
lxc = _smac(lxc, itemp, jkch_gci[j]); /* xc += itemp * jkch_gc[j]; */
lxs = _smac(lxs, itemp, jkch_gsi[j]); /* xs += itemp * jkch_gs[j]; */
}
xc = (lxc>>16);
xs = (lxs>>16);
ltemp = _lsmpy(*I, xc );
ltemp = _smas(ltemp, *Q, xs );
ltemp2 = _lsmpy(*Q, xc );
ltemp2 = _smac(ltemp2, *I, xs ); /* temp =((*I) * xc)-((*Q)*xs); */
*(I++) = ltemp>>16; /* *(Q++)=((*Q) * xc)+((*I)*xs); */
*(Q++) = ltemp2>>16; /* *(I++)=temp; */
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -