-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQAM_slicer.m
62 lines (59 loc) · 2.88 KB
/
QAM_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
% QAM_slicer.m
function [sliced_symbolseq] = QAM_slicer(symbolseq,Nb)
if Nb==2, sliced_symbolseq=QAM4_slicer(symbolseq);
elseif Nb==4, sliced_symbolseq=QAM16_slicer(symbolseq);
elseif Nb==6, sliced_symbolseq=QAM64_slicer(symbolseq);
else disp('When you need M-QAM modulation, you need to provide log2(M) as the 2nd argument');
end
function [sliced_symbolseq] = QAM4_slicer(symbolseq)
j=sqrt(-1);
symbolseq_length=length(symbolseq);
sliced_symbolseq=zeros(1,symbolseq_length);
for ii=1:symbolseq_length
real_part=real(symbolseq(ii));
imag_part=imag(symbolseq(ii));
if (real_part>0)&&(imag_part>0), sliced_symbolseq(ii)= (1+j)/sqrt(2.);
elseif (real_part<0)&&(imag_part>0), sliced_symbolseq(ii)= (-1+j)/sqrt(2.);
elseif (real_part<0)&&(imag_part<0), sliced_symbolseq(ii)=(-1-j)/sqrt(2.);
elseif (real_part>0)&&(imag_part<0), sliced_symbolseq(ii)=(1-j)/sqrt(2.); end
end
function [sliced_symbolseq] =QAM16_slicer(symbolseq)
j=sqrt(-1);
symbolseq_length = length(symbolseq);
for ii=1:symbolseq_length
real_part=real(symbolseq(ii));
imag_part=imag(symbolseq(ii));
if real_part<-2./sqrt(10.), real_hat=-3./sqrt(10.);
elseif (-2./sqrt(10.)<=real_part)&&(real_part<0), real_hat=-1./sqrt(10.);
elseif (0<=real_part)&&(real_part<2./sqrt(10.)), real_hat=1./sqrt(10.);
elseif 2./sqrt(10.)<=real_part, real_hat=3./sqrt(10.); end
if imag_part<-2./sqrt(10.), imag_hat=-3./sqrt(10.);
elseif (-2./sqrt(10.)<=imag_part)&&(imag_part<0), imag_hat=-1./sqrt(10.);
elseif (0<=imag_part)&&(imag_part<2./sqrt(10.)), imag_hat=1./sqrt(10.);
elseif 2./sqrt(10.)<=imag_part, imag_hat=3./sqrt(10.); end
sliced_symbolseq(ii)=real_hat+j*imag_hat;
end
function [sliced_symbolseq]=QAM64_slicer(symbolseq)
j=sqrt(-1);
symbolseq_length = length(symbolseq);
for ii = 1: symbolseq_length
real_part = real(symbolseq(ii));
imag_part = imag(symbolseq(ii));
if(real_part < -6/sqrt(42.)), real_hat = -7/sqrt(42.);
elseif(real_part < -4/sqrt(42.)), real_hat = -5/sqrt(42.);
elseif(real_part < -2/sqrt(42.)), real_hat = -3/sqrt(42.);
elseif(real_part < 0/sqrt(42.)), real_hat = -1/sqrt(42.);
elseif(real_part < 2/sqrt(42.)), real_hat = 1/sqrt(42.);
elseif(real_part < 4/sqrt(42.)), real_hat = 3/sqrt(42.);
elseif(real_part < 6/sqrt(42.)), real_hat = 5/sqrt(42.);
elseif(real_part >= 6/sqrt(42.)), real_hat = 7/sqrt(42.); end
if(imag_part < -6/sqrt(42.)), imag_hat = -7j/sqrt(42.);
elseif(imag_part < -4/sqrt(42.)), imag_hat = -5j/sqrt(42.);
elseif(imag_part < -2/sqrt(42.)), imag_hat = -3j/sqrt(42.);
elseif(imag_part < 0/sqrt(42.)), imag_hat = -j/sqrt(42.);
elseif(imag_part < 2/sqrt(42.)), imag_hat = j/sqrt(42.);
elseif(imag_part < 4/sqrt(42.)), imag_hat = 3j/sqrt(42.);
elseif(imag_part < 6/sqrt(42.)), imag_hat = 5j/sqrt(42.);
elseif(imag_part >= 6/sqrt(42.)), imag_hat = 7j/sqrt(42.); end
sliced_symbolseq(ii) = real_hat + imag_hat;
end