receiver.cpp
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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;
}
}
};