Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Difference between revisions of "Exercise 2.12: Run–Length Coding and Run–Length Limited Coding"

From LNTwww
 
(5 intermediate revisions by 3 users not shown)
Line 6: Line 6:
 
We consider a binary source with the symbol set  A  and  B, where  B  however, occurs only very rarely.
 
We consider a binary source with the symbol set  A  and  B, where  B  however, occurs only very rarely.
  
* Without source coding, exactly one bit would be needed per source symbol, and accordingly, for a source symbol sequence of length  N  would also apply to the coder symbol sequence  Nbits=N.
+
* Without source coding, exactly one bit would be needed per source symbol, and accordingly, for a source symbol sequence of length  N , the encoded sequence would also have length   Nbits=N.
 
* Entropy coding makes little sense here without further measures  (example:  combining several symbols into a tuple)  because of the unfavourable symbol probabilities.
 
* Entropy coding makes little sense here without further measures  (example:  combining several symbols into a tuple)  because of the unfavourable symbol probabilities.
 
* The remedy is  [[Information_Theory/Weitere_Quellencodierverfahren#Run.E2.80.93Length_coding|Run-Length Coding]]  (RLC), which is described in the theory section under the link mentioned.  For example, for the symbol sequence   ABAABAAAABBAAB...    the corresponding output of  "Run–Length Coding":   2; 3; 5; 1; 3;...
 
* The remedy is  [[Information_Theory/Weitere_Quellencodierverfahren#Run.E2.80.93Length_coding|Run-Length Coding]]  (RLC), which is described in the theory section under the link mentioned.  For example, for the symbol sequence   ABAABAAAABBAAB...    the corresponding output of  "Run–Length Coding":   2; 3; 5; 1; 3;...
Line 12: Line 12:
 
:010'011'101'001'011'...
 
:010'011'101'001'011'...
  
The graph shows the RLC result to be analysed.  Columns 2 and 3 show the substring lengths  Li  in binary and decimal, respectively, and column 4 shows them in cumulative form  (values from column 3 added up).
+
The graph shows the RLC result to be analyzed.  Columns 2 and 3 show the substring lengths  Li  in binary and decimal, respectively, and column 4 shows them in cumulative form  (values from column 3 added up).
  
 
*One problem of  "Run-Length Coding"  (RLC) is the unlimited range of values of the quantities  Li.  With  D=3,  no value  Li>7  can be represented and with  D=2,  the restriction is  1Li3.
 
*One problem of  "Run-Length Coding"  (RLC) is the unlimited range of values of the quantities  Li.  With  D=3,  no value  Li>7  can be represented and with  D=2,  the restriction is  1Li3.
Line 27: Line 27:
 
Hints:  
 
Hints:  
 
*This exercise belongs to the chapter  [[Information_Theory/Further_Source_Coding_Methods|Further source coding methods]].
 
*This exercise belongs to the chapter  [[Information_Theory/Further_Source_Coding_Methods|Further source coding methods]].
*In particular, reference is made to the page  [[Information_Theory/Further_Source_Coding_Methods#Run.E2.80.93Length_coding|Run-Length Coding]].
+
*In particular, reference is made to the section  [[Information_Theory/Further_Source_Coding_Methods#Run.E2.80.93Length_coding|Run-Length Coding]].
 
   
 
   
  
Line 59: Line 59:
  
  
{How many bits are needed for&nbsp; <u>Run&ndash;Length Coding</U>&nbsp; (RLC)&nbsp; according to the given table with eight bits per codeword&nbsp; (D=8)?
+
{How many bits are needed for&nbsp; <u>Run&ndash;Length Coding</U>&nbsp; (RLC)&nbsp; according to the given table with eight bits per code word&nbsp; (D=8)?
 
|type="{}"}
 
|type="{}"}
 
Nbits =  { 200 }  
 
Nbits =  { 200 }  
  
  
{Is&nbsp; <u>Run&ndash;Length Coding</u>&nbsp; with seven bit codewords&nbsp; (D=7)&nbsp; possible here?
+
{Is&nbsp; <u>Run&ndash;Length Coding</u>&nbsp; with seven bit code words&nbsp; (D=7)&nbsp; possible here?
 
|type="()"}
 
|type="()"}
 
- Yes.
 
- Yes.
Line 70: Line 70:
  
  
{How many bits are needed for&nbsp; <u>Run&ndash;Length Limited Coding</U>&nbsp; (RLLC)&nbsp; with seven bits per codeword&nbsp; (D=7)?
+
{How many bits are needed for&nbsp; <u>Run&ndash;Length Limited Coding</U>&nbsp; (RLLC)&nbsp; with seven bits per code word&nbsp; (D=7)?
 
|type="{}"}
 
|type="{}"}
 
Nbits =  { 182 }
 
Nbits =  { 182 }
  
  
{How many bits are needed for&nbsp; <u>Run&ndash;Length Limited Coding</u>&nbsp; (RLLC)&nbsp; with six bits per codeword&nbsp; (D=6)?
+
{How many bits are needed for&nbsp; <u>Run&ndash;Length Limited Coding</u>&nbsp; (RLLC)&nbsp; with six bits per code word&nbsp; (D=6)?
 
|type="{}"}
 
|type="{}"}
 
Nbits = { 204 }
 
Nbits = { 204 }
Line 85: Line 85:
 
===Solution===
 
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
'''(1)'''&nbsp; The binary sequence consists of&nbsp; N=1250&nbsp; binary symbols (can be read from the last column in the table).&nbsp; This means that the same number of bits is needed without coding:
+
'''(1)'''&nbsp; The binary sequence consists of&nbsp; N=1250&nbsp; binary symbols&nbsp; (can be read from the last column in the table).&nbsp;  
:$$N_\text{Bit}\hspace{0.15cm}\underline{= 1250}.$$
+
*This means that the same number of bits is needed without coding:
 +
:$$N_\text{bits}\hspace{0.15cm}\underline{= 1250}.$$
  
  
 
'''(2)'''&nbsp; The entire symbol sequence of length&nbsp; N=1250&nbsp; contains&nbsp; NB=25&nbsp; symbols&nbsp; B&nbsp; and thus&nbsp; NA=1225&nbsp; symbols&nbsp; A.&nbsp;
 
'''(2)'''&nbsp; The entire symbol sequence of length&nbsp; N=1250&nbsp; contains&nbsp; NB=25&nbsp; symbols&nbsp; B&nbsp; and thus&nbsp; NA=1225&nbsp; symbols&nbsp; A.&nbsp;
*The number&nbsp; NB&nbsp; der Symbole&nbsp; B&nbsp; ist dabei gleich der Zeilenzahl in der vorne angegebenen Tabelle.   
+
*The number&nbsp; NB&nbsp; of symbols&nbsp; B&nbsp; is equal to the number of rows in the table given at the front.   
*Thus the following applies to the relative frequency of&nbsp;&nbsp; B:
+
*Thus the following applies to the relative frequency of symbol&nbsp; B:
 
:hB=NBN=251250=0.02_=2%.
 
:hB=NBN=251250=0.02_=2%.
  
  
'''(3)'''&nbsp; We now consider&nbsp; <i>Run&ndash;Length Coding</i>&nbsp; (RLC), where each distance between two&nbsp; B&ndash;symbols is represented by eight bits&nbsp; (D=8).  
+
'''(3)'''&nbsp; We now consider&nbsp; "Run&ndash;Length Coding"&nbsp; (RLC), where each distance between two&nbsp; B&ndash;symbols is represented by eight bits&nbsp; (D=8).  
*Thus, with&nbsp; NB=25, we get::
+
*Thus, with&nbsp; NB=25, we get:
:$$N_{\rm Bit} = N_{\rm B} \cdot 8 \hspace{0.15cm}\underline{= 200} \hspace{0.05cm}.$$
+
:$$N_{\rm bits} = N_{\rm B} \cdot 8 \hspace{0.15cm}\underline{= 200} \hspace{0.05cm}.$$
  
  
'''(4)'''&nbsp; RLC&nbsp;  with&nbsp; D=7&nbsp;only allows values between&nbsp; 1&nbsp; und&nbsp; 271=127 for&nbsp; Li&nbsp; .  
+
'''(4)'''&nbsp; RLC&nbsp;  with&nbsp; D=7&nbsp;only allows values between&nbsp; 1&nbsp; und&nbsp; 271=127 for&nbsp; Li.  
*However, the entry "226" in line 19 is greater &nbsp; &nbsp; &#8658; &nbsp; &nbsp; <u>NO</u>.
+
*However, the entry&nbsp; "226"&nbsp; in line 19 is greater &nbsp; &nbsp; &#8658; &nbsp; &nbsp; <u>NO</u>.
  
  
'''(5)'''&nbsp; Even with Run&ndash;Length Limited Coding&nbsp;  (RLLC)&nbsp; , only values up to&nbsp; 127&nbsp are permitted for the "real" distances&nbsp; Li&nbsp; with&nbsp;  D=7&nbsp; ;.
+
'''(5)'''&nbsp; Even with Run&ndash;Length Limited Coding&nbsp;  (RLLC),&nbsp; only values up to&nbsp; 127&nbsp; are permitted for the&nbsp; "real"&nbsp; distances&nbsp; Li&nbsp; with&nbsp;  D=7.
*The entry "226" in line 19 is replaced by the following for&nbsp;  RLLC&nbsp;
+
*The entry&nbsp; "226"&nbsp; in line 19 is replaced by the following for&nbsp;  RLLC:
  
:* Line 19a: &nbsp;  <b>S</b> = <b>0000000</b> &nbsp;&nbsp;&#8658;&nbsp;&nbsp; special character, stands for "+ 127",
+
:* Line 19a: &nbsp;  <b>S</b> = <b>0000000</b> &nbsp;&nbsp;&#8658;&nbsp;&nbsp; special character, stands for "+127",
  
 
:* Line 19b: &nbsp;  <b>1100011</b> &nbsp;&nbsp;&#8658;&nbsp;&nbsp; decimal 99.
 
:* Line 19b: &nbsp;  <b>1100011</b> &nbsp;&nbsp;&#8658;&nbsp;&nbsp; decimal 99.
  
 
*This gives a total of 26 words of seven bits each:
 
*This gives a total of 26 words of seven bits each:
:$$N_{\rm Bit} = 26 \cdot 7 \hspace{0.15cm}\underline{= 182} \hspace{0.05cm}.$$
+
:$$N_{\rm bits} = 26 \cdot 7 \hspace{0.15cm}\underline{= 182} \hspace{0.05cm}.$$
  
  
'''(6)'''&nbsp; Now the following changes have to be made in&nbsp; RLLC&nbsp; compared to&nbsp; RLC&nbsp; (see table):
+
'''(6)'''&nbsp; With&nbsp;  D=6&nbsp; the following changes have to be made in&nbsp; RLLC&nbsp; compared to&nbsp; RLC&nbsp; (see table):
  
* Zeile &nbsp;&nbsp;1: &nbsp; 122 = 1 &middot; 63 + 59 &nbsp;&nbsp;(one word more),
+
* Line &nbsp;&nbsp;1: &nbsp; 122 = 1 &middot; 63 + 59 &nbsp;&nbsp;(one word more),
  
* Zeile &nbsp;&nbsp;6: &nbsp;&nbsp;&nbsp; 70 = 1 &middot; 63 + 7 &nbsp;&nbsp;&nbsp;&nbsp;(one word more),
+
* Line &nbsp;&nbsp;6: &nbsp;&nbsp;&nbsp; 70 = 1 &middot; 63 + 7 &nbsp;&nbsp;&nbsp;&nbsp;(one word more),
  
* Zeile &nbsp;&nbsp;7: &nbsp;&nbsp;&nbsp; 80 = 1 &middot; 63 + 17 &nbsp;&nbsp;(one word more),
+
* Line &nbsp;&nbsp;7: &nbsp;&nbsp;&nbsp; 80 = 1 &middot; 63 + 17 &nbsp;&nbsp;(one word more),
  
* Zeile 12: &nbsp;&nbsp;&nbsp; $79 = 1 &middot; 63 + 18$ &nbsp;&nbsp;(one word more),
+
* Line 12: &nbsp;&nbsp;&nbsp; $79 = 1 &middot; 63 + 16$ &nbsp;&nbsp;(one word more),
  
* Zeile 13: &nbsp;&nbsp;&nbsp; 93 = 1 &middot; 63 + 30 &nbsp;&nbsp;(one word more),
+
* Line 13: &nbsp;&nbsp;&nbsp; 93 = 1 &middot; 63 + 30 &nbsp;&nbsp;(one word more),
  
* Zeile 19: &nbsp; 226 = 3 &middot; 63 + 37  &nbsp;&nbsp;(one word more),
+
* Line 19: &nbsp; 226 = 3 &middot; 63 + 37  &nbsp;&nbsp;(one word more),
  
* Zeile 25: &nbsp;&nbsp;&nbsp; 97 = 1 &middot; 63 + 34  &nbsp;&nbsp;(one word more).
+
* Line 25: &nbsp;&nbsp;&nbsp; 97 = 1 &middot; 63 + 34  &nbsp;&nbsp;(one word more).
  
  
This gives a total of 34 words of six bits each:
+
This gives a total of&nbsp; $25+9=34$&nbsp; words of six bits each:
:$$N_{\rm Bit} = 34 \cdot 6 \hspace{0.15cm}\underline{= 204} \hspace{0.05cm},$$
+
:$$N_{\rm bits} = 34 \cdot 6 \hspace{0.15cm}\underline{= 204} \hspace{0.05cm},$$
 
i.e. a worse result than with seven bits according to subtask '''(5)'''.
 
i.e. a worse result than with seven bits according to subtask '''(5)'''.
 
{{ML-Fuß}}
 
{{ML-Fuß}}

Latest revision as of 01:34, 13 November 2022

Table on Run-Length Coding

We consider a binary source with the symbol set  A  and  B, where  B  however, occurs only very rarely.

  • Without source coding, exactly one bit would be needed per source symbol, and accordingly, for a source symbol sequence of length  N , the encoded sequence would also have length   Nbits=N.
  • Entropy coding makes little sense here without further measures  (example:  combining several symbols into a tuple)  because of the unfavourable symbol probabilities.
  • The remedy is  Run-Length Coding  (RLC), which is described in the theory section under the link mentioned.  For example, for the symbol sequence   ABAABAAAABBAAB...   the corresponding output of  "Run–Length Coding":   2; 3; 5; 1; 3;...
  • Of course, the lengths  L1=2L2=3, ...  of the individual substrings, each separated by  B , must be represented in binary before transmission.  If one uses  D=3  (bit) for all  Li  one obtains the RLC binary symbol sequence
010'011'101'001'011'...

The graph shows the RLC result to be analyzed.  Columns 2 and 3 show the substring lengths  Li  in binary and decimal, respectively, and column 4 shows them in cumulative form  (values from column 3 added up).

  • One problem of  "Run-Length Coding"  (RLC) is the unlimited range of values of the quantities  Li.  With  D=3,  no value  Li>7  can be represented and with  D=2,  the restriction is  1Li3.
  • The problem is circumvented with  "Run–Length Limited Coding"  (RLLC).  If a value is  Li2D,  one replaces  Li  with a special character  S  and the difference  Li2D+1.  With the RLLC decoder, this special character  S  is expanded again.





Hints:


RLLC Example:  We again assume the above sequence and the parameter  D=2 :

  • Source symbol sequence:    ABAABAAAABBAAB...
  • RLC decimal sequence:          2; 3; 5; 1; 3; ...
  • RLLC decimal sequence:       2;  3;  S; 2;  1;  3; ...
  • RLLC binary sequence:          10′11′ 00′10′01′11′...


You can see:

  • The special character  S  is binary-coded here as  00 .  This is only an example – it does not have to be like this.
  • Since with  D=2  for all real RLC values  1Li3 , the decoder recognizes the special character  00.
  • It replaces this again with  2D1  (three in the example)  A–symbols.


Questions

1

How many bits would be needed  without source coding , i.e. with the assignment  A   →  0  and  B   →  1?

Nbits = 

2

What is the relative frequency of symbol  B?

hB = 

 %

3

How many bits are needed for  Run–Length Coding  (RLC)  according to the given table with eight bits per code word  (D=8)?

Nbits = 

4

Is  Run–Length Coding  with seven bit code words  (D=7)  possible here?

Yes.
No.

5

How many bits are needed for  Run–Length Limited Coding  (RLLC)  with seven bits per code word  (D=7)?

Nbits = 

6

How many bits are needed for  Run–Length Limited Coding  (RLLC)  with six bits per code word  (D=6)?

Nbits = 


Solution

(1)  The binary sequence consists of  N=1250  binary symbols  (can be read from the last column in the table). 

  • This means that the same number of bits is needed without coding:
Nbits=1250_.


(2)  The entire symbol sequence of length  N=1250  contains  NB=25  symbols  B  and thus  NA=1225  symbols  A

  • The number  NB  of symbols  B  is equal to the number of rows in the table given at the front.
  • Thus the following applies to the relative frequency of symbol  B:
hB=NBN=251250=0.02_=2%.


(3)  We now consider  "Run–Length Coding"  (RLC), where each distance between two  B–symbols is represented by eight bits  (D=8).

  • Thus, with  NB=25, we get:
Nbits=NB8=200_.


(4)  RLC  with  D=7 only allows values between  1  und  271=127 for  Li.

  • However, the entry  "226"  in line 19 is greater     ⇒     NO.


(5)  Even with Run–Length Limited Coding  (RLLC),  only values up to  127  are permitted for the  "real"  distances  Li  with  D=7.

  • The entry  "226"  in line 19 is replaced by the following for  RLLC:
  • Line 19a:   S = 0000000   ⇒   special character, stands for "+127",
  • Line 19b:   1100011   ⇒   decimal 99.
  • This gives a total of 26 words of seven bits each:
Nbits=267=182_.


(6)  With  D=6  the following changes have to be made in  RLLC  compared to  RLC  (see table):

  • Line   1:   122=1·63+59   (one word more),
  • Line   6:     70=1·63+7     (one word more),
  • Line   7:     80=1·63+17   (one word more),
  • Line 12:     79=1·63+16   (one word more),
  • Line 13:     93=1·63+30   (one word more),
  • Line 19:   226=3·63+37   (one word more),
  • Line 25:     97=1·63+34   (one word more).


This gives a total of  25+9=34  words of six bits each:

Nbits=346=204_,

i.e. a worse result than with seven bits according to subtask (5).