forked from dario-pilori/dsp-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harddec.m
32 lines (30 loc) · 976 Bytes
/
harddec.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
function d = harddec(x,Mc)
%HARDDEC Square QAM hard decision
% This function applies hard-decision to the received signal x.
%
% INPUTS:
% x := Array of symbols (column vectors)
% Mc := Constellation bits/symb
%
% OUTPUTS
% d := Hard-decision symbols
% Apr. 2016 - Dario Pilori <dario.pilori@polito.it>
switch Mc
case 2
d = sign(real(x))+1j*sign(imag(x));
case 4
d = 2*(sign(real(x))+1j*sign(imag(x)));
d = d+sign(real(x-d))+1j*sign(imag(x-d));
case 6
d = 4*(sign(real(x))+1j*sign(imag(x)));
d = d+2*(sign(real(x-d))+1j*sign(imag(x-d)));
d = d+sign(real(x-d))+1j*sign(imag(x-d));
case 8
d = 8*(sign(real(x))+1j*sign(imag(x)));
d = d+4*(sign(real(x-d))+1j*sign(imag(x-d)));
d = d+2*(sign(real(x-d))+1j*sign(imag(x-d)));
d = d+sign(real(x-d))+1j*sign(imag(x-d));
otherwise
error('Constellation not supported');
end
end