You are on page 1of 21

CHNG 5 X L S LIU TRUYN I.

M HA S LIU MC VT L S liu cung cp t my tnh hoc cc thit b u cui s liu thng dng nh phn n cc (unipolar) vi cc bit 0 v 1 c biu din cng mc in p m hoc dng. Tc truyn dn ca chng c tnh bng s bit truyn trong mt giy. Cc s liu ny khi truyn i s c bin i sang dng tn hiu vi cc k thut m ha khc nhau. Cc tn hiu ny c c trng bng s thay i mc in hoc tc truyn ca chng v th chng c xc nh bng tc ca s thay i ny, cn c gi l tc iu ch v c tnh bng Baud. 1. M ha NRZ (Non Return to Zero Level): NRZ l mt k thut m ha knh gip chuyn cc gi tr logic bit thnh cc xung in c th truyn qua ng truyn hu tuyn. M ha NRZ l trong thi gian mt bit tn hiu khng tr v mc 0, dng trong trng hp lu d bng vt liu bng t tinh. t dng trong truyn s liu 2. M nh phn a mc S dng nhiu hn 2 mc tn hiu cho 1 bit: Mc 0 khng c tn hiu, 1 c tn hiu v tn hiu o cc gia 2 bit 1 lin tip. (lng cc o bit 1) Hoc 1 khng c tn hiu, 0 c tn hiu v tn hiu o cc gia 2 bit 0 lin tip hoc (lng cc o bit 0) 3. M lng cc M ha bng cch dng hai cc in hoc hai cc t du khc nhau, t cch nhau mt khong nh. Phng php ny thc hin chuyn i xung 0 v 1 ca tn hiu nh phn thnh xung ca 2 cc +A v -A. c tnh ca loi m ny l khng tn ti thnh phn mt chiu v x dng lun phin +A, -A c th pht hin li II. PHT HIN LI V SA SAI. 1. Tng quan Khi d liu c truyn gia 2 DTE, cc tn hiu in i din lung bit truyn rt d b thay i sai s do nhiu nguyn nhn : ng dy truyn, lu lng truyn, loi m ng, loi iu ch, loi thit b pht, thit b thu, c bit l do s thm nhp in t

cm ng ln cc ng dy t cc thit b in gn , Nu cc ng dy tn ti trong mt mi trng xuyn nhiu th d nh mng in thoi cng cng. iu ny c ngha l cc tn hiu i din cho bit 1 b u thu dch ra nh bit nh phn 0 v ngc li. xc sut thng tin thu c bi DTE ch ging thng tin truyn t c gi tr cao, cn phi c mt vi bin php ni thu c kh nng nhn bit thng tin thu c c cha li hay khng, nu c li s c mt c cu thch hp thu v bn copy chnh xc ca thng tin. chng sai khi truyn s liu thng c 2 cch : Dng b gii m c kh nng t sa sai Truyn li mt b phn ca d liu thc hin vic sa sai, cch ny gi l ARQ Automatic Repeat Request . 2. Phng php kim tra chn l theo k t ( parity bit ) Phng php thng dng nht c dng pht hin li ca bit trong truyn khng ng b v truyn ng b hng k t l phng php parity bit. Vi cch ny my pht s thm vo mi k t truyn mt bit kim tra parity c tnh ton trc khi truyn. Khi nhn c thng tin truyn, my thu s thc hin cc thao tc tnh ton trn cc k t thu c , v so snh vi bit parity thu c. Nu chng bng nhau th c gi s l khng c li, y ta dng t gi s, bi v cch ny c th khng pht hin c li trong khi li vn tn ti trong d liu. Nhng nu chng khc nhau th chc chn mt li xy ra . tnh ton parity bit cho mt k t, s cc bit trong m k t c cng module 2 vi nhau v parity bit c chn sao cho tng s cc bit 1 bao gm c parity bit l chn (even parity) hoc l l (odd parity) Trong b m ASCII mi k t c 7 bit v mt bit kim tra Vi kim tra chn gi tr ca bit kim tra l 1 nu s lng cc bit c gi tr 1 trong 7 bit l l v c gi tr 0 trong trng hp ngc li. Vi kim tra l th ngc li. Thng thng ngi ta s dng kim tra chn v bit kim tra gi l P. Gi tr kim tra cho php u thu pht hin nhng sai st n gin Th d K t M ASCII T m pht i Bit kim tra P A 1000001 10000010 0 E 1010001 10100011 1 Phng php parity bit ch pht hin cc li n bit (s lng bit li l s l )v khng th pht hin cc li 2 bit (hay s bit li l mt s chn)

