Run Length Encoder/Decoder EE113D Project Authors: Imran Hoque Yipeng Li Yipeng Li Diwei Zhang Diwei Zhang.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Introduction to Computer Science 2 Lecture 7: Extended binary trees
Multidimensional Data Rtrees Bitmap indexes. R-Trees For “regions” (typically rectangles) but can represent points. Supports NN, “where­am­I” queries.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Introduction to Computing Science and Programming I
© 2004 Goodrich, Tamassia Hash Tables1  
Designing Algorithms Csci 107 Lecture 4. Outline Last time Computing 1+2+…+n Adding 2 n-digit numbers Today: More algorithms Sequential search Variations.
CS0007: Introduction to Computer Programming Array Algorithms.
Procedures of Extending the Alphabet for the PPM Algorithm Radu Rădescu George Liculescu Polytechnic University of Bucharest Faculty of Electronics, Telecommunications.
BTrees & Bitmap Indexes
CPSC 231 Organizing Files for Performance (D.H.) 1 LEARNING OBJECTIVES Data compression. Reclaiming space in files. Compaction. Searching. Sorting, Keysorting.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
Efficiency of Algorithms
CSCI 3 Chapter 1.8 Data Compression. Chapter 1.8 Data Compression  For the purpose of storing or transferring data, it is often helpful to reduce the.
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Chapter 3: Arrays, Linked Lists, and Recursion
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Spring 2015 Mathematics in Management Science Binary Linear Codes Two Examples.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Comparing AlgorithmsCSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Complexity Reading: Kolman, Sections 4.6, 5.2, and 5.3.
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
1. Definition and General Structure 2. Small Example 1 3. Simplified Structure 4. Short Additional Examples 5. Full Example 2 6. Common Error The for loop.
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Pointers OVERVIEW.
Lossless Compression CIS 465 Multimedia. Compression Compression: the process of coding that will effectively reduce the total number of bits needed to.
CSC 211 Data Structures Lecture 13
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Execution of an instruction
read and learn from example loop programs develop modular program
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
CS654: Digital Image Analysis Lecture 34: Different Coding Techniques.
Cross-Product Packet Classification in GNIFS based on Non-overlapping Areas and Equivalence Class Author: Mohua Zhang, Ge Li Publisher: AISS 2012 Presenter:
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
ENTROPY & RUN LENGTH CODING. Contents What is Entropy coding? Huffman Encoding Huffman encoding Example Arithmetic coding Encoding Algorithms for arithmetic.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
Compression and Huffman Coding. Compression Reducing the memory required to store some information. Lossless compression vs lossy compression Lossless.
IS502:M ULTIMEDIA D ESIGN FOR I NFORMATION S YSTEM M ULTIMEDIA OF D ATA C OMPRESSION Presenter Name: Mahmood A.Moneim Supervised By: Prof. Hesham A.Hefny.
CS 116 Object Oriented Programming II Lecture 13 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
1 SWE 423 – Multimedia System. 2 SWE Multimedia System Introduction  Compression is the process of coding that will effectively reduce the total.
Selection Using IF THEN ELSE CASE Introducing Loops.
LINKED LISTS.
Windows Programming Lecture 03. Pointers and Arrays.
BIT116: Scripting Loops.
Chapter 5: Control Structures II
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
A First Book of ANSI C Fourth Edition
Java Programming Arrays
Coding Concepts (Basics)
Image Coding and Compression
Number Systems Instructions, Compression & Truth Tables.
CPS125 Week
Presentation transcript:

Run Length Encoder/Decoder EE113D Project Authors: Imran Hoque Yipeng Li Yipeng Li Diwei Zhang Diwei Zhang

Introduction – What is RLE? Compression technique Compression technique Represents data using value and run lengthRepresents data using value and run length Run length defined as number of consecutive equal valuesRun length defined as number of consecutive equal valuese.g RLE ValuesRun Lengths

Introduction - Applications Useful for compressing data that contains repeated values Useful for compressing data that contains repeated values e.g. output from a filter, many consecutive values are 0.e.g. output from a filter, many consecutive values are 0. Very simple compared with other compression techniques Very simple compared with other compression techniques Reversible (Lossless) compression Reversible (Lossless) compression decompression is just as easydecompression is just as easy

