akocius

Untitled

Dec 6th, 2021
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %% RLE kodu užkoduotos Delta vertės
  2. clear all
  3. clc
  4. load('Temperature.mat');
  5.  
  6. %Delta užkodavimas
  7. deltaTemp(1) = Temperature(1);
  8.  
  9. for i = 2:length(Temperature)
  10.     deltaTemp(i) = Temperature(i) - Temperature(i-1);
  11. end
  12.  
  13. %RLE kodavimas
  14. j = 1;
  15. i = 1;
  16. while i <= length(deltaTemp)
  17.     val = deltaTemp(i);
  18.     rleEncodedTemp(j) = val;
  19.     repeat = 1;
  20.    
  21.     while i < length(deltaTemp) && val == deltaTemp(i + 1)
  22.         repeat = repeat + 1;
  23.         i = i + 1;
  24.     end
  25.    
  26.     %Kitu elementu masyve įrašomas pasikartojimų skaičius
  27.     j = j + 1;
  28.     rleEncodedTemp(j) = repeat;
  29.  
  30.     j = j + 1;
  31.     i = i + 1;
  32. end
  33.  
  34. %Užkoduotos Delta sekos dydis bitais
  35. firstValueSize = length(dec2bin(deltaTemp(1)));
  36. differenceValuesSize = length(dec2bin(max(deltaTemp(2:end)) - min(deltaTemp(2:end))));
  37. deltaEncodedSize = differenceValuesSize * (length(Temperature) - 1) + firstValueSize;
  38.  
  39. %RLE - delta kodo dydis bitais
  40. rleFirstValSize = length(dec2bin(rleEncodedTemp(1)))
  41.  
  42. maxEncodedValue = max(rleEncodedTemp(3:2:end));
  43. minEncodedValue = min(rleEncodedTemp(3:2:end));
  44. if minEncodedValue < 0
  45.     encodedValueLength = length(dec2bin(maxEncodedValue - minEncodedValue));
  46. else
  47.     encodedValueLength = length(dec2bin(maxEncodedValue));
  48. end
  49.  
  50. maxEncodedRepetition = max(rleEncodedTemp(2:2:end));
  51. repetitionLength = length(dec2bin(maxEncodedRepetition));
  52.  
  53. %Užkoduotos RLE koduote sekos dydis bitais
  54. sizeEncodedRle = ((encodedValueLength + repetitionLength) * (length(rleEncodedTemp) / 2)) + rleFirstValSize;
  55.  
  56. %Duomenų dydžio sumažėjimas
  57. deltaEncodedSize
  58. sizeEncodedRle
  59. compression = sizeEncodedRle / deltaEncodedSize
RAW Paste Data