3. Phng php kim tra theo ma trn Khi truyn i mt khi thng tin, mi k t c truyn i s c kim tra tnh chn l theo chiu ngang, ng thi c khi thng tin ny cng c kim tra tnh chn l theo chiu dc. C sau mt s byte nht nh th mt byte kim tra chn l cng c gi i, byte chn l ny c to ra bng cch kim ta tnh chn l ca khi k t theo ct. Da vo cc bit kim tra ngang v dc ta s xc nh c to ca bit sai v sa c bit sai ny Chng ta c th thy rng mc d cc li 2 bit trong mt k t s thot khi kim tra parity theo hng, nhng chng s b pht hin bi kim tra parity theo ct tng ng. D nhin iu ny l ng ch khi khng c li 2 bit xy ra trong cng mt ct ti cng thi im. R rng xc sut xy ra trng hp ny nh hn nhiu so vi xc sut xy ra li 2 bit trong mt k t. Vic dng kim tra theo ma trn ci thin ng k cc c trng pht hin li ca kim tra chn l V tr bit truyn 1 2 3 Kim tra p theo ct Dy bit truyn i 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 1 1 0 1 0 1 0 Kim p theo hng 0 1 0 0

V d: sau khi truyn nhn c dy truyn nh di y da vo s thay i ca cc bit p dc v ngang s xc nh c v tr li tng ng (hnh di) V tr bit truyn 1 2 3 Kim tra p theo ct Dy bit truyn i 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 0 1 0 Kim p theo hng 1 0 0 0

Tuy nhin phng php ny cng khng hon ton hiu qu. Gi s bit th nht v bit th 3 ca k t th nht b sai kim tra hng s khng b sai, nhng kim tra chn l ca ct s pht hin b sai, nhng khng xc nh c v tr sai ??? V tr bit truyn 1 Dy bit truyn i 1 0 0 0 1 0 0 Kim p theo hng 0

2 3 Kim tra p theo ct

1 1 1

0 0 0

0 1 1

1 0 1

0 0 1

1 1 0

0 1 0

1 0 1

By gi ta lai gi thit rng bit th nht v bit th 3 ca k t th 3 cng b sai ng thi v bit th nht v bit th 3 ca k t th nht, lc kim tra chn l ca ct v hng u khng thy sai nn khng pht hin c sai??? V tr bit truyn 1 2 3 Kim tra p theo ct Dy bit truyn i 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 1 0 1 0 0 1 1 0 0 0 0 0 Kim p theo hng 0 1 0 0

4. Phng php m d tha - m vng (CRC) Mt t m c vit di dng mt a thc C(x) = Cn-1 Xn-1+ Cn-2 Xn-2+ ......+ C1 X + C0 Phng php kim tra tn hiu bng m vng c thc hin nh sau : Tn hiu cn pht i gm k bit s c bn pht thm vo n bit na kim tra c gi l Frame Check Sequence (FCS). Nh vy tn hiu pht i bao gm k+n bit. Bn thu khi nhn c tn hiu nay s em chia cho mt a thc c gi l a thc sinh bit trc ( bn pht v bn thu u cng chn a thc ny ). Nu kt qu chia khng d coi nh tn hiu nhn c l ng. Vn c t ra l n bit thm vo s c xc nh nh th no khi bit khung tin cn truyn i, v bit a thc sinh c chn, n bit thm vo c gi l CRC (Cyclic Redundancy Check). Phng php to ra CRC bao gm vic dch thng bo sang tri c bit ( c chnh l bc ca a thc chn trc) sau thc hin php chia cho a thc c chn ny . Kt qu d li ca php chia chnh l CRC. Bn thu sau khi nhn c thng bo cng em chia cho hm bit trc nh bn pht. Nu kt qu bng 0. php truyn khng sai s. Tnh xu phi truyn i FCS theo 4 bc: Bc 1: Chuyn thng bo nh phn thnh a thc M(x), sau chn a thc sinh cho trc G(x) = Xc + 1 c bc cao nht l c (c l di ca xu kim tra CRC) Bc 2: Nhn M(x) vi Xc

Bc 3: Thc hin M(x)*Xc/G(x) c kt qu l thng Q(x) v s d R(x). R(x) chnh l xu kim tra CRC Bc 4: Thnh lp xu truyn i l: M(x)*Xc +R(x) V d: xu cn truyn l: 110101 hy s dng phng php m CRC kim tra li khi truyn Gii: Bc 1: Dy nh phn 110101 c th c dng a thc l M(x) = X5 + X4 + X2 +1 Bc 2: Chn a thc sinh c s m l 3: G(x) = X3 + 1 Bc 3: Tnh M(x)*X3/G(x) = Q(x) + R(x) = (X8 + X7 + X5 + X3)/X3 + 1

