📄 modulating.cpp
字号:
/**********************************************/
/* Modulator
/* struct Complex * ModulatingF(struct BasicParaS * ctrl, int * input)
/* Written by: Ouyang Ziyue,
/* Date: Dec 21st, 2007,
/* Function: It maps the input bits into complex MQAM constellations
/* Input parameter:
/* The type of MQAM should be defined ahead,
/* The length of the input bits(N) is needed,
/* The input includes all the input encoded bits,
/* The numRetrans is needed.
/* Output parameter:
/* An COMPLEX set which consists all the modulation symbols is outputed
/* Note:
/* ctrl should be built before this function is called,
/* All the constellations are normalized.
/**********************************************/
#include "parameter_sets.h"
const double sqrt2norm[4] = {1.0, 1.414213562373095, 3.16227766016838, 6.48074069840786};
// {sqrt(1), sqrt(2), sqrt(10), sqrt(42)}, derived from Matlab 2006R
const Complex constMap_bpsk[2] = {{1.0, 0}, {-1.0, 0}};
const Complex constMap_qpsk[4] = {{1.0, 1.0}, {1.0, -1.0}, {-1.0, 1.0}, {-1.0, -1.0}};
const Complex constMap_16qam[16] = {{1.0, 1.0}, {1.0, 3.0}, {1.0, -1.0}, {1.0,-3.0}, {3.0, 1.0},
{3.0, 3.0}, {3.0, -1.0}, {3.0, -3.0}, {-1.0, 1.0}, {-1.0, 3.0}, {-1.0, -1.0}, {-1.0, -3.0},
{-3.0, 1.0}, {-3.0, 3.0}, {-3.0, -1.0}, {-3.0, -3.0}};
const Complex constMap_64qam[64] = {{3.0, 3.0}, {3.0, 1.0}, {3.0, 5.0}, {3.0, 7.0}, {3.0, -3.0},
{3.0, -1.0}, {3.0, -5.0}, {3.0, -7.0}, {1.0, 3.0}, {1.0, 1.0}, {1.0, 5.0}, {1.0, 7.0}, {1.0, -3.0},
{1.0, -1.0}, {1.0, -5.0}, {1.0, -7.0}, {5.0, 3.0}, {5.0, 1.0}, {5.0, 5.0}, {5.0, 7.0}, {5.0, -3.0},
{5.0, -1.0}, {5.0, -5.0}, {5.0, -7.0}, {7.0, 3.0}, {7.0, 1.0}, {7.0, 5.0}, {7.0, 7.0}, {7.0, -3.0},
{7.0, -1.0}, {7.0, -5.0}, {7.0, -7.0}, {-3.0, 3.0}, {-3.0, 1.0}, {-3.0, 5.0}, {-3.0, 7.0}, {-3.0, -3.0},
{-3.0, -1.0}, {-3.0, -5.0}, {-3.0, -7.0}, {-1.0, 3.0}, {-1.0, 1.0}, {-1.0, 5.0}, {-1.0, 7.0},
{-1.0, -3.0}, {-1.0, -1.0}, {-1.0, -5.0}, {-1.0, -7.0}, {-5.0, 3.0}, {-5.0, 1.0}, {-5.0, 5.0},
{-5.0, 7.0}, {-5.0, -3.0}, {-5.0, -1.0}, {-5.0, -5.0}, {-5.0, -7.0}, {-7.0, 3.0}, {-7.0, 1.0},
{-7.0, 5.0}, {-7.0, 7.0}, {-7.0, -3.0}, {-7.0, -1.0}, {-7.0, -5.0}, {-7.0, -7.0}};
struct Complex * ModulatingF(struct BasicParaS * ctrl, int * input, int numRetrans)
{
//////////////////////////////////////////////////////////////////////////
//Declaration
struct Complex * output;
int i,r,numSymOut,temp,N;
switch (ctrl->typeModu)
{
case 0:
r = 1;
break;
case 1:
r = 2;
break;
case 2:
r = 4;
break;
case 3:
r = 6;
break;
default:
exit(0);
}
if(numRetrans==0)
N = ctrl->codeN;
else
N = ctrl->codeM;
if (N%r)
{
printf("The number of symbols is not an integer!!!\n");
exit(0);
}
numSymOut = N/r;
ctrl->numModuOut = numSymOut;
ctrl->bitsPerSym = r;
output = new struct Complex[numSymOut];
switch(ctrl->typeModu)
{
case 0:
for (i=0; i<numSymOut; i++)
{
temp = * (input + i);
(* (output+i)).real = constMap_bpsk[temp].real/sqrt2norm[0];
(* (output+i)).imag = constMap_bpsk[temp].imag/sqrt2norm[0];
}
break;
case 1:
for (i=0; i<numSymOut; i++)
{
temp = (*(input + 2*i))*2 + (*(input + 2*i +1)); //计算四进制码
(*(output+i)).real = constMap_qpsk[temp].real/sqrt2norm[1];
(*(output+i)).imag = constMap_qpsk[temp].imag/sqrt2norm[1];
}
break;
case 2:
for (i=0; i<ctrl->numSymOut; i++) {
temp = (*(input+4*i))*8+(*(input+4*i+1))*4+(*(input+4*i+2))*2+(*(input+4*i+3));
(*(output+i)).real = constMap_16qam[temp].real/sqrt2norm[2];
(*(output+i)).imag = constMap_16qam[temp].imag/sqrt2norm[2];
}
break;
case 3:
for (i=0; i<ctrl->numSymOut; i++) {
temp = (*(input+6*i))*32+(*(input+6*i+1))*16+(*(input+6*i+2))*8+(*(input+6*i+3))*4+
(*(input+6*i+4))*2+(*(input+6*i+5))*1;
(*(output+i)).real = constMap_64qam[temp].real/sqrt2norm[3];
(*(output+i)).imag = constMap_64qam[temp].imag/sqrt2norm[3];
}
default:
exit(0);
}
//////////////////////////////////////////////////////////////////////////
//DEBUG
#ifdef DEBUG
printf("The modulated symbol are ..\n");
temp = 0;
for (i=0; i<numSymOut; i++)
{
printf("%.3f+j%.3f\t ", (*(output+i)).real, (*(output+i)).imag);
temp++;
if (temp == 4)
{
printf("\n");
temp=0;
}
}
#endif
return output;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -