-
Notifications
You must be signed in to change notification settings - Fork 0
/
QAM_2_3_CC_Viterbi_Decoder_Rayleigh.m~
73 lines (56 loc) · 1.81 KB
/
QAM_2_3_CC_Viterbi_Decoder_Rayleigh.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
%% 16 QAM Viterbi decoder && 2/3 Convolutional enconding && Rayleigh
% Author: Marcus Vinicius Bunn
% date: 28/04/2017
clc; clear all;
N = 100e3;
k = 2;
n = 3;
codeRate = k/n;
info = randi([0 1], N*k, 1);
% Trellis
% If the encoder diagram has k inputs and n outputs, the code generator matrix is a k-by-n matrix.
% The element in the ith row and jth column
% indicates how the ith input contributes to the jth output.
% 3 = 1 input + 2 shift registers adding on that input
% 1 1 0 ones representing shift-register adders
% 1 1 1
% Deseja-se n = 4 e k =7.
%
% trellis = poly2trellis(7,[171 133]);
% tbl = 32;
trellis = poly2trellis([5 4],[23 35 0; 0 5 13]);
tbl=16;
delay = k*tbl;
% Convolutional enconding
codeword = convenc(info,trellis);
% Modulacao
M = 16;
K = log2(M);
modulated = qammod(codeword,M,'InputType','bit');
% Rayleigh Fading Channel
Ts = 1/100000;
fd = 130;
h = rayleighchan(Ts, fd);
h.StoreHistory=1;
txSig = filter(h,modulated);
channel_gains = h.PathGains;
EbNo= (-2:10)';
berSoft = zeros(size(EbNo));
berHard = zeros(size(EbNo));
for n = 1:length(EbNo)
snr = EbNo(n) + 10*log10(K*codeRate);
with_noise = awgn(txSig,snr,'measured');
rxSig = with_noise./channel_gains;
rxDataSoft = qamdemod(rxSig,M,'OutputType','approxllr','NoiseVariance',(10.^(snr/10))./(channel_gains)); % -1 = 1 + = 0.
rxDataHard = qamdemod(rxSig,M,'OutputType','bit');
dataSoft = vitdec(rxDataSoft,trellis,tbl,'cont','unquant');
dataHard = vitdec(rxDataHard,trellis,tbl,'cont','hard');
[~,berSoft(n)] = biterr(info(1:end-delay),dataSoft(delay+1:end));
[~,berHard(n)] = biterr(info(1:end-delay),dataHard(delay+1:end));
end
figure(2);
semilogy(EbNo,berSoft,EbNo,berHard);
title('16 QAM 2/3 CC Rayleigh')
ylabel('Pb')
xlabel('Eb/No')
legend('SDD','HDD');