Kt qu cho: Q(x) = X5 +X4 + X + 1 R(x) = X + 1 Xu kim tra CRC l: X +1 = 011 (di 3 k t) Bc 4: Xu phi truyn c m CRC l: M(x)*Xc + CRC = 110101011 Thu v kim tra CRC kim tra sai s khi truyn bn thu em khi thng tin thu c chia cho G(x) theo modul 2, nu s d nhn c l 0 th truyn ng, ngc li d liu b truyn sai V d: Thng tin truyn i l: 110101011 Thng tin nhn c l: 110101011 C ngha thng tin truyn ng tc l R(x) = 0 Kim tra CRC nh sau: Chuyn thng tin nhn c thnh a thc: x8 +x7 +x5 + x3 + x1 + 1 a thc sinh ca hai bn pht v thu l: G(x) = x3 + 1 Chia a thc nhn c cho G(x), kt qu R(x) = 0, vy khng c truyn sai

5: Pht hin v sa sai theo m Hamming M Hamming l mt m sa li tuyn tnh c t tn theo tn ca ngi pht minh ra n, Richard Hamming. M Hamming c th pht hin v sa c sai cho mt s bit nht nh a) Nguyn tc: Mt t m Hamming gm m bit nh phn d liu v p bit kim tra chn l (2p -1 m + p), p bit kim tra c b tr ti cc v tr thch hp pht hin chnh xc v tr li l cc s m ca 2 v d: 20, 21, 22, Tt c cc v tr bit khc c dng cho d liu s c m ha. (cc v tr 3, 5, 6, 7, Mi bit chn l tnh gi tr chn l cho mt s bit trong m bit. V tr ca bit chn l quyt nh chui cc bit m n lun phin kim tra v b qua o V tr 1 (n=1): b qua 0 bit(n-1), kim 1 bit(n), b qua 1 bit(n), kim 1 bit(n), b qua 1 bit(n), v.v. p1 (20) o V tr 2(n=2): b qua 1 bit(n-1), kim 2 bit(n), b qua 2 bit(n), kim 2 bit(n), b qua 2 bit(n), v.v. p2 (21) o V tr 4(n=4): b qua 3 bit(n-1), kim 4 bit(n), b qua 4 bit(n), kim 4 bit(n), b qua 4 bit(n), v.v. p3 (22) o V tr 8(n=8): b qua 7 bit(n-1), kim 8 bit(n), b qua 8 bit(n), kim 8 bit(n), b qua 8 bit(n), v.v. p4 (23) o V tr 16(n=16): b qua 15 bit(n-1), kim 16 bit(n), b qua 16 bit(n), kim 16 bit(n), b qua 16 bit(n), v.v. (24) o V tr 32(n=32): b qua 31 bit(n-1), kim 32 bit(n), b qua 32 bit(n), kim 32 bit(n), b qua 32 bit(n), v.v. (25) o v tip tc nh trn.

Xc nh v tr li bng cch ly mudul 2 (xor) ca cc bit chn l ca d liu sau v trc khi truyn nu = 0 th khng c li, ngc li th v tr li l kt ca php mdul 2 chuyn sang h thp phn. b) V d 1: cho m bit d liu cn truyn l: 0110101 hy chn cc bit cn thit vo theo phng php m sa sai Hamming. (cho bit dy truyn t phi sang tri ) Gii: - m = 7, p = 4 (2p -1 7 + 4) cc bit p1, p2, p3, p4 c b tr vo cc v tr 1,2,4,8 - Cc v tr 3,5,6,7,9,10,11 l cc bit d liu - Xc nh p1, p2, p3, p4 theo thut ton kt qu l: 1000 p1= 01011 = 1 (xor) p2= 01001 = 0 p3= 110 = 0 p4= 101 = 0 - Ri cc bit va tnh c vo trong xu gc ta c xu cn truyn l: 10001110010

Xc nh v tr bit li nh sau: - Gi s sau khi truyn nhn c dy nh phn l: 10001100100.

- Bng cch xc nh cc bit chn l p1, p2, p3, p4 nh trn ta c: p1=0, p2=1, p3=0, p4=1 - Thc hin php xor cc bit chn l trc v sau khi truyn ( ch phi vit ngc li) P4 p3 p2 p1 1 0 1 0 Xor 0 0 0 1 1 0 1 1 = 11(10) v tr li l 11 c) v d 2: Cho chui bit gc m = 1101100111, hy chn cc bit cn thit vo theo

