Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. napis = 'cabacabacabarrraaasddawkgaiikallwororoewiiieekisiikeaikgg#';
  5. [a,~,~] = unique(napis);
  6. for i = 1:length(a)
  7. prob(i) = length(findstr(a(i), napis));
  8. end
  9. prob = prob./sum(prob);
  10. [~,ind] = sort(prob,'descend');
  11. prob = prob(ind);
  12. a = a(ind);
  13. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  14. %prob = [0.45,0.3,0.2,0.05];
  15. %a = ['abc#'];
  16.  
  17. tab = zeros(length(prob),2);
  18. startValue = 0;
  19.  
  20. for i = 1:length(prob)
  21. tab(i,1) = startValue;
  22. tab(i,2) = sum(prob(1:i));
  23. startValue = tab(i,2);
  24. end
  25. tab2 = tab;
  26. tab_new = hpf(0,[15,0]);
  27. for i = 1:length(napis)
  28. indx = find(napis(i)==a);
  29. tab_new = hpf(tab(indx,:));
  30. p = tab_new(1);
  31. k = tab_new(2);
  32. for j = 1:length(prob)-1
  33. tab_new(end+1,2) = tab_new(end,2);
  34. tab_new(end-1,2) = (k-p)*sum(prob(1:j))+p;
  35. tab_new(end,1) = tab_new(end-1,2);
  36. end
  37. tab = tab_new;
  38. end
  39. %%%%%%%%%%%%%dekodowanie
  40. value = (tab(end,1) + tab(end,2))/2;
  41. tab = tab2;
  42. s = '0';
  43. wynik = [];
  44. while(s~='#')
  45. indx = find(tab(:,1)<value);
  46. indx = indx(end);
  47. s = a(indx);
  48. wynik = [wynik,s];
  49.  
  50. tab_new = hpf(tab(indx,:));
  51. p = tab_new(1);
  52. k = tab_new(2);
  53. for j = 1:length(prob)-1
  54. tab_new(end+1,2) = tab_new(end,2);
  55. tab_new(end-1,2) = (k-p)*sum(prob(1:j))+p;
  56. tab_new(end,1) = tab_new(end-1,2);
  57. end
  58. tab = tab_new;
  59. end
  60. napis
  61. wynik
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement