hamming code - courses.cs.washington.edu · hamming code • gives a method for construc=ng a code...

46
CSE 461 University of Washington 1 Hamming Code Gives a method for construc=ng a code with a distance of 3 Uses n = 2 k – k – 1, e.g., n=4, k=3 Put check bits in posi=ons p that are powers of 2, star=ng with posi=on 1 Check bit in posi=on p is parity of posi=ons with a p term in their values Plus an easy way to correct [soon]

Upload: phungdien

Post on 28-Apr-2019

258 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 1

HammingCode•  Givesamethodforconstruc=ngacodewithadistanceof3–  Usesn=2k–k–1,e.g.,n=4,k=3–  Putcheckbitsinposi=onspthatarepowersof2,star=ngwithposi=on1

–  Checkbitinposi=onpisparityofposi=onswithaptermintheirvalues

•  Plusaneasywaytocorrect[soon]

Page 2: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 2

HammingCode(2)•  Example:data=0101,3checkbits–  7bitcode,checkbitposi=ons1,2,4–  Check1coversposi=ons1,3,5,7–  Check2coversposi=ons2,3,6,7–  Check4coversposi=ons4,5,6,7

_______ 1234567

Page 3: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 3

HammingCode(3)•  Example:data=0101,3checkbits–  7bitcode,checkbitposi=ons1,2,4–  Check1coversposi=ons1,3,5,7–  Check2coversposi=ons2,3,6,7–  Check4coversposi=ons4,5,6,7

0100101p1=0+1+1=0,p2=0+0+1=1,p4=1+0+1=0

1234567

Page 4: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 4

HammingCode(4)•  Todecode:–  Recomputecheckbits(withparitysumincludingthecheckbit)

–  Arrangeasabinarynumber–  Value(syndrome)tellserrorposi=on–  Valueofzeromeansnoerror–  Otherwise,flipbittocorrect

Page 5: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 5

HammingCode(5)•  Example,con=nued

0100101p1=p2=p4=

Syndrome=Data=

1234567

Page 6: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 6

HammingCode(6)•  Example,con=nued

0100101p1=0+0+1+1=0,p2=1+0+0+1=0,p4=0+1+0+1=0

Syndrome=000,noerrorData=0101

1234567

Page 7: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 7

HammingCode(7)•  Example,con=nued

0100111p1=p2=p4=

Syndrome=Data=

1234567

Page 8: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 8

HammingCode(8)•  Example,con=nued

0100111p1=0+0+1+1=0,p2=1+0+1+1=1,p4=0+1+1+1=1

Syndrome=110,flipposi=on6Data=0101(correcta^erflip!)

1234567

Page 9: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 9

OtherErrorCorrec=onCodes•  Codesusedinprac=cearemuchmoreinvolvedthanHamming

•  Convolu=onalcodes(§3.2.3)–  Takeastreamofdataandoutputamixoftherecentinputbits

– Makeseachoutputbitlessfragile–  DecodeusingViterbialgorithm(whichcanusebitconfidencevalues)

Page 10: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 10

OtherCodes(2)–LDPC•  LowDensityParityCheck(§3.2.3)–  LDPCbasedonsparsematrices–  Decodeditera=velyusingabeliefpropaga=onalgorithm

–  Stateofthearttoday•  InventedbyRobertGallagerin1963aspartofhisPhDthesis–  Promptlyforgofenun=l1996…

Source:IEEEGHN,©2009IEEE

Page 11: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 11

Detec=onvs.Correc=on•  Whichisbeferwilldependonthepafernoferrors.Forexample:–  1000bitmessageswithabiterrorrate(BER)of1in10000

•  Whichhaslessoverhead?

Page 12: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 12

Detec=onvs.Correc=on•  Whichisbeferwilldependonthepafernoferrors.Forexample:–  1000bitmessageswithabiterrorrate(BER)of1in10000

•  Whichhaslessoverhead?–  Its=lldepends!Weneedtoknowmoreabouttheerrors

Page 13: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 13

Detec=onvs.Correc=on(2)1.  Assumebiterrorsarerandom

–  Messageshave0ormaybe1error

•  Errorcorrec=on:–  Need~10checkbitspermessage–  Overhead:

•  Errordetec=on:–  Need~1checkbitspermessageplus1000bit

retransmission1/10ofthe=me–  Overhead:

