📄 receiverclass.cpp
字号:
}
//Initialize the Channel Estimate Vector
ChannelEstimatePtr = (ComplexNumber *) calloc(SlotsPerFrame,sizeof(ComplexNumber));
if (ChannelEstimatePtr == NULL)
{
printf("Memory allocation for ChannelEstimatePtr failed--exiting\n");
return(NULL);
}
//Now Perform the channel Estimates--One estimate per Slot
//The estimates are obtained by dividing the despread symbol by the known pilot symbol
//for that particular location. Then for each slot, these estimates are averaged
TempChannelEstimatePtr = ChannelEstimatePtr;
TempDespreadSignalPtr = DespreadSignal;
TempPilotPtr = PilotPtr;
for (k=0; k<SlotsPerFrame; k++)
{
TempDespreadSignalPtr += PilotPositionInSlot;
CurrentEstimate.real = 0.0;
CurrentEstimate.imaginary = 0.0;
//Generate the channel estimate for each pilot symbol location in the slot
//and accumulate over all pilot symbol locations in the slot
for (j=0; j<NumPilotSymbols; j++)
CurrentEstimate = ComplexAdd(CurrentEstimate,ComplexDivide(*TempDespreadSignalPtr++,*TempPilotPtr++));
//Take the average
*TempChannelEstimatePtr++ = ComplexRealDivide(CurrentEstimate , (double) (NumPilotSymbols * SF) );
/************************************************************************************************
//Debug Code to compensate for channel estimation errors
CurrentEstimate.real = 2.0;
CurrentEstimate.imaginary = 0.0;
*(TempChannelEstimatePtr-1)=CurrentEstimate;
/************************************************************************************************/
}
return(ChannelEstimatePtr);
}
void ReceiverClass::ApplyChannelEstimates(DPCH_FormatStructure Format,
ComplexNumber *DespreadSignal,
ComplexNumber *ChannelEstimate)
/****************************************************************************************************
void ReceiverClass::ApplyChannelEstimates(DPCH_FormatStructure Format,
* ComplexNumber *DespreadSignal,
* ComplexNumber *ChannelEstimate)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* Multiplies the Despread Signal by the channel estimates. Note that we have one channel
* estimate per slot. Therefore, the channel estimates are applied on a slot-by-slot by multiplying
* the despread signal by the conjugate of the channel response
*
* Returns: None
*
* Parameters
* Format DPCH_FormatStructure Contains the format information of the desired frame
* DespreadSignal ComplexNumber * Contains the despread symbol values
* ChannelEstimate ComplexNumber * Contains the Channel Estimates
*****************************************************************************************************/
{
unsigned SlotsPerFrame; //Number of slots in a given frame
unsigned SymbolsPerSlot; //Number of symbols in a given slott
unsigned j,k; //Loop countes
ComplexNumber *TempDespreadSignal; //Temporary pointer to the array that contains the despread signal
ComplexNumber *TempChannelEstimate; //Temporary pointer to the array that contains the channel estimates
//Compute the number of slots per frame
SlotsPerFrame = Format.ActualSlotsPerFrame;
//Compute the number of symbols per slot
SymbolsPerSlot = Format.BitsPerSlot >> 1;
//Assign temporary pointers
TempChannelEstimate = ChannelEstimate;
TempDespreadSignal = DespreadSignal;
//Apply the channel estimate by multiplying each slot with the conjugate of the channel estimate
//for that slot
for (k=0; k<SlotsPerFrame; k++)
{
for (j=0; j<SymbolsPerSlot; j++)
*TempDespreadSignal++ = ComplexMultiply(*TempDespreadSignal,Conjugate(*TempChannelEstimate));
TempChannelEstimate++;
}
}
int * ReceiverClass::DetectBits(DPCH_FormatStructure Format,
ComplexNumber *DespreadSignal)
/***********************************************************************************************
* int * ReceiverClass::DetectBits(DPCH_FormatStructure Format,
* ComplexNumber *DespreadSignal)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* This function uses the despread signal to detect the data bits in the associated frame
* The funciton assumes that phase shifts and amplitude shifts resulting from channel effects
* (e.g., fading) have already been compensated for. The function also assumes that any diversity
* combining (if any) have already been accomplished. Therefore, if the signal value (in-phase or
* quadrature is greater than 0, then a '1' is detected. Otherwise a '-1' is detected
*
* Returns: An integer array of that contains the detected data bits associated with incoming
* signal
*
* Parameters
* Format DPCH_FormatStructure Contains the format information of the desired frame
* DespreadSignal ComplexNumber * Contains the despread symbol values
*************************************************************************************************/
{
unsigned k,j; //Loop counters
int *DetectedDataBits,*TempDetectedDataBits; //Pointer and temporary pointer to the array
//that contains the detected data bits
ComplexNumber *TempDespreadSignal; //Temporary pointer to the array that contains
//the despread signal
unsigned DataBitsPerFrame; //Number of data bits in a given frame
unsigned SkipLength; //used to skip over non-data fields in a given slot
//e.g., the Pilot, TFCI, and TPC fields
unsigned Data1Symbols; //Stores the number of symbols in the data1 field
unsigned Data2Symbols; //Stores the number of symbols in the data2 field
//Determine the skip length
SkipLength = (Format.Ntpc + Format.Ntfci) >> 1;
//Determine the number of symbols in the data1 field
Data1Symbols = Format.Ndata1 >> 1;
//Determine the number of symbols in the data2 field
Data2Symbols = Format.Ndata2 >> 1;
//Determine the number of databits in a given frame
DataBitsPerFrame = Format.ActualSlotsPerFrame * (Format.Ndata1 + Format.Ndata2);
//Allocate memory for an array that will store the detected data bits
DetectedDataBits = (int *) calloc(DataBitsPerFrame,sizeof(int));
if (DetectedDataBits == NULL)
{
printf("memory Allocation for DetectedDataBits failed--exiting\n");
return(NULL);
}
//Assign temporary pointers
TempDetectedDataBits = DetectedDataBits;
TempDespreadSignal = DespreadSignal;
//Go through the detection process on a slot-by-slot basis
for (k=0; k<Format.ActualSlotsPerFrame; k++)
{
//first do symbols in the data1 field
for (j=0; j< Data1Symbols; j++)
{
if ((TempDespreadSignal->real) >= 0.0)
*TempDetectedDataBits++ = 1;
else
*TempDetectedDataBits++ = -1;
if ((TempDespreadSignal->imaginary) >= 0.0)
*TempDetectedDataBits++ = 1;
else
*TempDetectedDataBits++ = -1;
TempDespreadSignal++;
}
TempDespreadSignal += SkipLength;
//Then do symbols in the data2 field
for (j=0; j< Data2Symbols; j++)
{
if ((TempDespreadSignal->real) >= 0.0)
*TempDetectedDataBits++ = 1;
else
*TempDetectedDataBits++ = -1;
if ((TempDespreadSignal->imaginary) >= 0.0)
*TempDetectedDataBits++ = 1;
else
*TempDetectedDataBits++ = -1;
TempDespreadSignal++;
}
TempDespreadSignal += (Format.NPilot >> 1);
}
return(DetectedDataBits);
}
ComplexNumber * ReceiverClass::STTDChannelEstimator(DPCH_FormatStructure Format,ComplexNumber *DespreadSignal)
/********************************************************************************************************************
* ComplexNumber * ReceiverClass::STTDChannelEstimator(DPCH_FormatStructure Format,ComplexNumber *DespreadSignal)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* The function estimates the two complex channel gains associated with a STTD link. In such a link, two transimtter
* antennas and only one receive antenna are employed. Therefore, for each slot, two channel gain estimates are required.
* this function uses the Pilot symbols in each slot to estimate these gains.
*
* It is important to note that specific estimation procedure is a direct funciton of the number of Pilot bits per slot
* used in the transmission. Details of the specific estimation procedure are documented in the code
*
* Returns A ComplexNumber type array of length 30 (assuming the frame contains 15 slots) containing the channel gains
* from the two antennas to the receiver. The even numbered elements (note the elements are numbered 0 to 29)
* contain the channel estimates from transmit antenna 0 to the receiver. The odd numbered elements contain
* the channel estimates from transmit antenna 1 to the receiver.
*
* Parameters
* Format DPCH_FormatStructure Contains the format information of the desired frame
* DespreadSignal ComplexNumber * Contains the despread symbol values
*********************************************************************************************************************/
{
//***************************************************************************************************************
//Declare and define Pilot symbols
const ComplexNumber Npilot2[15]= {{-1,-1},
{1,1},
{1,-1},
{1,1},
{-1,1},
{-1,-1},
{-1,-1},
{-1,1},
{1,-1},
{-1,-1},
{1,-1},
{-1,1},
{-1,1},
{1,1},
{1,1}};
const ComplexNumber Npilot4[30]= {{-1,-1},{-1,-1},
{-1,-1},{1,1},
{-1,-1},{1,-1},
{-1,-1},{1,1},
{-1,-1},{-1,1},
{-1,-1},{-1,-1},
{-1,-1},{-1,-1},
{-1,-1},{-1,1},
{-1,-1},{1,-1},
{-1,-1},{-1,-1},
{-1,-1},{1,-1},
{-1,-1},{-1,1},
{-1,-1},{-1,1},
{-1,-1},{1,1},
{-1,-1},{1,1}};
const ComplexNumber Npilot8[60]= {{-1,-1},{-1,-1},{-1,-1},{-1,1},
{-1,-1},{1,1},{-1,-1},{-1,1},
{-1,-1},{1,-1},{-1,-1},{1,-1},
{-1,-1},{1,1},{-1,-1},{1,1},
{-1,-1},{-1,1},{-1,-1},{1,-1},
{-1,-1},{-1,-1},{-1,-1},{-1,1},
{-1,-1},{-1,-1},{-1,-1},{1,1},
{-1,-1},{-1,1},{-1,-1},{1,1},
{-1,-1},{1,-1},{-1,-1},{-1,1},
{-1,-1},{-1,-1},{-1,-1},{-1,-1},
{-1,-1},{1,-1},{-1,-1},{1,-1},
{-1,-1},{-1,1},{-1,-1},{-1,-1},
{-1,-1},{-1,1},{-1,-1},{1,1},
{-1,-1},{1,1},{-1,-1},{-1,-1},
{-1,-1},{1,1},{-1,-1},{-1,-1}};
const ComplexNumber Npilot16[120]= {{-1,-1},{-1,-1},{-1,-1},{-1,1},{-1,-1},{-1,-1},{-1,-1},{-1,1},
{-1,-1},{1,1},{-1,-1},{-1,1},{-1,-1},{-1,-1},{-1,-1},{1,1},
{-1,-1},{1,-1},{-1,-1},{1,-1},{-1,-1},{-1,1},{-1,-1},{1,1},
{-1,-1},{1,1},{-1,-1},{1,1},{-1,-1},{1,-1},{-1,-1},{-1,1},
{-1,-1},{-1,1},{-1,-1},{1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
{-1,-1},{-1,-1},{-1,-1},{-1,1},{-1,-1},{1,-1},{-1,-1},{1,-1},
{-1,-1},{-1,-1},{-1,-1},{1,1},{-1,-1},{-1,1},{-1,-1},{-1,-1},
{-1,-1},{-1,1},{-1,-1},{1,1},{-1,-1},{-1,1},{-1,-1},{1,1},
{-1,-1},{1,-1},{-1,-1},{-1,1},{-1,-1},{1,1},{-1,-1},{-1,-1},
{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{1,1},{-1,-1},{-1,-1},
{-1,-1},{1,-1},{-1,-1},{1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,1},
{-1,-1},{-1,1},{-1,-1},{-1,-1},{-1,-1},{1,1},{-1,-1},{-1,1},
{-1,-1},{-1,1},{-1,-1},{1,1},{-1,-1},{1,-1},{-1,-1},{1,-1},
{-1,-1},{1,1},{-1,-1},{-1,-1},{-1,-1},{1,1},{-1,-1},{1,1},
{-1,-1},{1,1},{-1,-1},{-1,-1},{-1,-1},{-1,1},{-1,-1},{1,-1}};
//Pilot symbols declared and defined
//***************************************************************************************************************
const ComplexNumber Sdata[4] = {{1,1},{1,-1},{-1,1},{-1,-1}}; //Stores the four possible symbol values
ComplexNumber *PilotPtr,*TempPilotPtr; //Poiter and temporary pointer to the array that contains
//the select pilot symbol
unsigned SF; //Spreading Factor
unsigned NumPilotSymbols; //Number of pilto symbols
ComplexNumber *ChannelEstimatePtr,*TempChannelEstimatePtr; //Poiner and temporary pointer to the array that
//contains the channel estimates
ComplexNumber *TempDespreadSignalPtr; //Temporary poiner to the despread signal
unsigned PilotPositionInSlot; //Location of the first pilot symbol in every slot
unsigned SlotsPerFrame; //Number of slots per frame
ComplexNumber TempEstimate0,TempEstimate1; //Temporary storage for the channel estimates
ComplexNumber s,s0,s1,r0,r1,r2,r3,r4,r5,r6,r7; //Varialbes used in channel estimation procedure
ComplexNumber fee,foo; //Temporary storage (general use)
unsigned j,k; //Loop counters
//Get spreading factor
SF = Format.SF;
//Determine the number of pilot symbols in a given slot
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -