Professional Documents
Culture Documents
P
r
li
1) Lower bound follows from Kraft inequality 2 1
i=1
P
I
2) Note: H(X) = pi log 2(pi )
i=1
P
I
Lav = pi l i
i=1
Imagine there was … then we can delete it (code was not optimal)
Optimal codes: Preliminaries
Fact 2: There exists an optimal binary prefix-free code such that
the two least likely codewords only differ in the last digit,
i.e., they are are siblings.
Option 1: Option 2:
pr
pr
pr 1 pr 1
Optimal codes: Huffman code
Facts 1 + 2: Start from leaves and build towards root as follows
Step 2 Create a parent node to the two least likely active nodes,
and assign it the corresponding probability.
Activate this new node and deactivate the children nodes.
Step 3 If there is only one active node left, it becomes the root.
Otherwise, go to Step 2.
Optimal codes: Huffman code
Example: AX = {A, B, C, D}
pA = 0.2, pB = 0.5, pC = 0.2, pD = 0.1
Huffman code:
Lav = 1.8
For a large file encoded using the following Huffman code, what is the
probability of randomly selecting a 1?
A p1>1/2
B p1=1/2
C p1<1/2
For a large file encoded using the following Huffman code, what is the
probability of randomly selecting a 1?
A p1>1/2
B p1=1/2
C p1<1/2
Where Symbol (Huffman) Codes Fail (I)
Entropy:
H = å i =1 pi log2 1 pi
6
1. I am twice as ha_ _ _ _ _ _ _ _.
Arithmetic codes:
- Bayesian model which uses the conditional probabilities of strings of
outcomes to partition the outcome space from [1 0).
- The partition label describes the compressed file.
- Closely matches the Shannon information content of the source string.
- Receiver need to know the symbol conditional probabilities.
Lempel Ziv Coding
- learn dictionary on the fly
- encode streams of data
- asymptotically optimal
Example1 AABABBBABAABABBBABBABB
A|ABABBBABAABABBBABBABB
A|AB|ABBBABAABABBBABBABB
A|AB|ABB|BABAABABBBABBABB
A|AB|ABB|B|ABA|ABAB|BB|ABBA|BB
1http://math.mit.edu/~goemans/18310S15/lempel-ziv-notes.pdf
Lempel Ziv Coding
Example1 AABABBBABAABABBBABBABB
1http://math.mit.edu/~goemans/18310S15/lempel-ziv-notes.pdf
Lempel Ziv Coding
Example1 AABABBBABAABABBBABBABB
,0|1,1|10,1|00,1|010,0|101,1|100,1|011,0|0111
1http://math.mit.edu/~goemans/18310S15/lempel-ziv-notes.pdf
Lempel Ziv Coding
Many versions and extensions
e.g. Lempel-Ziv-Welch, see
https://en.wikipedia.org/wiki/Lempel–Ziv–Welch
When do we do this?
- We do not care for the lost information (irrelevance)
e.g., sound we cannot hear, contrast we cannot see
- We do not have the resources for all the information
e.g., low resolution content over low-bandwidth links
Lossy compression
Analog Digital
Processing Sampling Quantization
signal
signal
quantization error
}
11
}
10
01
00
Quantization
Model x q = x + nq
quantized signal quantization
signal sample error
Assume
- quantization using m bits
Q=2m quantization intervals
- quantization range [-xmax, xmax]
and uniform quantization
interval size D=2xmax/Q
Quantization
xq
xmax
D clipping→
}
}
-xmax
xmax x
←clipping
-xmax
Quantization
Model x q = x + nq
quantized signal quantization
signal sample error
Assume
- negligible clipping
-xmax≤x≤xmax approximately
D2
- nq is uniformly distributed Pn q = E(n2q ) = 12
p
Px
Define: modulation level A = xmax
Quantization
Model x q = x + nq
quantized signal quantization
signal sample error
Measure of distortion
Signal-to-quantization-noise power ratio (SQNR)
E(x2 ) Px
SQNR = E(n2q ) = Pn q
Assumptions
12A2 x2max
SQNR = D2 = 3A2 Q2 = 3A2 22m
Quantization
in decibel (dB):
SQNR = 10 log10 (3A2 22m ) = 10 log10 (3) + 10 log10 (A2 ) + m20 log10 (2)
a l i ty
qu
70
16 CD 15
60
14
13
50
12
11 ty
SQNR (dB) --->
a l i
10
n e qu
40
9 ph o
8 Tele
30
7
6
20
5
10
m=4
0
-40 -35 -30 -25 -20 -15 -10 -5 0
20 log 10(A) --->
Quantization
80
a l i ty
qu
70
16 CD 15
60
14
Cl
13
ip
12
pi
50
ng
SQNR (dB) --->
11
10
di
40
9
st
or
30
8
tio
7
n
20
6
5
10
m=4
0
-40 -35 -30 -25 -20 -15 -10 -5 0
20 log 10(A) --->
Companding
xq
xmax
clipping→
-xmax
xmax x
←clipping
-xmax
Lossy compression
Analog Digital
Processing Sampling Quantization
signal
signal
1) Simplest case
xk yk
one
sample
delay
yk=xk-xk-1, k=0,1,2,…
Prediction
Reduce dynamic of signal through predicting next
samples from previous samples and look at difference
prediction
filter
a1 , . . . , a K
P
K
yk = x k a i xk i , 8k
i=1
Prediction
3) Example
https://www.mathworks.com/help/dsp/examples/lpc-analysis-and-synthesis-of-speech.html
0.4
!
0.3
0.2
0.1
-0.1
-0.2
-0.3
-0.4
0 200 400 600 800 1000 1200 1400 1600
Lossy compression
Analog Digital
Processing Sampling Quantization
signal
signal
most important
coefficient 2 3
r1
reduce # of 6 r2 7
quantization 6 7 1
6 .. 7=A x
levels 4 . 5
rn
least important
coefficient
Transformation
Use widely for image, sound, video compression
higher frequencies
higher frequencies
quantization step size
our D!
see https://en.wikipedia.org/wiki/JPEG
Lossy compression
Analog Digital
Processing Sampling Quantization
signal
signal