sender.h
1.23 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef __SENDER
#define __SENDER
#include <cmath>
#include "variables.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#define PI 3.141592
using namespace std;
class Csender
{
private:
public:
float c0;
float c1;
float T = 20;
float t = 0;
float A = 100;
float b0[500];
float b1[500];
int sum = 0;
float data[Nbits]; // 1000°³
Csender()
{};
float s[Nbits/Nbitspersymbol*Nsamplespersymbol]; // trasmitted signal
void transmitData()
{
ofstream out("senderoutput.txt");
srand((unsigned int)time(NULL));
for (int i = 0; i < 1000; i++)
{
data[i] = rand() % 2;
out << data[i] << endl;
}
for (int i = 0; i < 1000; i++)
{
if (data[i] == 0)
{
data[i] = 1;
}
else if (data[i] == 1)
{
data[i] = -1;
}
}
for (int i = 0; i < 500; i++)
{
b0[i] = data[2 * i];
b1[i] = data[(2 * i) + 1];
}
c0 = sqrt(2 / T) * cos(2 * PI / T * t);
c1 = sqrt(2 / T) * sin(2 * PI / T * t);
sum = 0;
for (int i = 0; i < 500; i++)
{
for (t = 0; t < 20; t++)
{
s[sum] = A * ((b0[i] * sqrt(2 / T) * cos(2 * PI / T * t)) + b1[i] * sqrt(2 / T) * sin(2 * PI / T * t));
sum++;
}
}
}
//1½Éº¼À» 20°³·Î ÂÉ°µ´Ù.
};
#endif