Introduction - Applications Image Compression – JPEG Image Compression – JPEG Run Length Encoder!

Introduction Compression effectiveness depends on input Compression effectiveness depends on input Must have consecutive runs of values in order to maximize compression Must have consecutive runs of values in order to maximize compression Best case: all values sameBest case: all values same Can represent any length using two values Can represent any length using two values Worst case: no repeating valuesWorst case: no repeating values Compressed data twice the length of original!! Compressed data twice the length of original!! Should only be used in situations where we know for sure have repeating values Should only be used in situations where we know for sure have repeating values

Encoder - Algorithm Start on the first element of input Start on the first element of input Examine next value Examine next value If same as previous valueIf same as previous value Keep a counter of consecutive values 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 Keep examining the next value until a different value or end of input then output the value followed by the counter. Repeat If not same as previous valueIf not same as previous value Output the previous value followed by ‘1’ (run length. Repeat Output the previous value followed by ‘1’ (run length. Repeat

Encoder – Matlab Code % Run Length Encoder % EE113D Project function encoded = RLE_encode(input) my_size = size(input); length = my_size(2); run_length = 1; encoded = []; for i=2:length if input(i) == input(i-1) run_length = run_length + 1; else encoded = [encoded input(i-1) run_length]; run_length = 1; end 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

Encoder – Matlab Results >> RLE_encode([ ]) ans = >> RLE_encode([ ]) ans = >> RLE_encode([ ]) ans =

Encoder Input from separate.asm file Input from separate.asm file In the form of a vectorIn the form of a vector e.g. ‘array.word 4,5,5,2,7,3,6,9,9,10,10,10,10,10,10,0,0’e.g. ‘array.word 4,5,5,2,7,3,6,9,9,10,10,10,10,10,10,0,0’ Output is declared as data memory space Output is declared as data memory space Examine memory to get outputExamine memory to get output Originally declared to be all -1.Originally declared to be all -1. Immediate Problem Immediate Problem Output size not known until run-time (depends on input size as well as input pattern)Output size not known until run-time (depends on input size as well as input pattern) Cannot initialize variable size array Cannot initialize variable size array

Encoder Solution Solution Limit user input to preset length (16)Limit user input to preset length (16) Initialize output to worst case (double input length – 32)Initialize output to worst case (double input length – 32) Initialize output to all -1’s (we’re only handling positive numbers and 0 as inputs)Initialize output to all -1’s (we’re only handling positive numbers and 0 as inputs) Output ends when -1 first appears or if length of output equals to worst caseOutput ends when -1 first appears or if length of output equals to worst case

Encoder – DSP Code ;******************************************************************* ;EE113D Final Project(encoder) ; ;Run Length Encoder: Shortens a series of input data by representing ;consecutive repeated numbers as the repeated number, followed by ;the number of repetitions. ; ;(Written by: Yi-peng Li, Diwei Zhang, Imran Hoque) ;.setsect ".text", 0x500,0 ;Executible code in ".text".setsect ".text", 0x500,0 ;Executible code in ".text" ;section will begin at 0x500 ;section will begin at 0x500 ;in program memory ;in program memory.setsect ".data", 0x800,1 ;Numbers to be sorted will.setsect ".data", 0x800,1 ;Numbers to be sorted will ;begin at 0x800 in data memory ;begin at 0x800 in data memory.data ;Data section begins.data ;Data section begins.copy "e_inputs.asm";Reads input values and initialize output.text ;Executible code section begins..text ;Executible code section begins. count1.set 1;Initialize a counter starting at the number 1 count2.set 15;Initialize a counter starting at the number 15

Encoder – DSP Code AR6 = #array ;AR6 points to the input data location AR3 = #array ;AR3 points to the next input data location AR3 = #array ;AR3 points to the next input data location A = *AR3+ A = *AR3 AR5 = A;AR5 represents the actual number stored ;in the memory address AR3 points to ;(the actual number represented in the input) A = *AR6 AR0 = A;AR0 represents the actual number stored ;in the memory address AR6 points to AR4 = #output;AR4 points to the output data location AR2 = #count2;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 loop2 TC = (AR0 != AR5);Compares the number stored in AR5 with the ;number stored in AR0 A = *AR6+;Increment the pointer AR6 A = *AR3+;Increment the pointer AR3

Encoder – DSP Code A = *AR3 AR5 = A;Re-initialize AR5 A = *AR6 AR0 = A;Re-initialize AR0 if (TC) goto loop3;Break loop if next number different A = *AR1+;else continue counting if (*AR2- != 0) goto loop2 ;Stop encoder if count of AR2 reaches zero A = *AR2+;Leave count of AR2 at zero ;loop3 stores the encoded input, followed by ;its repeated count into the output array loop3A = *AR6-;Point back to the last repeated number A = *AR6 *AR4+ = A;Add the repeated number to output A = AR1 *AR4+ = A;Add the count of repeated number to output A = *AR6+;Move pointer back to where it left off if (*AR2- != 0) goto loop1;Stop encoder if count of AR2 reaches zero stop nop goto stop ;infinite loop goto stop ;infinite loop.end.end

Encoder – DSP Results Input: 4,5,5,2,7,3,6,9,9,10,10,10,10,10,10,0,0 Output: 4,1,5,2,2,1,7,1,3,1,6,1,9,2,10,6,0,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1… 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 Valid OutputOutput Ends Here

Decoder – Matlab Code % Run Length Decoder % EE113D Project % The input to this function should be the output from Run Length Encoder, % which means it assumes even number of elements in the input. The first % element is a value followed by the run count. Thus all odd elements in % the input are assumed the values and even elements the run counts. % function decoded = RLE_decode(encoded) my_size = size(encoded); length = my_size(2); index = 1; decoded = []; % iterate through the input while (index <= length) % get value which is followed by the run count value = encoded(index); run_length = encoded(index + 1); for i=1:run_length % loop adding 'value' to output 'run_length' times decoded = [decoded value]; end % put index at next value element (odd element) index = index + 2; end

Decoder – Matlab Results >> RLE_decode([0 12]) ans = >> RLE_decode([ ]) ans = >> RLE_decode(RLE_encode([ ])) ans =

Decoder – DSP Code ;******************************************************************* ;EE113D Final Project(decoder) ; ;Run Length Encoder: Takes as its input, a string of data encoded ;according the the run length encoder algorithm, and outputs it ;as the decoded string of data originally input to the encoder. ;(Written by: Yi-peng Li, Diwei Zhang, Imran Hoque).setsect ".text", 0x500,0 ;Executible code in ".text“ section will begin at 0x500.setsect ".text", 0x500,0 ;Executible code in ".text“ section will begin at 0x500 ;in program memory ;in program memory.setsect ".data", 0x800,1 ;Numbers to be sorted will begin at 0x800 in data memory.setsect ".data", 0x800,1 ;Numbers to be sorted will begin at 0x800 in data memory.data ;Data section begins.copy "d_inputs.asm";Get input values and initialze outputs.text ;Executible code section begins..text ;Executible code section begins. count2.set 14;Initialize a counter starting at the number 14 AR6 = #array ;AR6 points to the input data location AR3 = #array ;AR3 points to the next input data location A = *AR3+ A = *AR3 AR5 = A;AR5 keeps track of the number of repetitions

Decoder – DSP Code AR4 = #output;AR4 points to the output data location AR2 = #count2;AR0 keeps track of how much of the input ;data has been read ;loop2 reads through the input data to the decoder loop2if (*AR5- != 0) goto loop3;Keep outputting the current input number until ;the following count of that number reaches zero A = *AR6+;Else continue reading thru input A = *AR6+;Increment twice to get next number in output 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 loop3A = *AR6 *AR4+ = A;Add the repeated number to output goto loop2 stop nop goto stop ;infinite loop goto stop ;infinite loop.end.end

Decoder – DSP Results Input: 0,16 Output: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Input: 1,5,0,11 Output: 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0

Conclusion Results obtained from DSP match theoretical results as well as Matlab results Results obtained from DSP match theoretical results as well as Matlab results Limitations: Limitations: Does not handle negative numbersDoes not handle negative numbers Input to encoder limited to 16 numbers in this implementationInput to encoder limited to 16 numbers in this implementation Future Improvements Future Improvements Variable input lengthsVariable input lengths Allocate memory for output real-timeAllocate memory for output real-time