## Constant complexity rectangular QAM demodulator

November 14, 2010 Coded in C for the TI C67x

This code can demodulate an input to a constellation of size 'm'. The number of steps to perform the demodulation is independent of 'm'.

``````% N is the size of the constellation.
% v is the input data.
% For details email me.
void function_qam()
{

co=0;
m=0;

for(q=0; q<N; q++)

{

a=v[m];// a holds the real part
b=v[m+1];// b holds the imaginary part

d=a-onern[max];  %onern stores the negative real axis points and onein stores the negative imag axis points. eg for 256 QAM, each will store 0 to -8 as an array.
l=d;         //l stores the distance
s=(d-l);
if(l<max-1) % max is the maximum value that the 1-d coordinate can take.
{

if(d>0){
if(s<=.5)
{
hi=max-l;
flagtwo=1;
}
else
{
hi=max-l-1;
flagtwo=1;
}
}
else
{
hi=max;
flagtwo=1;
}

}

if(l==max-1)
{
hi=1;
flagtwo=1;
}
if(l==max)//
{
flagone=1;
hi=1;
}

if(l>max)
{
if(d<2*max)
{

if(s<=.5)
{
hi=l-max;
flagone=1;
}
else
{
hi=l-max+1;
flagone=1;
}
}
else
{
hi=max;
flagone=1;
}

}

de=b-onein[max];
le=de;         //l stores the distance
se=(de-le);

if(le<max-1)
{

if(de>0)
{
if(se<=.5)
{
hm=max-le;
flagfour=1;
}
else
{
hm=max-le-1;
flagfour=1;
}

}
else
{
hm=max;
flagfour=1;
}

}

if(le==max-1)
{
hm=1;
flagfour=1;
}
if(le==max)
{
flagthree=1;
hm=1;
}

if(le>max)
{

if(de<2*max){

if(se<=.5)
{
hm=le-max;
flagthree=1;
}
else
{
hm=le-max+1;
flagthree=1;
}
}
else
{
hm=max;
flagthree=1;
}

}

if(flagone==1)
{
vv[m]=hi;  // now v[m] holds one x coordinate of the qam mapping and v[m+1] holds the y coordinate
}

else
{
vv[m]= 100-hi;
}

if(flagthree==1)
{
vv[m+1]=hm;
}
else
{
vv[m+1]= 100-hm;
}

flagone=0;
flagtwo=0;
flagthree=0;
flagfour=0;
r=0;

output[co]= valuetable[ vv[m] ][ vv[m+1] ] ;

m = m+ 2;

co = co+ 1;

}

for(t=0;t<(N/2);t++)
{
p[t] = (output[t]);

}

}``````