You are on page 1of 38

ti : M Hamming

Richard W. Hamming (1915-1998)

Thnh vin : Trn ng Khoa

Trn ng Hng
Trn Minh Khu Nguyn Hng Ho

Mnh Y Vinh

Hamming Code

K hiu u v S(x) N(x) R(x) R

nh ngha Bn tin gc M ha Tn hiu truyn Tn hiu nhiu Tn hiu nhn Chui bit gii iu ch Chui bit gii m

Hamming Code

Mc ch ca l thuyt M ha trn knh truyn (channel encoding theory) l tm nhng m c th truyn thng nhanh chng, cha ng nhiu m k (code word) hp l v c th sa li (error correction) hoc t nht pht hin cc li xy ra (error detection). Cc mc ch trn khng ph thuc vo nhau, v mi loi m c cng dng ti u cho mt ng dng ring bit. Nhng c tnh m mi loi m ny cn cn tu thuc nhiu vo xc sut li xy ra trong qu trnh truyn thng

y ta tm hiu m khi tuyn tnh (Linear block codes), bao gm : M tun hon (Cyclic codes, m Hamming l mt b phn nh) M ti din (Repetition codes) M chn l (Parity codes) M Reed-Solomon (Reed Solomon codes) M BCH (BCH code) M Reed-Muller M hon ho (Perfect codes)

Hamming Code

Trong vin thng (telecommunication), m Hamming l mt m sa li tuyn tnh (linear error-correcting code), c t tn theo tn ca ngi pht minh ra n, Richard Hamming. M Hamming c th pht hin mt bit hoc hai bit b li (single and double-bit errors). M Hamming cn c th sa cc li do mt bit b sai gy ra. Ngc li vi m ca ng, m chn l (parity code) n gin va khng c kh nng pht hin cc li khi 2 bit cng mt lc b hon v (0 thnh 1 v ngc li), va khng th gip sa c cc li m n pht hin thy.

Hamming Code

Khong cch Hamming


Khong cch Hamming c s dng trong k thut vin thng tnh s lng cc bit trong mt t nh phn (binary word) b i ngc, nh mt hnh thc c tnh s li xy ra trong qu trnh truyn thng, v v th, i khi n cn c gi l khong cch tn hiu (signal distance). Vic phn tch trng s Hamming ca cc bit cn c s dng trong mt s ngnh, bao gm l thuyt tin hc, l thuyt m ha, v mt m hc. Trc tin ta tm hiu v trng s Hamming: trng s Hamming ca mt t m l s s 1 c trong t m . V d vi t m 00111010 c trng s Hamming l 4. Khong cch Hamming c nh ngha l cc bt khc nhau gia hai t m. Khong cch Hamming gia hai t m c ly bng cch dng ton t XOR tng bt ca hai t m vi nhau v khong cch Hamming l trng s ca kt qu tm c trong php XOR trn. V d ta c hai t m 0110101 v 1110001 ta c: 0110101 XOR 1110001 ---------------1000100 Vy khong cch Hamming ca 2 t m trn l 2.

Hamming Code

Trng lng Hamming


Trng lng Hamming (Hamming weight) ca mt dy k t l khong cch Hamming t mt dy k t ton s khng c cng chiu di. C ngha l s phn t trong dy k t khng c gi tr khng (0): i vi mt dy k t nh phn (binary string), n ch l s cc k t c gi tr mt (1), ly v d trng lng Hamming ca dy k t 11101 l 4.

i vi mt chiu di c nh "n", khong cch Hamming l o trn khng gian vect ca cc t c chiu di , v n tha mn yu cu v tnh cht s khng m (non-negativity) (s tuyt i), hin thn ca tnh bt kh phn nh (indiscernibles) v tnh i xng (symmetry), v n c th c chng minh mt cch d dng bng php quy np ton phn (complete induction) rng n cn tha mn bt ng thc tam gic (triangle inequality) na.

Hamming Code

Khong cch Hamming gia hai t a v b cn c gi l trng lng Hamming (Hamming weight) ca php ton ab, dng mt ton t thch hp thay th cho ton t "". i vi hai dy k t nh phn a v b, php ton ny tng ng vi php ton a XOR b. Khong cch Hamming ca cc dy k t nh phn cn tng ng vi khong cch Manhattan gia hai giao im ca mt hnh gi phng cp n (n-dimensional hypercube), trong n l chiu di ca cc t.

