📄 hannelclass.cpp
字号:
{
printf("Memory allocation for pointer d failed--exiting\n");
return(-1);
}
cTemp = c;
dTemp = d;
TempYdata = Ydata;
for (i=0; i<N; i++)
{
if ( (dift = fabs(x - *TempXdata++)) < dif)
{
ns = i;
dif = dift;
}
*cTemp++ = *TempYdata;
*dTemp++ = *TempYdata++;
}
y = *(Ydata + ns--);
for (m=1; m<N; m++)
{
TempXdata = Xdata;
TempXdata1 = Xdata + m;
cTemp = c;
dTemp = d;
for (i=0; i<N-m; i++)
{
ho = *TempXdata++ - x;
hp = *TempXdata1++ - x;
w = *(cTemp+1) - *dTemp;
if ((den=hp-ho) == 0.0)
{
printf("Error in PolynoimalFit--exiting");
return(-1);
}
den = w / den;
*dTemp++ = hp * den;
*cTemp++ = ho * den;
}
y += (*error=(2*ns < (N - m) ? *(c + ns+1) : *(d + ns-- -1)));
}
free(d);
free(c);
return (y);
}
ComplexNumber * ChannelClass::Radix2FFT(ComplexNumber *data, unsigned NN, int isign)
/*****************************************************************************
* ComplexNumber Radix2FFT(ComplexNumber data, unsigned NN, int isign)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* Computes a radix 2 FFT of the input array "data." The length of the
* array must be a power of 2. The function can perform both the FFT
* and the IFFT
*
* Returns An array of length NN and of type ComplexNumber containing
* either the FFT or the IFFT of the input
*
* Parameters
* data ComplexNumber * Contains the input sequence.
* The length must be a power of 2
* NN unsigned Contains the length of the sequenc
* isign int If isign = -1, then the FFT is computed
* If isign = 1, then the IFFT is computed
*
* NOTE: Algorithm was found in Numerical Recipies in C
*
*****************************************************************************/
{
unsigned n,mmax,m,j,istep,i;
double wtemp,theta,fee,foo=2.00000;
ComplexNumber w,wp,temp;
ComplexNumber *TempDataPtr;
ComplexNumber *ResultPtr,*TempResultPtr;
//Check to make sure that NN is a power of 2
theta = (double) NN;
foo = log(foo);
fee = log( theta);
fee /= foo;
wtemp = modf(fee,&theta);
wtemp = modf(wtemp,&theta);
if (wtemp != 0)
{
printf("NN = %d, NN must be a power of 2--exiting\n",NN);
return(NULL);
}
ResultPtr = (ComplexNumber *) calloc(NN,sizeof(ComplexNumber));
if (ResultPtr == NULL)
{
printf("Memory allocation to result pointer failed\n");
return(ResultPtr);
}
TempDataPtr = data;
TempResultPtr = ResultPtr;
theta = 1 / (double) NN;
if (isign == 1)
{
for (i=0; i<NN; i++) *TempResultPtr++ = ComplexRealMultiply(theta,*TempDataPtr++ );
}
else
{
for (i=0; i<NN; i++) *TempResultPtr++ = *TempDataPtr++ ;
}
n = NN;
j=0;
TempResultPtr = ResultPtr;
for(i=0; i<n; i++)
{
if ( i > j )
{
SWAP( *(TempResultPtr + j), *(TempResultPtr + i) );
}
m = n >> 1;
while ( m >= 1 && j >= m) //modification to code--may not be correct
{
j -= m;
m >>= 1;
}
j += m;
}
mmax = 1;
while (n > mmax)
{
istep = 2*mmax;
theta = 6.28318530717959 / (isign * 2.0 * mmax);
wtemp = sin(0.5*theta);
wp.real= -2.0*wtemp*wtemp;
wp.imaginary = sin(theta);
w.real = 1.0;
w.imaginary = 0.0;
for (m=0; m<mmax; m++)
{
for(i=m; i<n; i+=istep)
{
j = i+mmax;
temp.real = w.real * (ResultPtr+j)->real - w.imaginary * (ResultPtr + j)->imaginary;
temp.imaginary = w.real * (ResultPtr+j)->imaginary + w.imaginary * (ResultPtr +j)->real;
*(ResultPtr+j) = ComplexSubtract( *(ResultPtr+i), temp);
*(ResultPtr + i) = ComplexAdd( *(ResultPtr + i),temp);
}
w.real = (wtemp=w.real)*wp.real - w.imaginary*wp.imaginary + w.real;
w.imaginary = w.imaginary * wp.real + wtemp*wp.imaginary + w.imaginary;
}
mmax = istep;
}
return(ResultPtr);
}
void ChannelClass::FadingProcessor()
/*********************************************************************************************
// Copyright 2002 The Mobile and Portable Radio Research Group
//
//Selects the fading signal. The fading signal for each multipath component
//is identified by a pointer that is stored in an array of pointers. Each fading
//signal covers a large number of frames (over 100), and 96 fading samples corresponds
//to one 10ms fade duration. Each time this function is called 3*96 fade sampels
//are needed: one group of 96 for the preveious frame, one group of 96 for the
//current frame, and one group of 96 for the next frame. Once the channel is
//processed, the previous frame (and the fading associated with that frame) is
//no longer needed.
*********************************************************************************************/
{
unsigned k,j; //Loop coutners
ComplexNumber *TempFadePtr; //Temporary pointer to the fading signal
double *AmplitudePtr; //Temporary pointer to the membor array that contains
//the fading amplitudes
if (FadeInitFlag) //If this is the first time that the function is called
{ //Then a new fading signal was constrcuted in the constructor
FadingSignalOffset = 0; //So just set the offset to 0 and return
FadeInitFlag = false;
return;
}
FadingSignalOffset += FadeSamplesPerFrame;
if ( (FADE_SIGNAL_LENGTH - FadingSignalOffset) < (3*FadeSamplesPerFrame) )
{
// Free current fading signals
for (k=0; k<MultiPathComponents; k++) free( *(FadingSignals + k) );
// Generate new fading signals
AmplitudePtr = Amplitudes;
for (k=0; k<MultiPathComponents; k++)
{
*(FadingSignals + k) = RaylieghFadingGenerator(fDoppler,FADE_SAMPLE_RATE,FADE_SIGNAL_LENGTH);
TempFadePtr = *(FadingSignals + k);
for (j=0; j<FADE_SIGNAL_LENGTH; j++) *TempFadePtr++ = ComplexRealMultiply(*AmplitudePtr,*TempFadePtr);
AmplitudePtr++;
}
FadingSignalOffset = 0;
}
}
void ChannelClass::MpathProcessor(ComplexNumber *PrevSignal,
ComplexNumber *CurSignal,
ComplexNumber *NextSignal,
unsigned SignalLength)
/**************************************************************************************
*void ChannelClass::ChannelProcessor(ComplexNumber *PrevSignal,
* ComplexNumber *CurSignal,
* ComplexNumber *NextSignal
* unsigned SignalLength)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* This function performs the following three actions
* 1. It selects the fading signal
* 2. It generates the multipath response
* 3. It stores the pointer to the resultant array in
* the object memeber variable. MultipathSignal
*
*
* Parameters
* PrevSignal ComplexNumber * Pointer to an array that stores the signal
* from the previous frame
* CurSignal ComplexNumber * Pointer to an array that stores the signal
* from the current frame
* NextSignal ComplexNumber * Pointer to an array that stores the signal
* from the next frame
* SignalLength unsigned * Length of each of the above signals
**************************************************************************************/
{
//Select the fading signal. This is accomplished by calling the Fading Processor
FadingProcessor();
//Generate the multipath response
MultipathSignal = MultiPathChannel(PrevSignal, CurSignal, NextSignal, SignalLength);
return;
}
void ChannelClass::Combiner(ComplexNumber *OtherSignal)
/**************************************************************************************
*void ChannelClass::Combiner(ComplexNumber *OtherSignal)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* This function takes the array, identified by the pointer OtherSignal, and adds it to
* the array identified by the object member pointer MultipathSignal. This is used to combine
* multipath signals
*
* Returns Nothing
*
* Parameter
* OtherSignal ComplexNumber * Pointer to array that contains the multipath
* signal. This is probably the multipath
* response from the channel associated with the
* other antenna (when STTD is employed)
**************************************************************************************/
{
ComplexNumber *TempOtherSignal,*TempMultipathSignal; //Temporary pointers
unsigned k; //Loop counters
TempOtherSignal = OtherSignal;
TempMultipathSignal = MultipathSignal;
for (k=0; k<MultipathSignalLength; k++)
*TempMultipathSignal++ = ComplexAdd(*TempMultipathSignal,*TempOtherSignal++);
return;
}
void ChannelClass::NoiseGenerator()
/**************************************************************************************
*void ChannelClass::NoiseGenerator()
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* This function generates a noise signal and adds it to the signal identified by the
* object member pointer MultipathSignal
*
* Returns Nothing
*
* Parameter None
**************************************************************************************/
{
ComplexNumber *TempMultipathSignal; //Temporary pointer to the multipath
ComplexNumber Noise; //Random Noise sample
unsigned k;
int InitFlag = 1;
// FILE *fp1,*fp2;
// fp1=fopen("Signal.txt","w");
// fp2=fopen("Noise.txt","w");
// TempMultipathSignal = MultipathSignal;
// for (k=0; k<MultipathSignalLength; k++)
// {
// fprintf(fp1,"%g %g\n",TempMultipathSignal->real,TempMultipathSignal->imaginary);
// TempMultipathSignal++;
// }
TempMultipathSignal = MultipathSignal;
for (k=0; k<MultipathSignalLength; k++)
{
Noise = ComplexRealMultiply(NoiseSTDV,GaussianRandomNumberGenerator(&InitFlag));
// fprintf(fp2,"%g %g\n",Noise.real,Noise.imaginary);
// *TempMultipathSignal++ = Noise;
*TempMultipathSignal++ = ComplexAdd(*TempMultipathSignal,Noise);
}
// fclose(fp1);
// fclose(fp2);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -