-
Notifications
You must be signed in to change notification settings - Fork 11
/
MIMO_VLC.cpp
160 lines (127 loc) · 2.88 KB
/
MIMO_VLC.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "MIMO_VLC.h"
MIMO_VLC :: MIMO_VLC()
{
}
MIMO_VLC :: ~MIMO_VLC()
{
}
void MIMO_VLC :: Initialization()
{
FILE *fp;
char Setup_file_name[500] = "Setup_of_MIMO_VLC.txt";
char strTemp[500];
if(( fp = fopen(Setup_file_name, "r") ) == NULL)
{
printf("%s can not be opened!\n", Setup_file_name);
exit(1);
}
fscanf(fp, "%s", strTemp);
fscanf(fp,"%lf", &m_minsnr);
fscanf(fp, "%s", strTemp);
fscanf(fp,"%lf", &m_maxsnr);
fscanf(fp, "%s", strTemp);
fscanf(fp,"%lf", &m_arcsnr);
fscanf(fp, "%s", strTemp);
fscanf(fp, "%d", &m_max_block);
fscanf(fp, "%s", strTemp);
fscanf(fp, "%d", &m_len_bb);
fscanf(fp, "%s", strTemp);
fscanf(fp, "%s", m_Modem_file_name);
fclose(fp);
m_len_cc = m_len_bb;//This is valid in uncoded scheme
m_modem.m_len_cc = m_len_cc;//Pass m_len_cc to Modem module
m_modem.Initialization(m_Modem_file_name);
m_len_xx = m_modem.m_len_per_sym * m_modem.m_num_sym_per_xx;
m_len_yy = m_len_xx;
m_bb = new int[m_len_bb];
m_cc = new int[m_len_cc];
m_xx = new double[m_len_xx];
m_yy = new double[m_len_yy];
m_nn = new double[m_len_yy];
m_cc_hat = new int[m_len_cc];
m_bb_hat = new int[m_len_bb];
m_source.Initialization();
//cout << "MIMO-VLC has been initialzed!!\n";
m_source.PrintResult(m_Modem_file_name);
m_source.PrintResult2Terminal(m_Modem_file_name);
return;
}
void MIMO_VLC :: Simulation()
{
Initialization();
for(double snr = m_minsnr; snr <= m_maxsnr; snr += m_arcsnr)
{
m_var = pow(10, -0.1 * snr);
m_sigma = sqrt(m_var);
m_source.clc();
for(int simu_blocks = 1; simu_blocks <= m_max_block; ++simu_blocks)
{
m_source.getBitVec(m_len_bb, m_bb);
#if DEG
for(int i = 0; i < m_len_bb; ++i)
{
cout << m_bb[i] << " ";
}
cout << endl;
#endif
//channel coding
for(int i = 0; i < m_len_bb; ++i)
{
m_cc[i] = m_bb[i];
}
//modulation
m_modem.MIMO_Modulation(m_cc, m_xx);
#if DEG
for(int i = 0; i < m_len_xx; i++)
{
cout << m_xx[i] << " ";
}
cout << endl;
#endif
//AWGN
m_source.getGaussNoiseVec(m_len_yy, m_nn);
for(int i = 0; i < m_len_yy; ++i)
{
m_yy[i] = m_xx[i] + m_nn[i] * m_sigma;
//m_yy[i] = m_xx[i];
}
#if DEG
for(int i = 0; i < m_len_xx; i++)
{
cout << m_yy[i] << " ";
}
cout << endl;
#endif
//demodulation
m_modem.MIMO_Hard_Demodulation(m_bb_hat, m_yy);
#if DEG
for(int i = 0; i < m_len_bb; ++i)
{
cout << m_bb_hat[i] << " ";
}
cout << endl;
#endif
m_source.CalculateBER(m_bb, m_bb_hat, m_len_bb);
if(simu_blocks == 1 || simu_blocks == m_max_block || simu_blocks % 100 == 0)
{
m_source.PrintResult2Terminal(simu_blocks, snr);
}
}
m_source.PrintResult(snr);
}
FreeMemory();
return;
}
void MIMO_VLC :: FreeMemory()
{
delete []m_bb;
delete []m_cc;
delete []m_xx;
delete []m_yy;
delete []m_nn;
delete []m_cc_hat;
delete []m_bb_hat;
m_source.FreeMemory();
m_modem.FreeMemory();
return;
}