Professional Documents
Culture Documents
EE113D Project
Authors: Imran Hoque Yipeng Li Diwei Zhang
Compression technique
Represents data using value and run length Run length defined as number of consecutive equal values e.g
1110011111
RLE
130215
Values Run Lengths
Introduction - Applications
Very simple compared with other compression techniques Reversible (Lossless) compression
decompression is just as easy
Introduction - Applications
Introduction
Compression effectiveness depends on input Must have consecutive runs of values in order to maximize compression
Best case: all values same
Can represent any length using two values Compressed data twice the length of original!!
Should only be used in situations where we know for sure have repeating values
Encoder - Algorithm
Keep a counter of consecutive values Keep examining the next value until a different value or end of input then output the value followed by the counter. Repeat
if length > 1 % Add last value and run length to output encoded = [encoded input(i) run_length]; else % Special case if input is of length 1 encoded = [input(1) 1]; end
ans = 0 1 1 7
1 1
1 8
2 1
1 9
3 1
Encoder
Immediate Problem
Output size not known until run-time (depends on input size as well as input pattern)
Encoder
Solution
Limit user input to preset length (16) Initialize output to worst case (double input length 32) Initialize output to all -1s (were only handling positive numbers and 0 as inputs) Output ends when -1 first appears or if length of output equals to worst case
;AR5 represents the actual number stored ;in the memory address AR3 points to ;(the actual number represented in the input) ;AR0 represents the actual number stored ;in the memory address AR6 points to ;AR4 points to the output data location ;AR2 keeps track of how much of the input ;data has been read ;loop1 initializes the count of AR1 to '1'
loop1
AR1 = #count1
;Register AR1 is used to keep track of the ;number of repeated inputs in succession ;loop2 reads through the input data, and keeps ;track of the number of consecutive inputs
;Compares the number stored in AR5 with the ;number stored in AR0 ;Increment the pointer AR6 ;Increment the pointer AR3
Best Case: Input: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Output: 0,16,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 Worst Case: Input: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 Output: 0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10,1,11,1,12,1,13,1,14,1,15,1
A = *AR6+ A = *AR6+ A = *AR3+ A = *AR3+ ;Increment twice to get the count of that number A = *AR3 AR5 = A ;Re-initialize AR5 if (*AR2- != 0) goto loop2 ;Stop encoder if count of AR2 reaches zero goto stop ;loop3 stores the decoded output, by expanding the number of repeated inputs loop3 A = *AR6 *AR4+ = A goto loop2 stop nop goto stop .end ;Add the repeated number to output
;infinite loop
Conclusion
Results obtained from DSP match theoretical results as well as Matlab results
Limitations:
Does not handle negative numbers Input to encoder limited to 16 numbers in this implementation
Future Improvements
Variable input lengths Allocate memory for output real-time