Hamming Code

V d i vi m ASCII 7 bit

M ASCII 7 bit cn 4 bit d tha thm vo d liu gc. S d ta chn l 4 bt v 24 = 16 s xc nh c 16 trng hp b li n bt (trong dy ta xt c 11 bit: 7 bit d liu v 3 bit m). Cc bt d tha c t vo v tr 1, 2, 4 v 8 (Ch d (data) c dng biu th cc bit d liu v ch p (parity) biu th cc bit chn l (parity bits).)

11

10

d
7 6

d
5

d
4

p
4

d
3

d
2

d
3

p
1

d
2

p
1

Hamming Code

Thut ton :
M Hamming l mt m sa li tuyn , m ny c th pht hin mt bit hoc hai bit b li. M Hamming cn c th sa cc li do mt bit b sai gy ra. C th tm tt cc bc cho vic s dng m Hamming nh sau: 1) Cc v tr trong mt khi c bt u nh s t 1: Bit 1, 2, 3 2) Tt c cc bt v tr s m ca 2 c dng lm bt chn l. Vd: 20, 21, 22, 23, 24

3) Tt c cc v tr khc v tr cn li s c dng cho cc bit d liu. VD: v tr th 2, 3, 5, 6, 7


4) Mi bit chn l tnh gi tr chn l cho mt s bit trong t m theo quy tc nh sau:

Hamming Code

Bt chn l v tr s 1 (20) s kim tra tnh chn l ca cc v tr m s th t ca v tr trong h nh phn c bt ngoi cng l 1. Vd: 1 (1), 3 (11), 5 (101), 7 (111), 9 (1001) .. Bt chn l v tr s 2 (10) s kim tra tnh chn l ca cc v tr m s th t ca v tr trong h nh phn c bt th 2 l 1. Vd: 2 (10), 3 (111), 6 (110), 7 (111), 10 (1010) Bt chn l v tr s 4 (100) s kim tra tnh chn l ca cc v tr m s th t ca v tr trong h nh phn c bt th 3 l 1. Vd: 4, 5, 6, 7, 12, 13, 14, 15 Tng t vi cc bt chn l v tr cao hn: 8, 16, 32 Tm li, mi bt chn l trong m Hamming s tnh gi tr chn l m ti , bit nh phn ca v tr AND vi cc bit v tr s l mt s khc khng.

Hamming Code

Trong , bit R c dng tnh chn l cc t hp bt sau: Bit p1 tnh cc bit th 3, 5, 7, 9, 11 Bit p2 tnh cc bit th 3, 6, 7, 10, 11 Bit p3 tnh cc bit th 5, 6, 7 Bit p4 tnh cc bit th 9, 10, 11

Hnh 1: Vng trn trong m Hamming

Hamming Code

V d, ta c chui bit "1010110" v m Hamming s dng bt chn l chn th p1 = 1, p2 = 0, p3 = 0, p4 = 0 Khi , chui d liu truyn i s l 10100100110

Hnh 2: Vng trn Hamming

Hamming Code

Do m hamming s dng bit chn-l-chn nn tng s bt 1 trong 1 vng trn l s chn. Gi s trong qu trnh truyn xy ra li ti bit 11, ti pha thu, thut ton s pht hin ra tng s bit 1 trong 3 vng trn (vng bn tri v hai vng trn di) l mt s l, tri vi quy tc nn n s thay i gi tr ca bt nm vng giao ca 3 vng trn ny.

Hnh 2.3: Bit th 11 b li khin tng s bt 1 ca 3 vng trn bn phi l mt s l

Hamming Code

Ma Trn Sinh
K Hiu : G (k,n) k: s vecto c h (s hng) n: di t m (s ct) Cho [a] =[u1 u2 ui] l ma trn mang tin v ma trn sinh G th ta c [V]=[u].[G] .Vit gn : V=u.G

Ma Trn Sinh Chun

B m V c th thay i bng b m V c cng xc sut sai Cc b m tng ng c to ra bng cch bin i tng ng trn ma trn sinh : hon b ct , t hp tuyn tnh cc hng c thnh hng mi G Gch = [Ik,k , p k,(n-k)]

Hamming Code

Ma Trn Th

Di dng cu trc h thng H = [Ir.Q] Trong : Ir l ma trn n v Ma trn Q gm 2r 1 r ct Mi ct l vector r chiu c trng s l 2 hoc ln hn nh ngha : vi v V , u U th ma trn sinh [H] = [h1 h2 hn-k] vi v.HT =0 nh l : nu V c Gch = [Ik,k , p k,(n-k)] th Hch = [- PKT , Ik,(n-k)] Trong thc t vic to v gii m hamming mt cch n gin, ngi ta i v tr cc ct trong ma trn H . Khi cc bit cn kim tra xen k vi cc bit mang tin ch khng cn tnh cht khi

Hamming Code

M t bng thut ton


Nh ta bit, m Hamming l mt m khi. V vi mi m > 2, lun tn ti m Hamming vi cc thng s sau: Chiu di t m: n = 2m-1 Chiu di phn tin: k=2m-m-1 Chiu di phn kim tra: m=n-k Kh nng sa sai: t=1 Ma trn kim tra H c dng: H = [Im.Q]

Trong Im l m trn n v m*m v Q l ma trn [2m-m-1] ct, mi ct l vect m chiu c trng s l 2 hoc ln hn.

1 0 0 1 0 1 1

V d, vi m=3, ma trn ca m [7,4] c vit di dng H(3,7) =

0 1 0 1 1 1 0 0 0 1 0 1 1 1

Hamming Code

Xy Dng M Hamming
M hamming c c im : Ma trn th H c r hng , 2r 1 ct Xt V D : m hamming ( 7,4 ) c ma trn th H

vic to m n gin ta chn cc bit kim tra c1 , c2 , c3 cc v tr tng ng 2i vi i = 0,1,2,.. (ngha l cc v tr th nht , th hai v th t ca cc k hiu t m)
V c dng : v= c1 c2 u1 c3 u2 u3 u4 , vi u = u1 u2 u3 u4

Hamming Code

Xac nh c1,c2 ,c3 ? to m : v HT = 0 Vi d u = 1010 , v = c1 c2 1 c3 0 1 0 c v.HT =0

c3 +1 = 0 => c3= 1 c2 + 1 + 1 = 0 => c2 = 0 c1 + 1 = 0 => c1 = 1 v = 1011010

Hamming Code

S tao ma : u = u1 u2 u3 u4 v = c1 c2 u1 c3 u2 u3 u4 v HT = [c1 c2 u1 c3 u2 u3 u4 ] HT = 0

c3 = u2 + u3 + u4 c2 = u1 + u3 + u4 c1 = u1 + u2 + u4

Hnh 4. Mch m ha

Hamming Code

u im :
T ma trn H ta d dng suy ra t m v , ngha l khng cn bit ma trn sinh G ta cng d dng tm c v

Hamming Code

S Sa Li M Hamming
nhn bit sai v sa li knh truyn ta dng Syndrome

S = r.HT Nu : S = 0 th r = v ( Khng c li ) S 0 th r v ( c li ) Ta c : S = r.HT m r = v + e S = ( v + e ) . HT = v HT + e HT = e HT Xc nh c e ta suy ra v = r + e

Hamming Code

VD : xet ma Hamming ( 7 ,4 )

Vi r = r1r2r3r4r5r6r7 Syndrome :

S = r HT

S = [ r4 + r5 + r6 + r7, r2 + r3 + r6 + r7, r1 + r3 + r5 + r7 ]

Hamming Code

Cho : e= 1000000 => s1= eHT = [ 1000000 ] HT = 001

e= 0100000 => s2 = 010


e= 0010000 => s3 = 011 e= 0001000 => s4 = 100

e= 0000100 => s5 = 101


e= 0000010 => s6 = 110 e= 0000001 => s7 = 111

Hamming Code

Bn s tht :

Hamming Code

Mach Sa Li :

Hamming Code

V D : tn hiu thu c r = ( r1 r2 r3 r4 r5 r6 r7 ) = ( 0 0 1 1 0 1 1 ) Khi : S1= r4 + r5 + r6 + r7 = 1 + 0 + 1 + 1 = 1 S2 = r2 + r3 + r6 + r7 = 0 + 1 + 1 + 1 = 1 S3 = r1 + r3 + r5 + r7 = 0 + 1 + 0 + 1 = 0 Vy : S = ( 1 1 0) , nu i ra nh phn l 6 , ta nhn thy S trng vi ct s 6 ca ma trn H , c ngha k hiu sai l k hiu s 6(r) u ra th 6 ca s gii m s c i=1 . Ta ch cn o bit th 6 theo thut ton :

Kt lun : M hamming chi sa c 1 li / 1 ng truyn do o c dung rt nhiu trong truyn d liu trong mng may tinh

Hamming Code

li m ha (Coding Gain)
Tc m R = k/n k: s symbol d liu n: tng symbol

SNR t v SNR ca bit :

= =

Vi mt s m ha, li m ha ti mt xc sut li bit c nh ngha l s khc bit gia nng lng cn thit cho 1 bit thng tin m ha t c xc sut li cho trc v truyn dn khng m ha.

Hamming Code

li m ha :

Hamming Code

Hamming Code

C th ni, lch s pht trin ca m sa li c bt u bng s ra i ca m Hamming v nh l Shannon. Vic ra i m Hamming l c s cho vic pht trin thm nhiu loi m ha mi, c tin cy cao hn sau ny. M Hamming c tm quan trng c bn trong l thuyt m ha v c s dng thc t trong thit k my tnh. u im ca m ny l n gin, s bit kim tra t, ngoi ra, m ny hot ng tt trong vic pht hin cc li n bit v mt s trng hp li hai bit. Tuy nhin, m Hamming khng th sa c bn tin b li a bit.

Hamming Code

M HA NGUN

M SHANNON

nh ngha gii hn ca n0 : m-ni P(Ui) m1-ni (1). Bc 1: Lit k Ui v P(Ui) theo th t gim dn vo ct 1 v 2 Bc 2: Pi =
1 1 ()

Bc 3: Tnh ni theo bt ng thc (1) Bc 4: i Pi ra dng nh phn

Shannon Code

V D : Cho b m U vi xc sut nh sau


Ui P(Ui) U1 0.34 U2 0.2 U3 0.19 U4 0.1 U5 0.07 U6 0.04 U7 0.03 U8 0.02 U9 0.01

Ui
U1 U2 U3

P(ui)
0.34 0.2 0.19

Pi
0 0.34 0.54

ni
2 3 3

Dang nh phn ca Pi
0 0.01010111 0.10001010 00 010 100

T ma

U4 U5 U6
U7 U8 U9

0.1 0.07 0.04


0.03 0.02 0.01

0.73 0.83 0.9


0.94 0.97 0.99

4 4 5
6 6 7

0.10111010 0.111010100 0.11100110


0.11110000 0.11110000 0.11111101

1011 1101 11100


111100 111110 1111110

Shannon Code

di trung bnh t m :

Entropy ca tp tin :

Ch s kinh t ca b m :

Shannon Code

M T in LZ77
a chui vn bn vo b m

Dng 1 ca s trt c cc k t cn m ha vo
Ng ra :

+ Khi bt u m ha: <0,0,k> (k l k t u tin)


+ Ln m ha tip theo: <i,j,k> So snh k t m ha vi k t m ha, nu ging th a ra t m <i,j,k> trong : i l v tr bt u ca on/k t ging nm trong t in vi on/k t ang nn ; j l di ca on k t ging ; k l k t k tip

Dictionary Algorithm

V D : m ha on k t sau AABCBBABC Bc 1 2 3 4 5 V tr 1 2 4 5 7 A B AB K t ging Chui A AB C BB ABC

Ng ra <0,0,A> <0,0,B> <0,0,C> < 2,1,B> <5,2,C>

Dictionary Algorithm

M T im LZSS
Nu c 2 k t ging tr ln th mi chp trong t in ra <0,i,j> Ch c 1 k t ging hoc khng c k t ging <1,k>

VD: m ha AABBCBBAABC Bc 1 2 3 4 5 6 7 8 V tr 1 2 3 4 5 6 8 11 K t ging A B BB ABB C Ng ra <1,A> <1,A> <1,B> <1,B> <1,C> <0,3,2> <0,7,3> <1,C>

Dictionary Algorithm

The End

05

Hamming Code