-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviterbi_decoder.m
More file actions
53 lines (38 loc) · 1.08 KB
/
viterbi_decoder.m
File metadata and controls
53 lines (38 loc) · 1.08 KB
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
function [ ue ] = viterbi_decoder( v, state_table, s, U)
%VITERBI_DECODER Summary of this function goes here
% Detailed explanation goes here
%% matriz de custo e de posição
C = Inf(2^s, U +1);
P = zeros(2^s, U +1);
R = zeros(2^s, U +1);
C(1,1) = 0;
%%
for i = 1:U
partition = v((3*i-2):(3*i));
for j = 1:2^s
for k = [0 1]
next_j = next_state(k, j, s);
aux = C(j, i) + hamming_weight( partition, de2bi(state_table(j ,1+k), 3, 'left-msb') );
if C(next_j, i+1) > aux
C(next_j, i+1) = aux;
P(next_j, i+1) = j;
R(next_j, i+1) = k;
end
end
end
end
%%
min = Inf;
min_j = 0;
for j = 1:2^s
if C(j, U +1) < min;
min = C(j, U +1);
min_j = j;
end
end
ue = zeros(1, U);
for i = (U+1):-1:2
ue(i-1) = R(min_j, i);
min_j = P(min_j, i);
end
end