phng php m sa sai Hamming. (cho bit dy truyn t tri sang phi ) Gii: - m = 10, p = 4 (24 -1 > 10 + 4) cc bit p1, p2, p3, p4 c b tr vo cc v tr 1,2,4,8 - Cc v tr 3,5,6,7,9,10,11,12,13,14 l cc bit d liu - Xc nh p1, p2, p3, p4 theo thut ton kt qu l: p1= 110011 = 0 p2= 110111 = 1 p3= 110110 = 0 p4= 011011 = 0 Ri cc bit va tnh c vo trong xu gc ta c xu cn truyn l: 11011000110110 Gi s sau khi truyn xu nhn c l: 1 1 0 1 1 0 0 1 1 1 0 1 1 0 hy xc nh v tr li
Tm p1, p2, p3, p4 ca xu nhn: P1 = 111011 = 1 P2 = 111111 = 0 P3 = 111011 = 1

P4 = 011011 = 0 - V tr li l 0 1 0 Xor 0 0 1 1

p4 p3 p2 p1 1 0 1 0 1 V tr li l 7

III. MT M HA S LIU 1. Khi qut ng truyn s liu trong mt s trng hp cn phi c bo mt, th d nh quc phng, ngn hng .v.v..Nh vy ngoi cc bin php x l s liu cn thit truyn thnh cng v hiu qu, s liu cn c mt m ha bng phng php no , theo mt kha m no m ch my pht v my thu mi bit c. Qu trnh mt m ha v gii m thng c thc hin tng lin kt s liu (Data link). Tuy nhin cng c nhng vi mch c ln chuyn thc hin mt m ha v gii m s liu. Cc chip ny cho php ngi s dng thay i cc gii thut mt m phc tp vi rt nhiu kha khc nhau la chn. Ngy nay mt m ha mc vt l cng c quan tm nhiu, c bit l mt m ha theo ng cng ngh, mt s phng php li dng cng ngh cao tin hnh mt m n, thm m mun bit bn gc phi t c trnh cng ngh tng ng mi c th thc hin c. 2. Mt m ha c in Bn gc s c m ha bng mt kha c xc nh trc to ra mt bn m. Bn m chnh l bn c truyn ln knh. Khi thm nhp vo knh, i phng c th thu trm c bn m nhng v khng bit kha m nn kh tm ra c bn gc. V mt ton hc c th m phng mt m c in nh sau : Mt h thng m ha l mt tp c 5 thnh phn (P,C,K,E,D) trong : P l tp hp hu hn cc bn gc c th C l tp hp hu hn cc bn m c th K l tp hp kha c th. E tp hp cc lut mt m D tp hp cc lut gii m i vi mi k thuc K c mt lut mt m eK : P C; eK thuc E v mt lut gii m tng ng dK: C P, dK thuc D. Mi eK v dK l nhng nh x sao cho dK(eK (x))=x vi mi x thuc P

Gi s thng tin gc cn truyn l mt chui x1, x2, x3, x4xn vi n l mt s nguyn ln hn hoc bng 1. Mi k hiu xi (1 i n) c mt m bng lut mt m eK vi kha K thng nht vi bn thu. Ni pht s xc nh cc y theo y= eK (xi) v bn m s pht ln knh l y = y1, y2, y3,y4.yn. pha thu hp l, s tm ra bn gc bng cch dng nh x dK(yi)=xi, ch eK v dK phi l cc nh x 1-1, ngha l vi x1 x2 th y1 y2. C nhiu phng php mt m c in sau y chng ta xt mt phng php m dch vng. Phng php ny c c s l php ton module (chia d bao nhiu ). minh ha ta xt vic mt m ha trn b ch ci ting Anh gm 26 ch ci. Dng php module 26 nh sau : eK (x) =x+K module 26 (lut mt m eK ca phn t x) dK (x) =x - K module 26 (lut gii m dK ca phn t x) Bng 5.1. S tng ng ca cc ch ci v cc s theo module 26 nh sau

Th d : Gi s kha m dch vng ny l K= 9 v bn gc l : Gonewththewind Mt m ha nh sau : Trc ht chng ta bin i bn gc thnh chui cc s nguyn theo php ly tng ng trn bng 5.1 ta c : 6 14 13 4 22 8 19 7 9 7 4 22 8 13 3 Sau cng thm 9 vo mi gi tr ri thc hin module 26 (ly s d ca php chia cho 26), kt qu cho dy sau: 15 23 22 13 5 17 2 16 2 16 13 5 17 22 12 T chui cc gi tr ny ly cc gi tr tng ng trong bng 5.1 ta c m truyn i l: pxwnfreqcqnfrwm Gii m: bng cch i thnh cc dy tng ng trong bng 5.1, sau tr 9 v ly module 26 v i thnh cc gi tr tng ng. kt qu chnh l bn gc 3. M ha cng khai

