📄 rxdetector.c
字号:
/*****************************************************************************
Module : Detector
******************************************************************************
Function :
Procedures :
Author : $Author: Adrian $
Revision : $Revision: 13 $
Modified : $Modtime: 05-05-29 17:42 $
File : $Workfile: rxdetector.c $
******************************************************************************
KTH, Royal Institute of Technology, S3, Stockholm
*****************************************************************************/
/*--- Include files --------------------------------------------------------*/
/* import */
#include <math.h>
/* export */
#include "rxdetector.h"
#include "receivercfg.h"
#include <log.h>
/*=== End of include files =================================================*/
/*--- Global variables definition ------------------------------------------*/
typRX_DETECTORSTATE DetectorStat;
/*=== End of global variables definition ===================================*/
/*--- Global constants definition ------------------------------------------*/
/*=== End of global constants definition ===================================*/
/*--- Local defines --------------------------------------------------------*/
/*=== End of local defines =================================================*/
/*--- Local types declaration ----------------------------------------------*/
/*=== End of local types declaration =======================================*/
/*--- Local variables definition -------------------------------------------*/
/*=== End of local variables definition ====================================*/
/*--- Local constants definition -------------------------------------------*/
/*=== End of local constants definition ====================================*/
/*--- Local functions definition -------------------------------------------*/
/****************************************************************************
Function : MaptoBytes
****************************************************************************
Description : Maps the detected symbols to bytes
Inputs : The real and imaginary part of two symbols
Outputs : The two symbols in bytes
By : 2005-05-13 Created by Anders Lindgren
2005-05-15 modified by Anders Lindgren
****************************************************************************/
//static char MaptoBytes(float Ich_1, float Qch_1, float Ich_2, float Qch_2)
static char MaptoBytes(float Ich, float Qch)
{
//int k;
//int i;
char c = 0x00;
//I-channel 1
if (Ich > 0)
{
//bhat_1[i] = 1;
c = c|0x08;
if (Ich <= 2)
{
//bhat_1[i+1] = 1;
c = c|0x04;
}
}
else
{
//bhat_1[i] = 0;
//a = a|0x00 //Don't need to do this setting?
if (Ich > -2)
{
//bhat_1[i+1] = 1;
c = c|0x04;
}
}
//Q-channel 1
if (Qch > 0)
{
//bhat_1[i+2] = 1;
c = c|0x02;
if (Qch <= 2)
{
//bhat_1[i+3] = 1;
c = c|0x01;
}
}
else
{
//bhat_1[i+2] = 0;
if (Qch > -2)
{
//bhat_1[i+3] = 1;
c = c|0x01;
}
}
return c;
}
/****************************************************************************
Function : Detect
****************************************************************************
Description : Collect the bytes from the symbols into the DataBuffer
Inputs : Detected symbols
Outputs : Detected symbols in bytes
By : 2005-05-13 Created by Anders Lindgren
2005-05-15 modified by Anders Lindgren
****************************************************************************/
static void Detect(typRX_DETECTORSTATE *pDetectorStat)
{
int data_len;
int p, idx;
char a;
char b;
unsigned int uiNibble;
//char bhat_1[120]; //Antenna 1. Assume 30 symbols in a buffer, which gives 30*4=120 bits
//float bhat_2[120]; //Antenna 2
//float len;
float *Ich_1;
float *Qch_1;
float *Ich_2;
float *Qch_2;
//int nibble_1; //nibble assumes the values 0 and 1, where 0 equals 'low' and 1 equals 'high'
//int nibble_2;
data_len = pDetectorStat->uiNoOfSymb;
//len = 4*data_len;
Ich_1 = pDetectorStat->pfCplxSymbBuff_1->pIBuffer;
Qch_1 = pDetectorStat->pfCplxSymbBuff_1->pQBuffer;
Ich_2 = pDetectorStat->pfCplxSymbBuff_2->pIBuffer;
Qch_2 = pDetectorStat->pfCplxSymbBuff_2->pQBuffer;
/*for (p = 0; p < data_len; p = p + 2)
{
pDetectorStat->pcDataBuff[p] = MaptoBytes(Ich_1[p], Qch_1[p], Ich_1[p+1], Qch_1[p+1]);
pDetectorStat->pcDataBuff[p+1] = MaptoBytes(Ich_2[p], Qch_2[p], Ich_2[p+1], Qch_2[p+1]);
}*/
uiNibble = pDetectorStat->nibble;
pDetectorStat->uiBytesWritten = 0;
for (p = 0; p < data_len; p++, uiNibble ^= 1)
{
idx = (pDetectorStat->uiNextSymb + p) % pDetectorStat->uiBufLen;
a = MaptoBytes(Ich_1[idx], Qch_1[idx]);
b = MaptoBytes(Ich_2[idx], Qch_2[idx]);
switch(uiNibble)
{
case 1:
pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte] |= (a << 4) & 0xF0;
pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte+1] |= (b << 4) & 0xF0;
pDetectorStat->uiNextWriteByte += 2;
pDetectorStat->uiBytesWritten += 2;
break;
case 0:
pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte] = a & 0x0F;
pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte+1] = b & 0x0F;
break;
default:
#ifdef _DEBUGLOG
LOG_printf(&trace,"Value forbidden: file %s, line %d",__FILE__,__LINE__);
#endif
break;
}
}
pDetectorStat->nibble = uiNibble;
}
/****************************************************************************
Function : norm_ML
****************************************************************************
Description : Calculate the 2-norm of two symbols
Inputs : The real and imaginary part of two symbols
Outputs : 2-norm of the two symbols
By : 2005-05-07 Created by Anders Lindgren
2005-05-10 modified by Anders Lindgren
****************************************************************************/
static float norm_ML(float Z1_r, float Z1_i, float Z2_r, float Z2_i)
{
float len_Z1;
float len_Z2;
float norm_Z;
len_Z1 = sqrtf(Z1_r*Z1_r + Z1_i*Z1_i);
len_Z2 = sqrtf(Z2_r*Z2_r + Z2_i*Z2_i);
norm_Z = sqrtf(len_Z1*len_Z1 + len_Z2*len_Z2);
return norm_Z;
}
/****************************************************************************
Function : MLDetector
****************************************************************************
Description : Estimate the transmitted symbols with Maximum Likelihood
Inputs : Received symbols in antenna 1 and antenna 2
Outputs : Detected symbols in bytes
By : 2005-05-07 Created by Anders Lindgren
2005-05-13 modified by Anders Lindgren
****************************************************************************/
static void MLDetector(typRX_DETECTORSTATE *pDetectorStat)
{
float data_len;
float *pr1_data_I;
float *pr1_data_Q;
float *pr2_data_I;
float *pr2_data_Q;
float pS[2][2];
float pZ[2][2];
float normmin;
float newnorm;
float pS_out[4];
int pp, idx;
int s1_I = 0;
int s1_Q = 0;
int s2_I = 0;
int s2_Q = 0;
data_len = pDetectorStat->uiNoOfSymb;
pr1_data_I = pDetectorStat->pfCplxSymbBuff_1->pIBuffer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -