Department of Electrical Engineering Graduate Program (Ph.D.)
Project # 1:
Lempel-Ziv Source Decoding (Encoder and Decoder)
By: Anas (M.A.) Ata Salhab. (ID #: g200805780)
Submitted to: Dr. Samir Alghdhban.
Course Name: Information Theory (EE 575).
Date Delivered: 7 April, 2010.
Information Theory (EE 575) Project # 1 Lempel-Ziv Source Decoding (Encoder and Decoder) MATLAB Algorithm
1. Code Description: The MATLAB code can be divided into two main parts: the encoder and the decoder. In next subsections we explain each of them in a full manner.
1.1 System Encoder:
The system encoder can be explained as follows:
1. Input data: it is assigned to input the symbols that need to be encoded. We consider the binary case, where the source emits binary symbols. We put them in a vector called x1. The basic elements {0, 1} are then put in a new vector called x2. So, it includes M = 2 elements.
2. Initialization: The aim of this part is to initialize the encoder. It consists of initializing both the location pointer n to be 0 and the address pointer m to be M+1 which is 3 (the address of the blank location in the dictionary). We generated a zeros matrix of dimensions (M+1)*3 which is 3*3. This matrix will be used to build the root dictionary in next part.
3. Root Dictionary: In this part, we made two for loops to build the root dictionary. As we know, the root dictionary includes the address pointer in the first column and the dictionary entry in the second column as a pair <n, symbol=a>. The first row in the root dictionary contains the pair <0, null>. I chose the null element to be 0.
4. Encoding Process: in this part, we perform the encoding process and construct the encoder dictionary. We have the following steps: We first construct a zeros matrix with dimensions = (number of symbols in x1)*7. This matrix includes the results of the encoder operations. The encoding process is done in one for loop. We constructed a pair representing the entry pair of the dictionary <n, a>, where n = 0 and a is the first symbol in the emitted data (vector x1). Then, we use the if statement to check if this pair is an already existed member in the root dictionary or not. If yes, give n the value of the address of that pair and transmit nothing, else: - Transmit the value of present n and add a new pair to the root dictionary which is <n, a>. - If the new pair is <n, 0>, give n a new value which is the address value of the pair <0, 0> which is 1. If the new pair is <n, 1>, give n a new value which is the address value of the pair <0, 1> which is 2.
Continue with this until you construct the full encoder dictionary.
1.2 System Decoder:
The system decoder can be explained as follows:
The decoding operations are performed in a detailed for loop. In this part, we work on the received code word which is n. We compare it with 2: 1. If it is equal to 1, it means we are in the root dictionary. So, the decoded symbol will be the symbol in the entry pair that corresponds to the address 1. 2. If is equal to 2, it means also that we are in the root dictionary and thus the decoded symbol will be the symbol in the entry pair that corresponds to the address 2. If the received code word is larger than 2: 1. We go to the pair in the dictionary that is corresponding to that code word. 2. Then, we construct a new column in the decoder dictionary. This column includes the pair that is corresponding to the address which is the received code word. 3. Now, we again check if the first element in this pair is smaller than or equal to 2. If it is smaller than or equal to 2, then, we re-perform the same two steps done in the previous point. If not, we go again to step 2 in this point and continue until we recover all the decoded symbols.
2. Flowchart: The flowchart of the encoder is shown below:
Emitted Symbol a Transmit n Is <n, a> in the root dictionary? Make n = address of the pair <n, a> Yes No - Initialize with n=0 and m = M+1. - Build the root dictionary. Add <n, a> to the dictionary
Increment m
Is a = 0?
Make n = 2 Make n =1 Go to Next Symbol Code Word Go to Next Symbol The flowchart of the decoder is shown below:
Is Rx smaller than or = 2? x Code Word R Make n = Rx Decoded symbol = the symbol in the pair related to the address 2 Go to the pair at the address which = Rx Yes No Does it = 1?
Decoded symbol = the symbol in the pair related to the address 1 Yes No Is the 1 st element of the pair smaller than or = 2?
Go to the pair at the address which = the 1 st element in the last pair Does it = 1?
- 1 st decoded symbol = the sym. in the pair related to the address 2. - 2 nd decoded symbol = the sym. in the pair related to the address = 1 st
element in the pair. Yes No Yes - 1 st decoded symbol = the sym. in the pair related to the address 1. - 2 nd decoded symbol = the sym. in the pair related to the address = the 1 st
element in the pair. No Keep on doing this comparison until you reach the root dictionary