1 sem octave lab 5

This commit is contained in:
Andrew 2019-12-01 15:44:42 +07:00
parent 018bac4688
commit df67329dea
2 changed files with 6 additions and 10 deletions

View file

@ -8,15 +8,11 @@ function [b,n] = calc_info(msg, alph, alph_p)
b = 0; b = 0;
for i = 1:l_msg for i = 1:l_msg
flag = false; mask = alph == msg(i);
for j = 1:l_alph if any(mask)
if msg(i) == alph(j) comp = alph_p(mask);
flag = true; b -= log2(comp);
b -= log(alph_p(j)); else
break
endif
endfor
if ~flag
warning("[WARN] Symbol '%s' (at pos. %d from msg) not found in alphabet", msg(i), i) warning("[WARN] Symbol '%s' (at pos. %d from msg) not found in alphabet", msg(i), i)
endif endif
endfor endfor

View file

@ -17,7 +17,7 @@ msg = gen_msg(ralph, 100);
dlmwrite("msg.txt", msg, ''); dlmwrite("msg.txt", msg, '');
#stage 7 #stage 7
[b, n] = calc_info(msg, alph, ralph); [b, n] = calc_info(msg, alph, ralph)
#stage 8 #stage 8
avg_b = b / length(msg); avg_b = b / length(msg);