-
Notifications
You must be signed in to change notification settings - Fork 0
/
QAM_2_3_CC_Viterbi_Decoder_AWGN_Random_Interleaved.m
98 lines (72 loc) · 2.98 KB
/
QAM_2_3_CC_Viterbi_Decoder_AWGN_Random_Interleaved.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
%% 16 QAM Viterbi decoder && 2/3 Convolutional enconding && Interleaver
% Author: Marcus Vinicius Bunn
% date: 03/05/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);
% interleaved
state = 4831;
interleaved = randintrlv(codeword,state);
% Modulacao
M = 16;
K = log2(M);
txSig = qammod(codeword,M,'InputType','bit');
%interleaved
txSigInterleaved = qammod(interleaved,M,'InputType','bit');
EbNo= -2:20;
berSoft = zeros(size(EbNo));
berHard = zeros(size(EbNo));
berSoftInterleaved = zeros(size(EbNo));
berHardInterleaved = zeros(size(EbNo));
for n = 1:length(EbNo)
%% without interleaving
snr = EbNo(n) + 10*log10(K*codeRate);
rxSig = awgn(txSig,snr,'measured');
rxDataSoft = qamdemod(rxSig,M,'OutputType','approxllr'); % -1 = 1 + = 0.
rxDataHard = qamdemod(rxSig,M,'OutputType','bit');
% 0 = the most confident 0 and 2^nsdec-1 = the most confident 1
% TO DO = func onde min(teste) = 0 e max(teste) = maximo_soft
% meio = peso/2 como quantizar ?
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));
%% with interleaving
rxSig = awgn(txSigInterleaved,snr,'measured');
rxDataSoft = qamdemod(rxSig,M,'OutputType','approxllr'); % -1 = 1 + = 0.
rxDataHard = qamdemod(rxSig,M,'OutputType','bit');
softDeinter = randdeintrlv(rxDataSoft,state); % Deinterleave.
hardDeinter = randdeintrlv(rxDataHard,state); % Deinterleave.
dataSoft = vitdec(softDeinter,trellis,tbl,'cont','unquant');
dataHard = vitdec(hardDeinter,trellis,tbl,'cont','hard');
[~,berSoftInterleaved(n)]= biterr(info(1:end-delay),dataSoft(delay+1:end));
[~,berHardInterleaved(n)]= biterr(info(1:end-delay),dataHard(delay+1:end));
end
figure(1)
semilogy(EbNo,berSoft,EbNo,berHard,EbNo,berSoftInterleaved,EbNo,berHardInterleaved);
title('16 QAM 2/3 CC AWGN and Interleaved')
ylabel('Pb')
xlabel('Eb/No')
legend('SDD','HDD','SDDint','HDDint');
% dataSoft = vitdec(rxDataSoft,trellis,tbl,'cont','unquant');
% Quantize to prepare for soft-decision decoding.
% qcode = quantiz(teste,[min(teste),min(teste)*peso/K,min(teste)*peso/(2*K),max(teste)/min(teste),max(teste)/(2*peso*K),max(teste)/(peso*K),max(teste)]);