-
Notifications
You must be signed in to change notification settings - Fork 0
/
QAM_2_3_CC_Viterbi_Decoder_AWGN.m
68 lines (52 loc) · 1.66 KB
/
QAM_2_3_CC_Viterbi_Decoder_AWGN.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
%% 16 QAM Viterbi decoder && 2/3 Convolutional enconding
% 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);
% Montando vetor para modulaçao
toMod = reshape(codeword,n,[]).';
txSig = qammod(codeword,M,'InputType','bit');
EbNo= -2:10;
berSoft = zeros(size(EbNo));
berHard = zeros(size(EbNo));
for n = 1:length(EbNo)
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');
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
ber = berawgn(EbNo,'qam',M);
figure(1)
semilogy(EbNo,berSoft,EbNo,berHard,EbNo,ber);
title('16 QAM 2/3 CC AWGN')
ylabel('Pb')
xlabel('Eb/No')
legend('SDD','HDD','Uncoded Ber');