receiver.cpp 1.21 KB
#include "receiver.h"
#include "variables.h"
#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.14159


Creceiver::Creceiver() {


}
void Creceiver::demodulate()
{
	float c0[20];
	float c1[20];
	for (float t = 0; t < Nsamplespersymbol; t++)
	{
		c0[(int)t] = sqrt(2 * Nsamplespersymbol)*cos(2 * PI*Nsamplespersymbol*t);
		c1[(int)t] = sqrt(2 * Nsamplespersymbol)*sin(2 * PI*Nsamplespersymbol*t);
	}

	for (int i = 0; i < Nbits * 10; i = i + 20)
	{
		float sum_C0 = 0;
		float sum_C1 = 0;
		for (int j = 0; j < 20; j++)
		{
			sum_C0 = sum_C0 + (r[i + j] * c0[j]);
			sum_C1 = sum_C1 + (r[i + j] * c1[j]);
		}
		constellation[i / 10] = sum_C0 / 383.;
		constellation[(i / 10) + 1] = sum_C1 / 415.;
	}

	for (int i = 0; i < Nbits; i = i + 2)
	{
		if (constellation[i] > 0 && constellation[i + 1] > 0)
		{
			DecodedData[i] = 0;
			DecodedData[i + 1] = 0;
		}
		else if (constellation[i] < 0 && constellation[i + 1] > 0)
		{
			DecodedData[i] = 1;
			DecodedData[i + 1] = 0;
		}

		else if (constellation[i] < 0 && constellation[i + 1] < 0)
		{
			DecodedData[i] = 1;
			DecodedData[i + 1] = 1;
		}

		else if (constellation[i] > 0 && constellation[i + 1] < 0)
		{
			DecodedData[i] = 0;
			DecodedData[i + 1] = 1;
		}
	}
};