Page 14: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 14

Detec=onvs.Correc=on(3)2.  Assumeerrorscomeinburstsof100

–  Only1or2messagesin1000haveerrors

•  Errorcorrec=on:–  Need>>100checkbitspermessage–  Overhead:

•  Errordetec=on:–  Need32?checkbitspermessageplus1000

bitresend2/1000ofthe=me–  Overhead:

Page 15: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 15

Detec=onvs.Correc=on(4)•  Errorcorrec=on:– Neededwhenerrorsareexpected– Orwhenno=meforretransmission

•  Errordetec=on:– Moreefficientwhenerrorsarenotexpected

– Andwhenerrorsarelargewhentheydooccur

Page 16: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 16

ErrorCorrec=oninPrac=ce•  Heavilyusedinphysicallayer

–  LDPCisthefuture,usedfordemandinglinkslike802.11,DVB,WiMAX,LTE,power-line,…

–  Convolu=onalcodeswidelyusedinprac=ce

•  Errordetec=on(w/retransmission)isusedinthelinklayerandaboveforresidualerrors

•  Correc=onalsousedintheapplica=onlayer–  CalledForwardErrorCorrec=on(FEC)–  Normallywithanerasureerrormodel–  E.g.,Reed-Solomon(CDs,DVDs,etc.)

Page 17: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

Topic•  Mul=plexingisthenetworkwordforthesharingofaresource

•  Classicscenarioissharingalinkamongdifferentusers–  TimeDivisionMul=plexing(TDM)»–  FrequencyDivisionMul=plexing(FDM)»

CSE461UniversityofWashington 17

Page 18: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

TimeDivisionMul=plexing(TDM)

•  Userstaketurnsonafixedschedule

CSE461UniversityofWashington 18

2 2 2 2

Page 19: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

FrequencyDivisionMul=plexing(FDM)•  Putdifferentusersondifferentfrequencybands

CSE461UniversityofWashington 19

OverallFDMchannel

Page 20: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 20

TDMversusFDM•  InTDMausersendsatahighrateafrac=onofthe=me;inFDM,ausersendsatalowrateallthe=me

Rate

TimeFDM

TDM

Page 21: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 21

TDMversusFDM(2)•  InTDMausersendsatahighrateafrac=onofthe=me;inFDM,ausersendsatalowrateallthe=me

Rate

TimeFDM

TDM

Page 22: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 22

TDM/FDMUsage•  Sta=callydividearesource–  Suitedforcon=nuoustraffic,fixednumberofusers

•  Widelyusedintelecommunica=ons–  TVandradiosta=ons(FDM)–  GSM(2Gcellular)allocatescallsusingTDMwithinFDM

Page 23: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 23

Mul=plexingNetworkTraffic•  Networktrafficisbursty

–  ON/OFFsources–  Loadvariesgreatlyover=me

Rate

TimeRate

Time

Page 24: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 24

Mul=plexingNetworkTraffic(2)•  Networktrafficisbursty–  InefficienttoalwaysallocateusertheirONneedswithTDM/FDM

Rate

TimeRate

Time

R

R

Page 25: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

Mul=plexingNetworkTraffic(3)•  Mul=pleaccessschemesmul=plexusersaccordingtotheirdemands–forgainsofsta=s=calmul=plexing

CSE461UniversityofWashington 25

Rate

TimeRate

Time

Rate

Time

R

R

R’<2R

Twousers,eachneedR TogethertheyneedR’<2R

Page 26: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 26

Mul=pleAccess•  Wewilllookattwokindsofmul=ple

accessprotocols1.  Randomized.Nodesrandomizetheir

resourceaccessafempts–  Goodforlowloadsitua=ons

2.  Conten=on-free.Nodesordertheirresourceaccessafempts–  Goodforhighloadorguaranteed

qualityofservicesitua=ons

Page 27: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 27

Topic•  Howdonodesshareasinglelink?Whosendswhen,e.g.,inWiFI?–  Explorewithasimplemodel

•  Assumeno-oneisincharge;thisisadistributedsystem

Page 28: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 28

Topic(2)•  Wewillexplorerandommul=pleaccesscontrol(MAC)protocols–  ThisisthebasisforclassicEthernet–  Remember:datatrafficisbursty

Zzzz..Busy! Hohum

Page 29: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 29

