-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmapper.m
184 lines (167 loc) · 6.22 KB
/
mapper.m
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
180
181
182
183
function tx_out = mapper(data, mode)
%MAPPER Summary of this function goes here
% Detailed explanation goes here
if mode==1,
% BPSK
tx_out = 2*data - 1;
elseif mode==2,
% QPSK
tx_out = (2*data(1:2:end)-1) + 1i*(2*data(2:2:end)-1);
tx_out = tx_out*(1/sqrt(2));
elseif mode==4,
% 16-QAM
b0 = data(1:4:end);
b1 = data(2:4:end);
b2 = data(3:4:end);
b3 = data(4:4:end);
tx_out = zeros(1,length(data)/4);
for k=1:length(tx_out),
if b0(k)==0 && b1(k)==0,
tx_out(k) = -3;
elseif b0(k)==0 && b1(k)==1,
tx_out(k) = -1;
elseif b0(k)==1 && b1(k)==1,
tx_out(k) = 1;
elseif b0(k)==1 && b1(k)==0,
tx_out(k) = 3;
end
if b2(k)==0 && b3(k)==0,
tx_out(k) = tx_out(k) - 1i*(3);
elseif b2(k)==0 && b3(k)==1,
tx_out(k) = tx_out(k) - 1i*(1);
elseif b2(k)==1 && b3(k)==1,
tx_out(k) = tx_out(k) + 1i*(1);
elseif b2(k)==1 && b3(k)==0,
tx_out(k) = tx_out(k) + 1i*(3);
end
end
tx_out = tx_out * (1/sqrt(10));
elseif mode==6,
% 64-QAM
b0 = data(1:6:end);
b1 = data(2:6:end);
b2 = data(3:6:end);
b3 = data(4:6:end);
b4 = data(5:6:end);
b5 = data(6:6:end);
tx_out = zeros(1,length(data)/6);
for k=1:length(tx_out),
if b0(k)==0 && b1(k)==0 && b2(k)==0,
tx_out(k) = -7;
elseif b0(k)==0 && b1(k)==0 && b2(k)==1,
tx_out(k) = -5;
elseif b0(k)==0 && b1(k)==1 && b2(k)==1,
tx_out(k) = -3;
elseif b0(k)==0 && b1(k)==1 && b2(k)==0,
tx_out(k) = -1;
elseif b0(k)==1 && b1(k)==1 && b2(k)==0,
tx_out(k) = 1;
elseif b0(k)==1 && b1(k)==1 && b2(k)==1,
tx_out(k) = 3;
elseif b0(k)==1 && b1(k)==0 && b2(k)==1,
tx_out(k) = 5;
elseif b0(k)==1 && b1(k)==0 && b2(k)==0,
tx_out(k) = 7;
end
if b3(k)==0 && b4(k)==0 && b5(k)==0,
tx_out(k) = tx_out(k) - 1i*(7);
elseif b3(k)==0 && b4(k)==0 && b5(k)==1,
tx_out(k) = tx_out(k) - 1i*(5);
elseif b3(k)==0 && b4(k)==1 && b5(k)==1,
tx_out(k) = tx_out(k) - 1i*(3);
elseif b3(k)==0 && b4(k)==1 && b5(k)==0,
tx_out(k) = tx_out(k) - 1i*(1);
elseif b3(k)==1 && b4(k)==1 && b5(k)==0,
tx_out(k) = tx_out(k) + 1i*(1);
elseif b3(k)==1 && b4(k)==1 && b5(k)==1,
tx_out(k) = tx_out(k) + 1i*(3);
elseif b3(k)==1 && b4(k)==0 && b5(k)==1,
tx_out(k) = tx_out(k) + 1i*(5);
elseif b3(k)==1 && b4(k)==0 && b5(k)==0,
tx_out(k) = tx_out(k) + 1i*(7);
end
end
tx_out = tx_out * (1/sqrt(42));
elseif mode==8,
% 256-QAM
b0 = data(1:8:end);
b1 = data(2:8:end);
b2 = data(3:8:end);
b3 = data(4:8:end);
b4 = data(5:8:end);
b5 = data(6:8:end);
b6 = data(7:8:end);
b7 = data(8:8:end);
tx_out = zeros(1,length(data)/8);
for k=1:length(tx_out),
if b0(k)==0 && b1(k)==0 && b2(k)==0 && b3(k)==0,
tx_out(k) = -15;
elseif b0(k)==0 && b1(k)==0 && b2(k)==0 && b3(k)==1,
tx_out(k) = -13;
elseif b0(k)==0 && b1(k)==0 && b2(k)==1 && b3(k)==1,
tx_out(k) = -11;
elseif b0(k)==0 && b1(k)==0 && b2(k)==1 && b3(k)==0,
tx_out(k) = -9;
elseif b0(k)==0 && b1(k)==1 && b2(k)==1 && b3(k)==0,
tx_out(k) = -7;
elseif b0(k)==0 && b1(k)==1 && b2(k)==1 && b3(k)==1,
tx_out(k) = -5;
elseif b0(k)==0 && b1(k)==1 && b2(k)==0 && b3(k)==1,
tx_out(k) = -3;
elseif b0(k)==0 && b1(k)==1 && b2(k)==0 && b3(k)==0,
tx_out(k) = -1;
elseif b0(k)==1 && b1(k)==0 && b2(k)==0 && b3(k)==0,
tx_out(k) = 15;
elseif b0(k)==1 && b1(k)==0 && b2(k)==0 && b3(k)==1,
tx_out(k) = 13;
elseif b0(k)==1 && b1(k)==0 && b2(k)==1 && b3(k)==1,
tx_out(k) = 11;
elseif b0(k)==1 && b1(k)==0 && b2(k)==1 && b3(k)==0,
tx_out(k) = 9;
elseif b0(k)==1 && b1(k)==1 && b2(k)==1 && b3(k)==0,
tx_out(k) = 7;
elseif b0(k)==1 && b1(k)==1 && b2(k)==1 && b3(k)==1,
tx_out(k) = 5;
elseif b0(k)==1 && b1(k)==1 && b2(k)==0 && b3(k)==1,
tx_out(k) = 3;
elseif b0(k)==1 && b1(k)==1 && b2(k)==0 && b3(k)==0,
tx_out(k) = 1;
end
if b4(k)==0 && b5(k)==0 && b6(k)==0 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(-15);
elseif b4(k)==0 && b5(k)==0 && b6(k)==0 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(-13);
elseif b4(k)==0 && b5(k)==0 && b6(k)==1 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(-11);
elseif b4(k)==0 && b5(k)==0 && b6(k)==1 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(-9);
elseif b4(k)==0 && b5(k)==1 && b6(k)==1 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(-7);
elseif b4(k)==0 && b5(k)==1 && b6(k)==1 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(-5);
elseif b4(k)==0 && b5(k)==1 && b6(k)==0 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(-3);
elseif b4(k)==0 && b5(k)==1 && b6(k)==0 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(-1);
elseif b4(k)==1 && b5(k)==0 && b6(k)==0 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(15);
elseif b4(k)==1 && b5(k)==0 && b6(k)==0 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(13);
elseif b4(k)==1 && b5(k)==0 && b6(k)==1 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(11);
elseif b4(k)==1 && b5(k)==0 && b6(k)==1 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(9);
elseif b4(k)==1 && b5(k)==1 && b6(k)==1 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(7);
elseif b4(k)==1 && b5(k)==1 && b6(k)==1 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(5);
elseif b4(k)==1 && b5(k)==1 && b6(k)==0 && b7(k)==1,
tx_out(k) = tx_out(k) + 1i*(3);
elseif b4(k)==1 && b5(k)==1 && b6(k)==0 && b7(k)==0,
tx_out(k) = tx_out(k) + 1i*(1);
end
end
tx_out = tx_out * (1/sqrt(170));
else
% wrong QAM mode
end