-
Notifications
You must be signed in to change notification settings - Fork 10
/
slicer.m
191 lines (157 loc) · 3.54 KB
/
slicer.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
184
185
186
187
188
189
190
function rx_out = slicer(rx_in, mode)
%MAPPER Summary of this function goes here
% Detailed explanation goes here
N0 = 1; % No scaling, regular Viterbi decoding
type = 1; % 0 - exact, 1 - approximate
if mode==1,
% BPSK
rx_out = sign(real(rx_in)) * 1;
elseif mode==2,
% QPSK
rx_out = (sign(real(rx_in)) + 1i*sign(imag(rx_in))) / sqrt(2);
elseif mode==4,
% 16-QAM
rx_out = zeros(size(rx_in));
for k=1:length(rx_in),
re = real(rx_in(k)) * sqrt(10);
im = imag(rx_in(k)) * sqrt(10);
if re<-2,
re = -3;
elseif re<0,
re = -1;
elseif re<2,
re = 1;
else
re = 3;
end
if im<-2,
im = -3;
elseif im<0,
im = -1;
elseif im<2,
im = 1;
else
im = 3;
end
rx_out(k) = (re + 1i*im) / sqrt(10);
end
elseif mode==6,
% 64-QAM
rx_out = zeros(size(rx_in));
for k=1:length(rx_in),
re = real(rx_in(k)) * sqrt(42);
im = imag(rx_in(k)) * sqrt(42);
if re<-6,
re = -7;
elseif re<-4,
re = -5;
elseif re<-2,
re = -3;
elseif re<0
re = -1;
elseif re<2,
re = 1;
elseif re<4,
re = 3;
elseif re<6
re = 5;
else
re = 7;
end
if im<-6,
im = -7;
elseif im<-4,
im = -5;
elseif im<-2,
im = -3;
elseif im<0
im = -1;
elseif im<2,
im = 1;
elseif im<4,
im = 3;
elseif im<6
im = 5;
else
im = 7;
end
rx_out(k) = (re + 1i*im) / sqrt(42);
end
elseif mode==8,
% 256-QAM
rx_out = zeros(size(rx_in));
for k=1:length(rx_in),
re = real(rx_in(k)) * sqrt(170);
im = imag(rx_in(k)) * sqrt(170);
if re<-14,
re = -15;
elseif re<-12,
re = -13;
elseif re<-10,
re = -11;
elseif re<-8,
re = -9;
elseif re<-6,
re = -7;
elseif re<-4,
re = -5;
elseif re<-2,
re = -3;
elseif re<0,
re = -1;
elseif re<2,
re = 1;
elseif re<4,
re = 3;
elseif re<6,
re = 5;
elseif re<8,
re = 7;
elseif re<10,
re = 9;
elseif re<12,
re = 11;
elseif re<14,
re = 13;
else
re = 15;
end
if im<-14,
im = -15;
elseif im<-12,
im = -13;
elseif im<-10,
im = -11;
elseif im<-8,
im = -9;
elseif im<-6,
im = -7;
elseif im<-4,
im = -5;
elseif im<-2,
im = -3;
elseif im<0,
im = -1;
elseif im<2,
im = 1;
elseif im<4,
im = 3;
elseif im<6,
im = 5;
elseif im<8,
im = 7;
elseif im<10,
im = 9;
elseif im<12,
im = 11;
elseif im<14,
im = 13;
else
im = 15;
end
rx_out(k) = (re + 1i*im) / sqrt(170);
end
else
% wrong QAM mode
error('Wrong QAM-mode');
end