Mt trong nhng phng php mt m ha hin i l mt m kha cng khai. Phng php mt m ny ng dng tnh cht c bit ca cc hm by sp mt chiu tng kh v gy cn tr hot ng ca thm m. H mt m kha cng khai da trn logarit ri rc c dng kh ph bin v c gi l h mt m Elgamal. Thut ton: Mi u lin lc to mt kha cng khai v mt kha b mt tng ng Bc 1: To mt s nguyn t p v mt phn t sinh Bc 2: Chn mt s ngu nhin a: 1 a p-2 v tnh a mod p Bc 3: Kha cng khai l b 3 s (p, , a), kha b mt l a Ni thu hp l bit c a s suy din ra c bn ghi gc.

Cc bc m ha: Bc 1: Nhp kha cng khai Bc 2: Biu din bn tin di dng tp hp cc s nguyn {1,1,p-1} Chn s ngu nhin k: 1 k p-2 Tnh 2 phn ca bn m: y1 = k mod p; y2 = x* k mod p (nh du bn gc) Gi bn tin c m ha = (y1,y2) Cc bc gii m: S dng kha b mt a tnh y1p-1-a mod p (= y1-a) Khi phc bn gc = y2* y-a mod p Ni thu hp l bit c a s suy din ra c k t k sau s chia y2 cho k c x V d 1: Gi s mun gi bn tin x = 1299 c m ha cng khai Nhp kha cng khai: p = 2579, cho = 2, a = 765, = 2765 mod 2579 = 949 ( = a) Biu din bn tin bi b 3 (p= 2579, =2, =949) l cc kha cng khai, a l kha b mt Chn s ngu nhin k = 853 Tnh y1, y2: y1= 2853 mod 2579 = 435 (phn th nht gi i) y2= 1299*949853 mod 2579 =2396 (phn th hai gi i) Bn tin c m ha v truyn i l (435, 2396)

Gii m nh sau: u thu khi nhn c bn m y =(435,2396) s s dng m b mt a = 765 tnh ra bn gc nh sau

Tnh Y1p-1-a = 435-765 mod 2579 ( = y1-a) Bn gc l X = 2396*435-765 mod 2579 = 1299 V d 2: Gi s mun gi bn tin x = 2305 c m ha cng khai Nhp kha cng khai: p = 2357, = 2, a = 1751, = 21751 mod 2357 = 1185 ( = a) Biu din bn tin bi b 3 (p= 2357, =2, =1185) l cc kha cng khai, a l kha b mt Chn s ngu nhin k = 1520 Tnh y1, y2: y1= 21520 mod 2357 = 1430 (phn th nht gi i) y2= 2035*11851250 mod 2357 = 697 (phn th hai gi i) Bn tin c m ha v truyn i l (1430, 697)

Gii m nh sau: u thu khi nhn c bn m y = (1430, 697) s s dng m b mt a = 1751 tnh ra bn gc nh sau Tnh Y1p-1-a = 1430-1751 mod 2357 ( = y1-a) Bn gc l X = 697*1430-1751 mod 2357 = 2035 IV. NN S LIU 1. Khi qut Ni dung thng tin truyn i bao gm d liu gc di dng chui k t c chiu di c nh. Trong d liu c nn trc khi truyn i, nn d liu l mt vic lm thit yu trong cc dch v truyn dn cng cng, v d truyn qua mng PSTN, v trong cc mng cc mng nh vy vic tnh cc da vo thi gian v c ly truyn. . Trong thc t chng ta c th dng mt lot cc gii thut nn khc nhau, mi gii thut s ph hp vi mt loi d liu. Vi modem thng minh s cung cp c trng nn thch nghi t ng thc hin cc gii thut nn ph hp vi loi d liu ang c truyn 2. Nn nh n gin m cho cc ch s (Packed decimal )

Khi d liu ch bao gm cc k t s hc ang c truyn, chng ta c th tit kim ng k bng cch gim s bit trn mi k t t 7 xung 4 thng qua m BCD, thay cho m ASCII v cc s t 0 9 u c 3 bit cao l 011 (thc t 3 bit ny dng phn bit gia k t l s v khng phi l s). Do vy nu d liu ch l cc k t s th 3 bit ny l d tha 3. Nn theo m ha quan h. Mt phng php khc c s dng khi truyn d liu s hc k tip ch khc nhau phn nh v gi tr l ch gi lng khc nhau gia cc gi tr ny cng vi mt gi tr tham kho. iu ny c gi l m ha quan h v n c th em li hiu qu c bit trong cc ng dng ghi nhn d liu. Th d nu gim st t xa mc nc ca dng sng thng c mc nc theo cc khong thi gian nh trc . ti thiu thi gian cn truyn thay v truyn gi tr ch mc nc tuyt i, chng ta ch cn truyn i cc gi tr khc nhau. 4. Nn bng cch b bt cc k t ging nhau (m ho di lot (Run-Length Encoding)) Thng thng d liu c truyn thng xut hin chui lp li cc k t ging nhau. Thit b iu khin ti my pht s qut ni dung ca d liu trc khi truyn nu gp mt chui k t lin tip ging nhau th chng s c thay th bi mt cp s v k t. V d, xt chui sau: AAAABBBAABBBBBCCCCCCCCDABCBAAABBBBCCCD Chui ny gm bn ch A theo sau bi ba ch B ri li theo sau bi hai ch A, ri li theo sau bi nm ch B...Do c th s dng phng php m ho di lot m ha. V vy chui k t trn c m ho li nh sau: 4A3BAA5B8CDABCB3A4B3CD. "4A" c ngha l "bn ch A"... Ch l khng nn m ho cc lot chy c di 1 hoc 2 v cn n hai k t m ho. i vi cc tp tin nh phn tng y l lu li cc di lot bng cch tn dng s kin cc lot chy c thay i gia 0 v 1. V d dy nh phn 1010 c biu din bi cp s m v k t th l nh sau 11101110 nhng trnh phi lu chnh cc s 0 v 1 , mt phin bn c tinh ch ca phng php ny c dng thu c s tit kim ng k, lc ny dy nh phn trn s c biu din l 1010 (tit kim c 4 k t dng lm s m). C ngha l ta tit kim cc bit trn mt lot chy ch khi di ca ng chy l ln hn s bit cn biu din chnh n trong dng nh phn

Vic m ho di lot cn n cc biu din ring bit cho tp tin v cho bn c m ho ca n, v vy n khng th dng cho mi tp tin, v d, phng php nn tp tin k t s khng dng c i vi cc chui k t c cha s. Nu dng nhng k t khc m ho cc s m, th n s khng lm vic vi cc chui cha cc k t . V d nh ta phi m ho bt k k t no trong mt bng ch ci c nh bng cch ch dng cc k t t bng ch ci . Gi nh rng ta ch c 26 ch ci trong bng ch ci (v c khong trng) lm vic. c th dng vi ch ci biu din cc s v cc k t khc biu din cc phn t ca chui s c m ho, ta phi chn mt k t c gi l k t "Escape". Mi mt s xut hin ca k t bo hiu rng hai ch ci tip theo s to thnh mt cp (s m, k t) vi cc s m c biu din bng cch dng k t th i ca bng ch ci biu din s i. V vy, chui v d ca chng ta s c biu din nh sau vi Q c xem l cc k t "Escape" QDABBBAABQHCDABCBAAAQDBCCCD (QDA c ngha l 4 ch A, QHC c ngha l 8 ch C ) T hp ca k t "Escape", s m v mt k t lp li c gi l mt dy Escape. Ch rng khng ng m ho cc ng chy c chiu di t hn bn k t, v t nht l cn n ba k t m ho bt k mt lot chy no. Trong trng hp bn thn k t "Escape" xut hin trong dy k t cn m ho ta s phi dng mt dy "Escape" vi s m l 0 (k t space) biu din k t cho "Escape".. v d khi vit QEQCA (5 ch Q, 1 ch C 1 ch A nhng cng c th hiu l 5 ch Q, 3 ch A), lc ny mun biu din 5 ch Q, 1 ch C 1 ch A th phi vit l Q0QQ0QQ0QQ0QQ0QCA ??? (tri t!!!!!!) Nh vy trong trng hp k t "Escape" xut hin nhiu th c th s lm cho tp tin nn phnh to hn trc Cc lot chy di c th c ct ra m ho bng nhiu dy Escape, v d, mt lot chy gm 51 ch A s c m ho nh QZAQYA (z = 26, y = 25). Phng php m ho di lot thng c p dng cho cc tp tin ho bitmap v thng c cc mng ln cng mu c biu din di dng bitmap l cc chui bit c ng chy di. Trn thc t, n c dng trong cc tp tin .PCX, .RLE. 5. Phng php m ho Huffman (dng m ha thng k) a) M tin t (prefix-free binary code)

Chng ta vn m ha cc k hiu bng cc xu nh phn vi di khng i, c gi l t m ca k hiu . Chng hn b m ASCII, m ha cho 256 k hiu l biu din nh phn ca cc s t 0 n 255, mi t m gm 8 bt. Khi m ha mt ti liu c th khng s dng n tt c 256 k hiu, hn na s ln xut hin ca cc k t l khc nhau. Do ta c th khng cn dng ht 8 bt m ha cho mt k hiu, hn na di (s bt) dnh cho mi k hiu c th khc nhau, k hiu no xut hin nhiu ln th nn dng t bt m ha, k hiu no xut hin t th dng nhiu bt m ha. Tuy nhin, nu m ha vi di thay i, khi gii m ta lm th no phn bit c xu bt no l m ha ca k hiu no. Mt trong cc gii php l dng cc du phy (",") hoc mt k hiu quy c no tch t m ca cc k t ng cnh nhau. Nhng nh th s cc du phy s chim mt khng gian ng k trong bn m. Mt cch gii quyt khc dn n khi nim m tin t M tin t l b cc t m ca mt tp hp cc k hiu sao cho t m ca mi k hiu phi khng l tin t (phn u) ca t m ca mt k hiu no trong b m y. V d: Gi s m ha t "ARRAY", k hiu cn m ha l 3 ch ci: "A", "R", "Y". Nu m ha bng cc t m c di bng nhau ta phi dng t nht 2 bit cho mt ch ci chng hn "A"=00, "R"=01, "Y"=10. Khi m ha ca c t l 0001010010. gii m ta c hai bit mt v i chiu vi bng m.