ALOHANetwork•  Seminalcomputernetworkconnec=ngtheHawaiianislandsinthelate1960s– Whenshouldnodessend?–  AnewprotocolwasdevisedbyNormAbramson…

Hawaii

Page 30: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 30

ALOHAProtocol•  Simpleidea:–  Nodejustsendswhenithastraffic.–  Iftherewasacollision(noACKreceived)thenwaitarandom=meandresend

•  That’sit!

Page 31: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 31

ALOHAProtocol(2)•  Someframeswillbelost,butmanymaygetthrough…

•  Goodidea?

Page 32: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 32

ALOHAProtocol(3)•  Simple,decentralizedprotocolthatworkswellunderlowload!

•  Notefficientunderhighload–  Analysisshowsatmost18%efficiency–  Improvement:divide=meintoslotsandefficiencygoesupto36%

•  We’lllookatotherimprovements

Page 33: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 33

ClassicEthernet•  ALOHAinspiredBobMetcalfetoinventEthernetforLANsin1973–  Nodesshare10Mbpscoaxialcable–  Hugelypopularin1980s,1990s

:©2009IEEE

Page 34: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 34

CSMA(CarrierSenseMul=pleAccess)•  ImproveALOHAbylisteningforac=vitybeforewesend(Doh!)–  Candoeasilywithwires,notwireless

•  Sodoesthiseliminatecollisions?– Whyorwhynot?

Page 35: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 35

CSMA(2)•  S=llpossibletolistenandhearnothingwhenanothernodeissendingbecauseofdelay

Page 36: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 36

CSMA(3)•  CSMAisagooddefenseagainstcollisionsonlywhenBDissmall

X

Page 37: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 37

CSMA/CD(withCollisionDetec=on)•  Canreducethecostofcollisionsbydetec=ngthemandabor=ng(Jam)therestoftheframe=me–  Again,wecandothiswithwires

XXXXXXXXJam! Jam!

Page 38: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 38

CSMA/CDComplica=ons•  Wanteveryonewhocollidestoknowthatithappened–  Timewindowinwhichanodemayhearofacollisionis2Dseconds

X

Page 39: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 39

CSMA/CDComplica=ons(2)•  Imposeaminimumframesizethatlastsfor2Dseconds–  Sonodecan’tfinishbeforecollision–  Ethernetminimumframeis64bytes

X

Page 40: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 40

CSMA“Persistence”•  Whatshouldanodedoifanothernodeissending?

•  Idea:Waitun=litisdone,andsend

Whatnow?

Page 41: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 41

CSMA“Persistence”(2)•  Problemisthatmul=plewai=ngnodeswillqueueupthencollide– Moreload,moreofaproblem

Now! Now!Uhoh

Page 42: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 42

CSMA“Persistence”(3)•  Intui=onforabefersolu=on–  IfthereareNqueuedsenders,wewanteachtosendnextwithprobability1/N

Sendp=½WhewSendp=½

Page 43: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 43

BinaryExponen=alBackoff(BEB)•  Cleverlyes=matestheprobability

–  1stcollision,wait0or1frame=mes–  2ndcollision,waitfrom0to3=mes–  3rdcollision,waitfrom0to7=mes…

•  BEBdoublesintervalforeachsuccessivecollision–  Quicklygetslargeenoughtowork–  Veryefficientinprac=ce

Page 44: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

ClassicEthernet,orIEEE802.3•  MostpopularLANofthe1980s,1990s–  10Mbpsoversharedcoaxialcable,withbasebandsignals– Mul=pleaccesswith“1-persistentCSMA/CDwithBEB”

CSE461UniversityofWashington 44

Page 45: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

EthernetFrameFormat•  Hasaddressestoiden=fythesenderandreceiver•  CRC-32forerrordetec=on;noACKsorretransmission•  Startofframeiden=fiedwithphysicallayerpreamble

CSE461UniversityofWashington 45

PacketfromNetworklayer(IP)

Page 46: Hamming Code - courses.cs.washington.edu · Hamming Code • Gives a method for construc=ng a code with a distance of 3 – Uses n = 2k – k – 1, e.g., n=4, k=3 – Put check bits

CSE461UniversityofWashington 46

ModernEthernet•  Basedonswitches,notmul=pleaccess,buts=llcalledEthernet– We’llgettoitinalatersegment

Switch

TwistedpairSwitchports