-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_demap_modulation.cpp
179 lines (157 loc) · 4.42 KB
/
my_demap_modulation.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "my_demap_modulation.h"
void demodulation_f(MyComplex_f *inData, uint8_t *outData, Modulation modulation)
{
switch (modulation) {
case BPSK:
demodulationBPSK_f(inData, outData);
break;
case QPSK:
demodulationQPSK_f(inData, outData);
break;
case QAM16:
demodulationQAM16_f(inData, outData);
break;
case QAM64:
demodulationQAM64_f(inData, outData);
break;
case QAM256:
demodulationQAM256_f(inData, outData);
break;
default:
break;
}
}
void demodulationBPSK_f(MyComplex_f *inData, uint8_t *outData)//+
{
outData[0] = 0;
for(int i = 0; i < 8; i++)
{
if(inData[i].real > 0)
outData[0] |= 1 << i;
}
}
void demodulationQPSK_f(MyComplex_f *inData, uint8_t *outData)//+
{
outData[0] = 0;
outData[1] = 0;
for(int i = 0; i < 4; i++)
{
if(inData[i].real > 0)
outData[0] |= 1 << (i*2);
if(inData[i].image > 0)
outData[0] |= 1 << (i*2+1);
if(inData[i+4].real > 0)
outData[1] |= 1 << (i*2);
if(inData[i+4].image > 0)
outData[1] |= 1 << (i*2+1);
}
}
inline uint8_t demap16(float inData)
{
//TODO MAP
if(inData < DMP_QAM16__3)
return 0b00;
if(inData < DMP_QAM16__1)
return 0b01;
if(inData < DMP_QAM16_1)
return 0b11;
return 0b10;
}
void demodulationQAM16_f(MyComplex_f *inData, uint8_t *outData)//+
{
outData[0] = 0;
outData[1] = 0;
outData[2] = 0;
outData[3] = 0;
for(int i = 0; i < 2; i++)
{
outData[0] |= demap16(inData[i].real) << 4*i;
outData[0] |= demap16(inData[i].image) << (4*i + 2);
outData[1] |= demap16(inData[i+2].real) << 4*i;
outData[1] |= demap16(inData[i+2].image) << (4*i + 2);
outData[2] |= demap16(inData[i+4].real) << 4*i;
outData[2] |= demap16(inData[i+4].image) << (4*i + 2);
outData[3] |= demap16(inData[i+6].real) << 4*i;
outData[3] |= demap16(inData[i+6].image) << (4*i + 2);
}
}
inline uint8_t demap64(float inData)
{
//TODO MAP
if(inData < DMP_QAM64__7)
return 0b000;
if(inData < DMP_QAM64__5)
return 0b001;
if(inData < DMP_QAM64__3)
return 0b011;
if(inData < DMP_QAM64__1)
return 0b010;
if(inData < DMP_QAM64_1)
return 0b110;
if(inData < DMP_QAM64_3)
return 0b111;
if(inData < DMP_QAM64_5)
return 0b101;
return 0b100;
}
void demodulationQAM64_f(MyComplex_f *inData, uint8_t *outData)//+
{
uint32_t dataTmp;
for(int i = 0; i < 2; i++)
{
dataTmp = 0;
dataTmp |= demap64(inData[i*4].real) << 0;
dataTmp |= demap64(inData[i*4].image) << 3;
dataTmp |= demap64(inData[i*4+1].real) << 6;
dataTmp |= demap64(inData[i*4+1].image) << 9;
dataTmp |= demap64(inData[i*4+2].real) << 12;
dataTmp |= demap64(inData[i*4+2].image) << 15;
dataTmp |= demap64(inData[i*4+3].real) << 18;
dataTmp |= demap64(inData[i*4+3].image) << 21;
outData[i*3+0] = dataTmp & 0xFF;
outData[i*3+1] = (dataTmp >> 8) & 0xFF;
outData[i*3+2] = (dataTmp >> 16) & 0xFF;
}
}
inline uint8_t demap256(float inData)
{
//TODO MAP
if(inData < DMP_QAM256__15)
return 0b0001;
if(inData < DMP_QAM256__13)
return 0b0101;
if(inData < DMP_QAM256__11)
return 0b0111;
if(inData < DMP_QAM256__9)
return 0b0011;
if(inData < DMP_QAM256__7)
return 0b0010;
if(inData < DMP_QAM256__5)
return 0b0110;
if(inData < DMP_QAM256__3)
return 0b0100;
if(inData < DMP_QAM256__1)
return 0b0000;
if(inData < DMP_QAM256_1)
return 0b1000;
if(inData < DMP_QAM256_3)
return 0b1100;
if(inData < DMP_QAM256_5)
return 0b1110;
if(inData < DMP_QAM256_7)
return 0b1010;
if(inData < DMP_QAM256_9)
return 0b1011;
if(inData < DMP_QAM256_11)
return 0b1111;
if(inData < DMP_QAM256_13)
return 0b1101;
return 0b1001;
}
void demodulationQAM256_f(MyComplex_f *inData, uint8_t *outData)//+
{
for(int i = 0; i < 8; i++)
{
outData[i] = (demap256(inData[i].image) << 4) | demap256(inData[i].real);
}
}