Nu m ha "A"=0, "R"=01, "Y"=11 th b t m ny khng l m tin t v t m ca "A" l tin t ca t m ca "R". Lc ny m ha c t ARRAY phi t du ngn cch vo gia cc t m 0,01,01,0,11
Nu m ha "A"=0, "R"=10, "Y"=11 th b m ny l m tin t. Vi b m tin t ny khi m ha xu "ARRAY" ta c 01010011.

b) Biu din m tin t trn cy nh phn Nu c mt cy nh phn n l ta c th to mt b m tin t cho n k hiu bng cch t mi k hiu vo mt l. T m ca mi k hiu c c to ra khi i t gc ti l cha k hiu , nu i qua cnh tri th ta thm s 0, i qua cnh phi th thm s 1. V d: Cy 3 l sau y biu din b m ca A,R,Y trong v d trn

c) M Huffman L cch xy dng cy m tin t ti u ca Huffman (nm 1952) Cc bc xy dng b m Huffman: Dng cy t di ln, xut pht vi cc nt l Cc nt l biu din cc k t v tn sut xut hin ca k t trong vn bn Cc nt trong c 2 nhnh tng ng vi : 0 l nhnh bn tri v 1 l nhnh bn phi. Cc nt ny cha tng tn sut xut hin ca cc nt trong cc nhnh con ca n Mt ng i t nt gc n nt l chnh l mt m nh phn biu din k t nt l K t c tn sut ln s xut hin mc thp hn, k t c tn sut nh s xut hin mc cao hn trong cy m Huffman V d: cho dy k t cn truyn l: abcdef v tn xut xut hin tng ng cho trong bng. Hy xy dng b m Huffman Dy k t cn m ha Tn xut xut hin f 5 e 9 c 12 b 13 d 16 a 45

Di y l cc bc xy dng cy Huffman

B m Huffman l: a=0 ( duyt t gc) c = 100 e = 1101 f = 1100 d) M ha bng b m Huffman

b = 101 d = 111

Cc bc m ha: Bc 1: Duyt vn bn cn m ha v xc nh tn sut xut hin ca cc k t Bc 2: Sp xp cc k t da trn tn sut xut hin ca chng trong vnbn Bc 3: Xy dng cy m Huffman da trn dy c sp. Bc 4: Duyt cy xc nh m ca cc k t Bc 5: Duyt vn bn cn m ha v sinh vn bn m ha s dng m c c bc 4

V d trn c m ha bng cui nh phn sau: 010110011111011100 e) Gii m Huffman Xut pht t gc ca cy c m ha c ln lt tng k t trong xu m ha t tri sang Nu l 0 : i sang tri Nu l 1: i sang phi Nu chm ti mt nt l ghi k t cha ti nt l ra, sau quay li nt gc ca cy m ha. V d: - Ln c u tin: 0, sang tri, chm nt l a k t a. Ri quay li gc duyt tip - Ln c th hai: 1, sang phi, cha gp nt l, 0 sang tri, cha gp nt l, 1 sang phi, gp nt l b k t b. Ri quay li gc duyt tip - Ln c th 3: 1, sang phi, cha gp nt l, 0 sang tri, cha gp nt l, 0 sang tri gp nt l l c k t c. Ri quay li gc duyt tip - Qu trnh s dng khi duyt ht cy 6. Phng php nn LZW ( cu trc t) Phng php nn LZW c pht minh bi Lempel - Zip v Welch. N hot ng a trn mt tng rt n gin l ngi m ho v ngi gii m cng xy dng bn m. * Nguyn tc hot ng ca n nh sau: - Mt xu k t l mt tp hp t hai k t tr ln. - Nh tt c cc xu k t gp v gn cho n mt du hiu (token) ring. - Nu ln sau gp li xu k t , xu k t s c thay th bng du hiu ca n. Phn quan trng nht ca phng php nn ny l phi to mt mng rt ln dng lu gi cc xu k t gp (Mng ny c gi l "T in"). Khi cc byte d liu cn nn c em n, chng lin c gi li trong mt b m cha (Accumulator) v em so snh vi cc chui c trong "t in". Nu chui d liu trong b m cha khng c trong "t in" th n c b sung thm vo "t in" v ch s ca chui trong "t in" chnh l du hiu ca chui. Nu chui trong b m cha c trong "t in" th du hiu ca chui c em ra thay cho chui dng d liu ra. C bn qui tc thc hin vic nn d liu theo thut ton LZW l:

Qui tc 1: 256 du hiu u tin c dnh cho cc k t n (000h 0FFh). Qui tc 2: C gng so snh vi "t in" khi trong b m cha c nhiu hn hai k t. Qui tc 3: Cc k t u vo (Nhn t tp tin s c nn) c b sung vo b m cha n khi chui k t trong b m cha khng c trong "t in". Qui tc 4: Khi b m cha c mt chui m trong "t in" khng c th chui trong b m cha c em vo "t in". K t cui cng ca chui k t trong b m cha phi li trong b m cha tip tc to thnh chui mi. V d: Cc bc m ho chui "!BAN!BA!BAA!BAR!" nh sau (Bng 4. 1): - bc 1: K t th nht ! c ct vo b m cha chun b to nn mt chui. - bc 2: K t th hai B ni thm vo sau k t !. V trong "t in" cha c chui "!B" nn chui ny c thm vo "t in" v c gn du hiu l 100h (V t 000h n 0FFh c dnh ring cho cc k t n: Qui tc 1). ! c gi ra cn B phi li trong b m cha.

- bc 3: K t th ba A thm vo sau B. Chui "BA" cng cha c trong "t in" nn n c thm vo "t in" v gn du hiu l 101h. A li trong b m cha cn B c gi ra. - bc 4: K t th t N thm vo sau A to thnh chui "AN" cng cha c trong "t in" nn c thm vo "t in" v c du hiu l 102h. N li trong b m cha cn A c gi ra. - bc 5: K t th nm ! thm vo sau N to thnh chui "N!", "N!" c thm vo "t in" vi du hiu l 103h. ! li cn N c gi ra. - bc 6: K t th su B thm vo sau !. Ln ny th chui "!B" c trong "t in" nn khng c k t no c gi ra. "!B" tip tc li trong "t in" to ra chui mi. - bc 7: K t th by A thm vo sau B to thnh chui "!B!A", do "!BA" khng c trong "t in" nn n c thm vo "t in" v gn du hiu l 104h ng thi du hiu 100h c gi ra thay cho "!B" (Qui tc 4). A tip tc li trong b m cha to thnh chui mi. Cc bc trn c th tip tc cho n khi ht tp tin cn nn. Vic gim kch thc ch thc s bt u ti bc 7 khi m mt du hiu 12 bits l <100h> c gi ra thay cho hai byte "!B". Trong thut ton nn ny, phn ln thi gian khi bt u nn ch yu mt vo vic to "t in". Khi "t in" ln, xc sut gp chui b m cha trong "t in" tng ln v cng nn c nhiu hn. Mt iu cn ch y l mi mt du

hiu, ta phi lu mt chui trong "t in" so snh. V du hiu c biu din bng mt s 12 bits nn "t in" s c 4096 li vo, khi tng s bit d biu din du hiu ln th hiu qu nn s tt hn nhng li b gii hn bi b nh ca my tnh. V d, khi dng 16 bits biu din mt du hiu th "t in" phi c n 65536 li vo, nu mi li vo c khong 20 k t th "t in" phi ln khong 1,2 MB. Vi mt t in c dung lng nh vy rt kh c th thc hin trn cc my tnh PC hot ng di h iu hnh DOS v gii hn ca mt on (Segment) l 64KB. u im ca phng php nn LZW l bn nhn c th t xy dng bng m m khng cn bn gi phi gi km theo bn tin nn. * Gii nn: Qu trnh gii nn LZW cng khng c g phc tp. Thm vo n c nhiu li th hn so vi cc phng thc nn tnh v khng cn mt t in hay nhng thng tin cn thit cho qu trnh gii nn. Mt t in mi kt hp ng nht vi t in gc to trong khi nn c ti to ngc li trong qu trnh gii nn. Qu trnh m ha v gii m cn phi s dng cng 1 t in khi u, trong trng hp ny l 256 k t ca bng m ASCII B gii m LZW trc ht c mt ch s (l 1 s nguyn), tm ch s trong t in, v cho ra chui con gn vi ch s . K t u tin ca chui con ny c cng thm vo chui ang lm vic. Chui mi to ra c thm vo t in (hon ton ging vi qu trnh nn). Chui c gii m li tr thnh chui ang lm vic v c th qu trnh ny c tip tc.