📄 transmitterclass.cpp
字号:
TempFrameBufferPtr=FrameBufferPtr;
if(STTDflag) SymbolsPerFrame = SymbolsPerFrame << 1; //Multiply by 2 to account for the second antenna
//Spread the Data Bits
for (k=0; k<SymbolsPerFrame; k++)
{
TempChanCodePtr=ChanCode;
for (j=0; j<format.SF; j++)
*TempChipSequencePtr++ = ComplexRealMultiply( *TempChanCodePtr++, *TempFrameBufferPtr);
TempFrameBufferPtr++;
}
//We no longer need the array that stores the symbols
free(FrameBufferPtr);
//Now Scramble the Data
TempChipSequencePtr=ChipSequencePtr;
TempScrambleCodePtr = ScrambleCode;
for (k=0; k<CHIPS_PER_FRAME; k++)
*TempChipSequencePtr++ = ComplexMultiply(*TempChipSequencePtr,*TempScrambleCodePtr++);
//if STTD is employed scramble the data associated with antenna2
if (STTDflag)
{
TempScrambleCodePtr = ScrambleCode;
for (k=0; k<CHIPS_PER_FRAME; k++)
*TempChipSequencePtr++ = ComplexMultiply(*TempChipSequencePtr,*TempScrambleCodePtr++);
}
//*******************************************************
//Debug Code
// fp=fopen("ChipSequence.txt","w");
// TempChipSequencePtr=ChipSequencePtr;
// for (k=0; k<CodeLength; k++)
// {
// fprintf(fp,"%d %d\n",(int) TempChipSequencePtr->real,(int) TempChipSequencePtr->imaginary);
// TempChipSequencePtr++;
// }
//
// fclose(fp);
//End Debug Code
//*********************************************************
return(ChipSequencePtr);
}
double TransmitterClass::UniformRandomNumberGenerator(int *idum)
/*******************************************************************************************
* double UniformRandomNumberGenerator(int *idum)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* A random number generator that produces a random number between 0 and 1
*
* Returns A double value between 0 and 1
*
*Parameters
* Input
* idum int * Reinitializes the random number sequence if the contents is set
* to a negative value
*******************************************************************************************/
{
static double y,maxran,v[98];
double dum;
static int iff=0;
int j;
unsigned i;
if (*idum < 0 || iff == 0) //If the contents of the arguement is negative
{ //Then reset the seed
iff=1;
i=2;
maxran = RAND_MAX+1;
// srand(1);
srand( (unsigned)time( NULL ) );
*idum=1;
for (j=1; j <= 97; j++) dum = rand();
for (j=1; j <= 97; j++) v[j] = rand();
y=rand();
}
//Otherwise generate the number
j = 1 + 97.0 * y / maxran;
if (j > 97 || j < 1)
{
printf("\nj = %d. This should not have happened!\n",j);
printf("j should have been between 1 and 97\n");
return(-1);
}
y=v[j];
v[j]=rand();
return(y/maxran);
}
int TransmitterClass::FillDesiredFrame(DPCH_FormatStructure format,
int *PilotPtr,
unsigned TPCCommand,
ComplexNumber *FrameBufferPtr,
int *DataBitsPtr,
int *DesiredDataPtr)
/************************************************************************************
/int TransmitterClass::FillDesiredFrame(DPCH_FormatStructure format,
/ int *PilotPtr,
/ unsigned TPCCommand,
/ ComplexNumber *FrameBufferPtr,
/ int *DataBitsPtr,
/ int *DesiredDataPtr)
/
/ Copyright 2002 The Mobile and Portable Radio Research Group
/
/Loads the frame with random symbols for data, the transmit power control symbols,and
/the Pilot symbols, which are supplied by *PilotPtr. Since this frame is the
/"desired frame", the funtion also loads a buffer that contains the raw user data
/
/Returns: Integer that denotes the number of user data bits in the frame.
/
/Parameters
/ Input
/ format DPCH_FormatStructure Configuration and format of the
/ Desired DPCH
/ PilotPtr int * Pointer to the Pilot Bits for the frame
/ TPCCommand unsigned The Transmit Power Control Command
/ DataBitsPtr int * Pointer to an arraythat contains the
/ random Bits that will be used to fill the frame
/ Output
/ FrameBufferPtr ComplexNumber * Pointer to an array that contains the data
/ and control symbols for the frame
/ DesiredDataPtr int * Pointer to an array that contains the data
/ bits (i.e. the traffic) for the frame
/************************************************************************************/
{
unsigned j,k; //Loop counters
int *TempPilotPtr; //Temporary Pointer to the Pilot Bits array
int *TempDataBitsPtr; //Temporary pointer to the array that stores
//the random bits for filling the frame
int *TempDesiredDataPtr; //Temporary pointer to the array the contains
//the data bits
ComplexNumber *TempFrameBufferPtr; //Temporary Pointer to the array that contains
//the symbols for the frame
int NDesiredDataBits; //The number of data bits in the frame
int TPCsymbol; //If TPCCommand = 1, then TPCsymbol = -1
//If TPCCommand = 0, then TPCsymbol = 1
//Assign Temporary Pointers
TempDesiredDataPtr = DesiredDataPtr;
TempFrameBufferPtr = FrameBufferPtr;
TempDataBitsPtr = DataBitsPtr;
TempPilotPtr = PilotPtr;
//Set the TPC Symbol
TPCsymbol = 1 - 2*TPCCommand;
//Fill the buffer on a slot-by-slot basis
for (k=0; k<format.MaxSlotsPerFrame; k++)
{
/********************************************************
Note that the bits placed in to the complex symbols by placing the first bit into the
real part (of the symbol) and the next bit into the imaginary part and so on
*********************************************************/
//fill Data1 field
for (j=0; j<format.Ndata1; j+=2)
{
TempFrameBufferPtr->real = (double) *TempDataBitsPtr;
*TempDesiredDataPtr++ = *TempDataBitsPtr++;
TempFrameBufferPtr->imaginary = (double) *TempDataBitsPtr;
*TempDesiredDataPtr++ = *TempDataBitsPtr++;
TempFrameBufferPtr++;
}
//fill TPC field
for (j=0; j<format.Ntpc; j+=2)
{
TempFrameBufferPtr->real = (double) TPCsymbol;
TempFrameBufferPtr->imaginary = (double) TPCsymbol;
TempFrameBufferPtr++;
}
//fill TFCI field--for now it is just random data
for (j=0; j<format.Ntfci; j+=2)
{
TempFrameBufferPtr->real = (double) *TempDataBitsPtr++;
TempFrameBufferPtr->imaginary = (double) *TempDataBitsPtr++;
TempFrameBufferPtr++;
}
//fill Data2 field
for (j=0; j<format.Ndata2; j+=2)
{
TempFrameBufferPtr->real = (double) *TempDataBitsPtr;
*TempDesiredDataPtr++ = *TempDataBitsPtr++;
TempFrameBufferPtr->imaginary = (double) *TempDataBitsPtr;
*TempDesiredDataPtr++ = *TempDataBitsPtr++;
TempFrameBufferPtr++;
}
//fill Pilot field
for (j=0; j<format.NPilot; j+=2)
{
TempFrameBufferPtr->real = (double) *TempPilotPtr++;
TempFrameBufferPtr->imaginary = (double) *TempPilotPtr++;
TempFrameBufferPtr++;
}
}
/********************************************
//Debuggin Code
FILE *fp;
fp = fopen("DesiredDPCHdata.txt","w");
TempFrameBufferPtr = FrameBufferPtr;
for (k=0;k<150;k++)
{
fprintf(fp,"%d %d\n",(int) TempFrameBufferPtr->real,(int) TempFrameBufferPtr->imaginary);
TempFrameBufferPtr++;
}
fclose(fp);
/************************************************/
//Compute the number of Data Bits used in frame generation
NDesiredDataBits = TempDesiredDataPtr - DesiredDataPtr +1;
return (NDesiredDataBits);
}
int TransmitterClass::FillUndesiredFrame(DPCH_FormatStructure format,
int *PilotPtr,
unsigned TPCCommand,
ComplexNumber *FrameBufferPtr,
int *DataBitsPtr)
/************************************************************************************
/int TransmitterClass::FillUndesiredFrame(DPCH_FormatStructure format,
int *PilotPtr,
unsigned TPCCommand,
ComplexNumber *FrameBufferPtr,
int *DataBitsPtr)
/
/ Copyright 2002 The Mobile and Portable Radio Research Group
/
/Loads the frame with random symbols for data, the transmit power control symbols,and
/the Pilot symbols, which are supplied by *PilotPtr. Since this frame is the
"desired frame", the funtion also loads a buffer that contains the raw user data
/
/Returns: Integer that denotes the number of user data bits in the frame.
/
/Parameters
/ Input
/ format DPCH_FormatStructure Configuration and format of the
/ Desired DPCH
/ PilotPtr int * Pointer to the Pilot Bits for the frame
/ TPCCommand unsigned The Transmit Power Control Command
/ DataBitsPtr int * Pointer to an arraythat contains the
/ random Bits that will be used to fill the frame
/ Output
/ FrameBufferPtr ComplexNumber * Pointer to an array that contains the data
/ and control symbols for the frame
/
/Returns: Integer that denotes the number of user data bits in the frame.
/************************************************************************************/
{
unsigned j,k; //Loop counters
int *TempPilotPtr; //Temporary Pointer to the Pilot Bits array
int *TempDataBitsPtr; //Temporary pointer to the array that stores
//the random bits for filling the frame
int *TempDesiredDataPtr; //Temporary pointer to the array the contains
//the data bits
ComplexNumber *TempFrameBufferPtr; //Temporary Pointer to the array that contains
//the symbols for the frame
int TPCsymbol; //If TPCCommand = 1, then TPCsymbol = -1
//If TPCCommand = 0, then TPCsymbol = 1
//Assign Temporary Pointers
TempFrameBufferPtr = FrameBufferPtr;
TempDataBitsPtr = DataBitsPtr;
TempPilotPtr = PilotPtr;
//Set the TPC Symbol
TPCsymbol = 1 - 2*TPCCommand;
for (k=0; k<format.MaxSlotsPerFrame; k++)
{
//fill Data1 field
for (j=0; j<format.Ndata1; j+=2)
{
TempFrameBufferPtr->real = (double) *TempDataBitsPtr++;
TempFrameBufferPtr->imaginary = (double) *TempDataBitsPtr++;
TempFrameBufferPtr++;
}
//fill TPC field
for (j=0; j<format.Ntpc; j+=2)
{
TempFrameBufferPtr->real = (double) TPCsymbol;
TempFrameBufferPtr->imaginary = (double) TPCsymbol;
TempFrameBufferPtr++;
}
//fill TFCI field--for now it is just random data
for (j=0; j<format.Ntfci; j+=2)
{
TempFrameBufferPtr->real = (double) *TempDataBitsPtr++;
TempFrameBufferPtr->imaginary = (double) *TempDataBitsPtr++;
TempFrameBufferPtr++;
}
//fill Data2 field
for (j=0; j<format.Ndata2; j+=2)
{
TempFrameBufferPtr->real = (double) *TempDataBitsPtr++;
TempFrameBufferPtr->imaginary = (double) *TempDataBitsPtr++;
TempFrameBufferPtr++;
}
//fill Pilot field
for (j=0; j<format.NPilot; j+=2)
{
TempFrameBufferPtr->real = (double) *TempPilotPtr++;
TempFrameBufferPtr->imaginary = (double) *TempPilotPtr++;
TempFrameBufferPtr++;
}
}
//Compute the number of Data Bits used in frame generation
return (TempDataBitsPtr - DataBitsPtr - (format.MaxSlotsPerFrame * format.Ntfci) );
}
int TransmitterClass::STTDcodeDPCH(ComplexNumber *FrameBufferPtr,
DPCH_FormatStructure format,
unsigned SymbolsPerFrame)
/************************************************************************************
/int TransmitterClass::STTDcodeDPCH(ComplexNumber *FrameBufferPtr,
/ DPCH_FormatStructure format,
/ unsigned SymbolsPerFrame)
/
/ Copyright 2002 The Mobile and Portable Radio Research Group
/
/ Applies the STTD code to the DPCH by constructing the data frame for Antenna #2.
/This data frame is appended to the back of FrameBufferPtr, which should have the
/space allocated for the 2nd code. For each slot in the frame, STTD coding is
/applied to all fields except the pilot field, which is filled via a lookup table.
/For the case were the spreading factor is 512, the first two bits in each slot are
/not coded.
/
/Returns an integer for the error code
/
/Parameters
/ Input
/ format DPCH_FormatStructure Contains the configuration of the DPCH
/ SymbolsPerFrame unsigned Contains the number of complex symbols
/ per channel frame
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -