Está en la página 1de 14

CHNG 1 TM HIU V M HAMMING 1.

Gii thiu chung v m ha knh Tn hiu truyn qua knh truyn s b nh hng bi nhiu, can nhiu, fading l tn hiu u thu b sai. M ha knh dng bo v d liu khng b sai bng cch thm vo cc bit d tha (redundancy). tng ca m ha knh l gi mt chui bit c kh nng sa li. M ha knh khng lm gim li bit truyn m ch lm gim li bit d liu. 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 S m ha knh truyn tin:

Hnh 1.S m ha knh truyn tin

K hiu u v S(x) N(x) R(x) R 2. M Hamming

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

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 doublebit 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. 3.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. 3.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. 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: 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) .. Vd: 20,

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.

4. 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. V d, vi m=3, ma trn ca m [7,4] c vit di dng

1 0 0 1 0 1 1
H(3,7) = 0 1 0 1 1 1 0

0 0 1 0 1 1 1
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 kim tra xen k vi cc bit mang tin.

vic to cc m n gin, ta chn cc bit kim tra x, y, z cc v tr tng ng 2i vi i=0, 1, 2 ngha l ti cc v tr th nht, th hai v th t ca cc k hiu (i vi khi c 4 bit d liu): t=(x, y, u0 ,z, u1, u2, u3 ) a) To m:

0 0 1 0 1 1 1 0 0 1 1
t.Ht = | x y u0 z u1 u2 u3 | .

0 0 0 1 0

=0

1 1

1 1 1

z u .1 u .1 u .1 0 1 2 3 y .1 u0 .1 z .1 u2 .1 u3 .1 0 x.1 u0 .1 z .1 u1 .1 u3 .1 0

z u u u 1 2 3 y u u u 0 2 3 x u0 u1 u3
V d: Tin cn pht i l U = (u0, u1, u2, u3) = (1 0 1 1) Ta c: x = u0 + u 1 + u 3 = 1 + 0 + 1 = 0 y = u 0 + u2 + u3 = 1 + 1 + 1 = 1 z = u1 + u2 + u3 = 0 + 1 + 1 = 0

vy t m pht i s l : t = (0 1 1 0 0 1 1)

b) Gii m ti bn thu :
0 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1

s = r. Ht = |r0 r1 r2 r3 r4 r5 r6| . 1
1 1 1

= (S0, S1, S2)

s0 r3 r4 r5 r6 s1 r r2 r5 r6 1 s r r r r 0 2 4 5 2

V d: Tn hiu thu c l R = (r0, r1, r2, r3, r4, r5, r6) = (0 0 1 0 0 1 1) Khi : s0=1+0+1+1=1 s1=0+1+1+1=1 s2=0+1+0+1=0 Ta c S = (1 1 0), i sang thp phn th S = 6, tc l bt th 6 (tng ng vi r1) b li, o bt ny ta thu c chui bt ng l R = (0 1 1 0 0 1 1). 6. Kt lun.

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.

CHNG 2 M PHNG M HA KNH HAMMING BNG MATLAB S dng cng c Simulink: 1. Xy dng khi. u tin, t ca s ca chng trnh Matlab, g lnh simulink s dng cng c ny Sau , to ra mt file m phng mi bng cch vo File > New > Model (hoc s dng cm phm tt Ctrl + N) Tip theo, t ca s Simulink Library Browser, ly cc khi sau: Bernoulli Binary Generator: Khi ny to cc bit ban u. BPSK Modulator Baseband. BPSK Demodulator Baseband. AWGN Channel: Knh truyn l AWGN. Hamming Encoder: Khi m ha Hamming. Hamming Decoder: Khi gii m Hamming. Error Rate Calculation: Khi dng so snh li gia tn hiu gc v tn hiu sau khi qua knh AWGN c s dng m Hamming. Display: Khi dng hin th. Khi ny s hin th ra 3 i lng: T l li / bit Tng s bit b li. Tng s bit nhn. Ta c s khi m phng nh sau:

Hnh 2: S khi m phng h thng s dng m Hamming 2. Thit lp cc thng s cho mi khi. - Khi Bernoulli Binary Generator: Chc nng:L khi to ngun d liu nh phn ban u

Hnh 3: Thit lp thng s cho khi Bernoulli Binary Generator Trong mc tham s (parameter) gm: + probability of a zero ( xc sut s 0 xut hin)

+ initial seed (s bit ca chui u) + sample time (thi gian mu) + samples per frame (mu cho mi khung) - Khi BPSK Modulator Baseband v khi BPSK Demodulator Baseband cng cc tham s: + Phase offset = 0 + Samples per symbol = 1.

Hnh 4: Thit lp thng s cho khi BPSK Modulator Baseband v khi BPSK Demodulator Baseband - Khi Hamming Encoder (m ha Hamming) v Hamming Decoder (gii m Hamming) cng cc tham s: +Codeword Length ( di t m) N=7. + Message Length K ( di bn tin) l gfprimfd(3,'min').

Hnh 5: Thit lp thng s cho khi Hamming Encoder (m ha Hamming) v Hamming Decoder (gii m Hamming) - Khi Display (hin th) mc nh, ko to ra hin th ht c 3 thng s. + T l li / bit + Tng s bit b li. + Tng s bit nhn - Khi Error Rate Calculation thit lp thng s nh hnh v ( y, s lng bit li khi t n 100 th qu trnh m phng s dng li): Gm cc tham s:

Hnh 7: Thng s ca khi tnh ton li. 3. M phng. Sau khi thit lp cc thng s nh trn, ta tin hnh m phng bng cch vo Simulation > Start. Kt qu c hin th trn khi Display nh hnh sau:

Hnh 8a: M phng ng truyn d liu khi s dng m ha Hamming v khng s dng m ha Hamming vi chiu di t m 7 bit.

Hnh 8b: M phng ng truyn d liu khi s dng m ha Hamming v khng s dng m ha Hamming vi chiu di t m 15 bit.

Nhn xt: Vi vic truyn d liu s dng m ha Hamming v khng s dng m ha Hamming trn ta c kt qu sau :

Bng kt qu M Hamming Chiu di t m (bit) C C(7,4) C(15,11) 7 15 Khng C Khng C 27 27 1000 1000 Khng 1000 1000 Xc sut li bit (bit) S bit li (bit) Tng s bit truyn (bit)

0,000996 0,02689 1 0,006993 0,02697 7

Ch thch :C l c s dng m ha Hamming. Khng l khng s dng m ha Hamming. -Khi khng s dng b m ha Hamming trn ng truyn th xc sut li bit tng, s bt li/s bit truyn tng (trong c trng hp t trc li v khng t trc s li). -Khi s dng cc b m c di t m ln hn th t l li bit tng ln ngay c khi s dng m Hamming nhng tc m ha cng tng ln. -V kh nng sa li v pht hin li ph thuc vo khong cch Hamming Pht hin sai c t bit nu d t + 1. Sai c t bit nu d 2t + 1. Gii hn trn: M <= 2 m n / (tng xch ma ca t hp chp i ca n) trong i chy t 0 n t. Vi M l s t m ti a,n l chiu di t m,t l s lng bit c th sa sai.Gii hn di: 2 m r >= tng xch ma t hp chp i ca n ,i chy t 0 n n. r l s bit kim tra vi chiu di t m n v k bit thng bo th r=n-k.