ece project SOFT COPY

Embed Size (px)

Citation preview

  • 8/16/2019 ece project SOFT COPY

    1/51

    CHAPTER-I

    INTRODUCTION

    A minimal variable-length character coding based on the frequency of each character.First, each character becomes a trivial binary tree, with the character as the only node.The character's frequency is the tree's frequency. Two trees with the least frequencies are

    joined as the sub trees of a new root that is assigned the sum of their frequencies. Re eatuntil all characters are in one tree. !ne code bit re resents each level. Thus more frequentcharacters are near the root and are coded with few bits, and rare characters are far fromthe root and are coded with many bits. Also "nown as static #uffman coding.

    $n com uter science and information theory, #uffman coding is an entro y encodingalgorithm used for lossless data com ression. The term refers to the use of a variable-length code table for encoding a source symbol %such as a character in a file& where thevariable-length code table has been derived in a articular way based on the estimated

    robability of occurrence for each ossible value of the source symbol.

    #uffman coding uses a s ecific method for choosing the re resentation for eachsymbol, resulting in a refi code %sometimes called ( refi -free codes(& %that is, the bitstring re resenting some articular symbol is never a refi of the bit string re resentingany other symbol& that e resses the most common characters using shorter strings of bitsthan are used for less common source symbols. #uffman was able to design the mostefficient com ression method of this ty e) no other ma ing of individual sourcesymbols to unique strings of bits will roduce a smaller average out ut si*e when theactual symbol frequencies agree with those used to create the code. A method was later found to do this in linear time if in ut robabilities %also "nown as weights& are sorted.

    For a set of symbols with a uniform robability distribution and a number of memberswhich is a ower of two, #uffman coding is equivalent to sim le binary bloc" encoding,e.g., A+ $$ coding. #uffman coding is such a wides read method for creating reficodes that the term (#uffman code( is widely used as a synonym for ( refi code( evenwhen such a code is not roduced by #uffman's algorithm.

    Although #uffman coding is o timal for a symbol-by-symbol coding %i.e. a stream of unrelated symbols& with a "nown in ut robability distribution, its o timality cansometimes accidentally be over-stated. For e am le, arithmetic coding and / codingoften have better com ression ca ability. 0oth these methods can combine an arbitrary

    number of symbols for more efficient coding, and generally ada t to the actual in utstatistics, the latter of which is useful when in ut robabilities are not recisely "nown or vary significantly within the stream. $n general, im rovements arise from in ut symbols

    being related %cat is more common than cta&.

    1

  • 8/16/2019 ece project SOFT COPY

    2/51

    #uffman tree generated from the e act frequencies of the te t (this is an e am le of a#uffman tree(. The frequencies and codes of each character are below. 2ncoding thesentence with this code requires 134 bits, not counting s ace for the tree.

    5

  • 8/16/2019 ece project SOFT COPY

    3/51

    CHAPTER-II

    IMAGE PROCESSING

    2.1 What is an Image?

    An image is a rectangular grid of i els. $t has a definite heightand a definite width counted in i els. 2ach i el is square and has a fi ed si*e on agiven dis lay. #owever different com uter monitors may use different si*ed i els.

    2ach i el has a color. The color is a 35-bit integer. The first eight bits determine theredness of the i el, the ne t eight bits the greenness, the ne t eight bits the blueness, andthe remaining eight bits the trans arency of the i el.

    1

    1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

    Trans arency Red 6reen 0lue

    2ach of these values can be inter reted as an unsigned byte between 7 and 544. /ithinthe color higher numbers are brighter. Thus a red of 7 is no red at all while a red of 544 isa very bright red.

    urrently 8ava only su orts two levels of trans arency) om letely o aque %544& andcom letely trans arent %7&. 9alues of 1 through 54: are treated as com letely trans arent.

    ;ifferent colors are made by mi ing different levels of the three rimary colors. For e am le, medium gray is 15< red, 15< green, and 15< blue.

    =edium 6rey

    544 15< 15< 15<

    >ure white is 544 red, 544 green, 544 blue.

    0right /hite

    544 544 544 544

    >ure red is 544 red, 7 green, 7 blue.

    >ure Red

    544 544 7 7

    A light cream is 544 red, 531 green, and 1?< blue.

    3

  • 8/16/2019 ece project SOFT COPY

    4/51

    ight ream

    544 544 531 1?<

    2.2 Image P !"essing

    $n electrical engineering and com uter science, image rocessing is any formof signal rocessing for which the in ut is an image, such as hotogra hs or frames of video@ the out ut of image rocessing can be either an image or a set of characteristics or

    arameters related to the image. =ost image- rocessing techniques involve treating theimage as a two-dimensional signal and a lying standard signal- rocessing techniques toit.

    $mage rocessing usually refers to digital image rocessing, but o tical and analogimage rocessing are also ossible. This article is about general techniques that a ly to

    all of them. The acquisition of images % roducing the in ut image in the first lace& isreferred to as imaging.

    .

    :

    http://en.wikipedia.org/wiki/File:Imagen_binaria.jpg

  • 8/16/2019 ece project SOFT COPY

    5/51

    2.# Image $! mat

    $mage format refers to the s ecification under which an image has beensaved to dis" or in which it resides in the com uter memory. There are many commonlyused digital image formats in use. +ome of the most used are T$FF, 0=>, 6$F, and

    8>26. The image format s ecification dictates what image information is resent andhow it is organi*ed in memory. =any formats su ort various sub-formats or flavors.

    The $mage Format is a base to ic for to ics describing a defined way of codinginformation for storage or transfer of images.

    $mage file formats are standardi*ed means of organi*ing and storing images. Thisentry is about digital image formats used to store hotogra hic and other images@ %for dis"-image file formats see ;is" image&. $mage files are com osed of either i el or vector %geometric& data that are raster *ed to i els when dis layed %with few e ce tions&in a vector gra hic dis lay. The i els that com ose an image are ordered as a grid

    %columns and rows&@ each i el consists of numbers re resenting magnitudes of brightness and color.

    .

    4

  • 8/16/2019 ece project SOFT COPY

    6/51

    CHAPTER-III

    COMPRESSION TECHNI%UES

    #.1 &OSS&ESS COMPRESSION'

    ossless data com ression is a class of data com ression algorithms that allowsthe e act original data to be reconstructed from the com ressed data. The termlossless is in contrast to lossy data com ression, which only allows an a ro imationof the original data to be reconstructed, in e change for better com ression rates.

    ossless data com ression is used in many a lications. For e am le, it is used inthe o ular $> file format and in the B$C tool *i . $t is also often used as acom onent within lossy data com ression technologies.

    ossless com ression is used when it is im ortant that the original and thedecom ressed data be identical, or when no assum tion can be made on whether certain deviation is uncritical. Ty ical e am les are e ecutable rograms and sourcecode. +ome image file formats, li"e >B6 or 6$F, use only lossless com ression,while others li"e T$FF and =B6 may use either lossless or lossy methods.

    D

  • 8/16/2019 ece project SOFT COPY

    7/51

    &!ss(ess "!m) essi!n te"hni*+es

    . =ost lossless com ression rograms do two things in sequence) the first ste

    generates a statistical model for the in ut data, and the second ste uses this model toma in ut data to bit sequences in such a way that ( robable( %e.g. frequentlyencountered& data will roduce shorter out ut than (im robable( data.

    The rimary encoding algorithms used to roduce bit sequences are #uffman coding%also used by ;2F AT2& and arithmetic coding. Arithmetic coding achieves com ressionrates close to the best ossible for a articular statistical model, which is given by theinformation entro y, whereas #uffman com ression is sim ler and faster but roduces

    oor results for models that deal with symbol robabilities close to 1.

    There are two rimary ways of constructing statistical models) in a static model, the

    data is analy*ed and a model is constructed, then this model is stored with thecom ressed data. This a roach is sim le and modular, but has the disadvantage that themodel itself can be e ensive to store, and also that it forces a single model to be used for all data being com ressed, and so erforms oorly on files containing heterogeneousdata. Ada tive models dynamically u date the model as the data is com ressed. 0oth theencoder and decoder begin with a trivial model, yielding oor com ression of initial data,

    but as they learn more about the data erformance im rove. =ost o ular ty es of com ression used in ractice now use ada tive coders.

    ossless com ression methods may be categori*ed according to the ty es of data theyare designed to com ress. /hile, in rinci le, any general- ur ose lossless com ression

    algorithm %general- ur ose meaning that they can com ress any bitstring& can be used onany ty e of data, many are unable to achieve significant com ression on data that is notof the form for which they were designed to com ress. =any of the lossless com ressiontechniques used for te t also wor" reasonably well for inde ed images.

    &!ss(ess "!m) essi!n meth!,s

    0y o eration of the igeonhole rinci le, no lossless com ression algorithm canefficiently com ress all ossible data, and com letely random data streams cannot becom ressed. For this reason, many different algorithms e ist that are designed either witha s ecific ty e of in ut data in mind or with s ecific assum tions about what "inds of

    redundancy the uncom ressed data are li"ely to contain.+ome of the most common lossless com ression algorithms are listed below.

  • 8/16/2019 ece project SOFT COPY

    8/51

    Gene a( )+ )!se

    Run-length encoding E a sim le scheme that rovides good com ression of data containsa lots of runs of the same value.

    / E used by gif and com ress among others

    ;eflate E used by g*i , modern versions of *i and as art of the com ression rocess of >B6, >>>, #TT>, ++#

    A+,i!

    A le ossless E A A %A le ossless Audio odec&

    ATRA Advanced ossless

    Audio ossless oding E also "nown as =>26-: A +

    =>26-: + + E also "nown as #;-AA

    ;irect +tream Transfer E ;+T

    ;olby True#;

    ;T+-#; =aster Audio

    Free ossless Audio odec E F A

    =eridian ossless >ac"ing E = >

    =on"ey's Audio E =on"ey's Audio A>2

    ! timFR!6

    Real>layer E RealAudio ossless

    +horten E +#B

    TTA E True Audio ossless

    /av>ac" E /av>ac" lossless

    /=A ossless E /indows =edia ossless

    ?

  • 8/16/2019 ece project SOFT COPY

    9/51

    G a)hi"s

    A0! E Ada tive 0inary ! timi*ation

    6$F E %lossless, but contains a very limited number color range&

    80$65 E %lossless or lossy com ression of 0 / images&

    8>26- + E %losslessGnear-lossless com ression standard&

    8>26 5777 E %includes lossless com ression method, as roven by +unil Humar, >rof +an;iego +tate niversity&

    8>26 CR - formerly /=>hoto and #; >hoto, includes a lossless com ression method

    >6F E >rogressive 6ra hics File %lossless or lossy com ression&

    >B6 E >ortable Betwor" 6ra hics

    T$FF - Tagged $mage File Format

    i,e!

    Animation codec

    ore>B6

    FF91

    8>26 5777

    #uffyuv

    agarith

    =+ ossless 9ideo odec

    +heer 9ideo

    I

  • 8/16/2019 ece project SOFT COPY

    10/51

    3.5 &OSS COMPRESSION'

    ossy com ression) A data com ression technique in whichsome data is deliberately discarded to achieve massive reductions in the si*e of thecom ressed file. ossy com ression techniques can reduce a file to 1G47 of its former si*e

    %or less&, com ared to the average of one-third achieved by lossless com ressiontechniques. ossy com ression is used for gra hics files in which the loss of data - suchas information about some of the gra hic's several million colors - isn't noticeable. Ane am le is the 8>26 com ression technique. ossless com ression. From J 2 $;

    A lossy com ression method is one where com ressing data and then decom ressing itretrieves data that is different from the original, but is close enough to be useful in someway. ossy com ression is most commonly used to com ress multimedia data %audio,video, still images&, es ecially in a lications such as streaming media and internettele hony. 0y contrast, lossless com ression is required for te t and data files, such as

    ban" records, te t articles, etc. $n many cases it is advantageous to ma"e a master lossless

    file which can then be used to roduce com ressed files for different ur oses@ for e am le a multi-megabyte file can be used at full si*e to roduce a full- ageadvertisement in a glossy maga*ine, and a 17 "ilobyte lossy co y made for a small imageon a web age.

    This category covers lossy com ression methods that canKt be inned down to one of the more refined to ics, such as 8>26 or =>3. $n some cases, the items here are esotericalgorithms that donKtK merit their own to ics. $n other cases, they s an one or moree isting to ics. The unifying theme is of course that they are lossy. This means that after a com ressionGdecom ression cycle, the data set will be modified. $deally, whencom ression image or sound files, the loss is either minimal or undetectable by human

    observers. Lossy compression differs from its counterpart, lossless compression, as its name implies—some amount of data may be lost in the process. Thus, after a compression/decompression cycle,the data set will be modified from the uncompressed original and information maybe lost. One may ask why the loss of data can be tolerated in any case. Lossy compressiontechniques attempt to eliminate unnecessary or redundant information, focusing more on savingspace over preserving the accuracy of the data. Ideally, the loss is either minimal or undetectableby human observations. Lossy compression techniques are used for pictures and music files thatcan be trimmed at the edges. nlike te!t files and processing files, pictures and music do notrequire reconstruction to be identical to the original, especially if the data dropped is insignificant orundetectable.

    This section will introduce lossy compression in "#$% and ' technology.

    17

  • 8/16/2019 ece project SOFT COPY

    11/51

    The e a e t/! 0asi" (!ss "!m) essi!n s"hemes'

    • $n lossy transform codes, sam les of icture or sound are ta"en, cho ed intosmall segments, transformed into a new basis s ace, and quanti*ed. The resultingquanti*ed values are then entro y coded.

    • $n lossy redictive codes, revious andGor subsequent decoded data is used to redict the current sound sam le or image frame. The error between the redicteddata and the real data, together with any e tra information needed to re roducethe rediction, is then quanti*ed and coded.

    $n some systems the two techniques are combined, with transform codes being used tocom ress the error signals generated by the redictive stage.

    &!ss e s+s (!ss(ess

    The advantage of lossy methods over lossless methods is that in some cases a lossymethod can roduce a much smaller com ressed file than any lossless method, while stillmeeting the requirements of the a lication.

    ossy methods are most often used for com ressing sound, images or videos. This is because these ty es of data are intended for human inter retation where the mind caneasily (fill in the blan"s( or see ast very minor errors or inconsistencies E ideally lossycom ression is trans arent %im erce tible&, which can be verified via an A0C test.

    11

  • 8/16/2019 ece project SOFT COPY

    12/51

    CAPTER-I

    COADING TECHNI%UES

    3.1 ARITHMETIC COADING

    Arithmetic coding is a method for lossless data com ression. Bormally, a string of characters such as the words (hello there( is re resented using afi ed number of bits er character, as in the A+ $$ code. i"e #uffman coding,arithmetic coding is a form of variable-length entro y encoding that converts a string intoanother form that re resents frequently used characters using fewer bits and infrequentlyused characters using more bits, with the goal of using fewer bits in total. As o osed toother entro y encoding techniques that se arate the in ut message into its com onentsymbols and re lace each symbol with a code word, arithmetic coding encodes the entiremessage into a single number, a fraction n where %7.7 L n M 1.7&.

    4.2 Defining a model

    Arithmetic coders roduce near-o timal out ut for a given set of symbols and robabilities %the o timal value is Nlog 2 P bits for each symbol of robability P , seesource coding theorem&. om ression algorithms that use arithmetic coding start bydetermining a model of the data E basically a rediction of what atterns will be found inthe symbols of the message. The more accurate this rediction is the closer to o timalitythe out ut will be.

    Example

    +u ose we are trying to decode a message encoded with the four-symbol modeldescribed above. The message is encoded in the fraction 7.43? %for clarity, we are usingdecimal, instead of binary@ we are also assuming that whoever gave us the encodedmessage gave us only as many digits as needed to decode the message. /e will discuss

    both issues later.&

    A diagram is showing decoding of 7.43? %the circular oint& in the e am le model. Theregion is divided into sub regions ro ortional to symbol frequencies, and then the subregion containing the oint is successively subdivided in the same way.

    /e start, as the encoder did, with the interval O7, 1&, and using the same model, we divide

    it into the same four sub-intervals that the encoder must have. !ur fraction 7.43? fallsinto the sub-interval for B2 TRA , O7, 7.D&@ this indicates to us that the first symbol theencoder read must have been B2 TRA , so we can write that down as the first symbolof our message.

    15

  • 8/16/2019 ece project SOFT COPY

    13/51

    /e then divide the interval O7, 7.D& into sub-intervals)

    • the interval for B2 TRA would be O7, 7.3D& -- 60% of [0, 0.6) • the interval for >!+$T$92 would be O7.3D, 7.:?& -- 20% of [0, 0.6) • the interval for B26AT$92 would be O7.:?, 7.4:& -- 10% of [0, 0.6) •

    The interval for 2B;-!F-;ATA would be O7.4:, 7.D&. -- 10% of [0, 0.6)

    !ur fraction of .43? is within the interval O7.:?, 7.4:&@ therefore the second symbol of themessage must have been B26AT$92.

    !nce more we divide our current interval into sub-intervals)

    • the interval for B2 TRA would be O7.:?, 7.41D&• the interval for >!+$T$92 would be O7.41D, 7.45?&• the interval for B26AT$92 would be O7.45?, 7.43:&• the interval for 2B;-!F-;ATA would be O7.43:, 7.4:7&.

    !ur fraction of .43? falls within the interval of the 2B;-!F-;ATA symbol@ therefore,this must be our ne t symbol. +ince it is also the internal termination symbol, it meansour decoding is com lete. $f the stream was not internally terminated, we would need to"now where the stream sto s from some other source. !therwise, we would continue thedecoding rocess forever, mista"enly reading more symbols from the fraction than werein fact encoded into it.

    The same message could have been encoded by the equally short fractions .43:, .434, .43D, .43< or .43I. This suggests that our use of decimal instead of binary introducedsome inefficiency. This is correct@ the information content of a three-digit decimal is

    a ro imately I.IDD bits@ we could have encoded the same message in the binary fraction.17771717 %equivalent to .43I7D54 decimal& at a cost of only ? bits. %Bote that the final*ero must be s ecified in the binary fraction, or else the message would be ambiguouswithout e ternal information such as com ressed stream si*e.&

    This ? bit out ut is larger than the information content, or entro y of our message, whichis 1.4< P 3 or :.

  • 8/16/2019 ece project SOFT COPY

    14/51

    3.2 ARIA4&E &ENGTH COADING

    $n coding theory a variable-length code is a code which ma s sourcesymbols to a variable number of bits.

    9ariable-length codes can allow sources to be com ressed and decom ressed with zeroerror %lossless data com ression& and still be read bac" symbol by symbol. /ith the rightcoding strategy an i.e. source may be com ressed almost arbitrarily close to its entro y.This is in contrast to fi ed length coding methods, for which data com ression is only

    ossible for large bloc"s of data, and any com ression beyond the logarithm of the totalnumber of ossibilities comes with a finite %though erha s arbitrarily small& robabilityof failure.

    +ome e am les of well-"nown variable-length coding strategies are #uffman coding,em el- iv coding and arithmetic coding.

    E5tensi!n !$ a "!,e

    The e tension of a code is the ma ing of finite length source sequences to finitelength bit strings, that is obtained by concatenating for each symbol of the sourcesequence the corres onding codeword roduced by the original code.

    C(asses !$ a ia0(e-(ength "!,es

    9ariable-length codes can be strictly nested in order of decreasing generality asnon-singular, uniquely decodable and instantaneous % refi -free&. $nstantaneous codes arealways uniquely decodable, which in turn are always non-singular)

    Non-singular codes

    A code is non-singular if each source symbol is ma ed to a different non-em ty bitstring, i.e. the ma ing from source symbols to bit strings is one-to-one.

    • For e am le the ma ing M1 S%a,7&, %b,7&, %c,1& is not non-singular because both (a( and (b( ma to the same bit string (7( @ any e tension of this ma ingwill generate a lossy %non-lossless& coding. +uch singular coding may still beuseful when some loss of information is acce table %for e am le when such codeis used in audio or video com ression, where a lossy coding becomes equivalent

    to source quanti*ation&.• #owever, the ma ing M2 S%a,7&, %b,1&, %c,77&, %d,71& is non-singular @ itse tension will generate a lossless coding, which will be useful for general datatransmission %but this feature is not always required&. Bote that it is not necessaryfor the non-singular code to be more com act than the source %and in manya lications, a larger code is useful, for e am le as a way to detect andGor recover from encoding or transmission errors, or in security a lications to rotect asource from undetectable tam ering&.

    1:

  • 8/16/2019 ece project SOFT COPY

    15/51

    Uniquely decodable codes

    A code is uniquely decodable if its e tension is non-singular.

    • The non-singular e am le ma ing M2 in the revious aragra h is not uniquely

    decodable because %for e am le& the source sequence (a a( ma s to bit string (77(using the e tension, e actly li"e the source sequence (c(. #owever, such a code isuseful when the set of all ossible source symbols is com letely "nown and finite,or when there are restrictions %for e am le a formal synta & that determine if source elements of this e tension are acce table. +uch restrictions ermit thedecoding of the original message by chec"ing which of the ossible sourcesymbols ma ed to the same symbol are valid under those restrictions.

    • The e tension of the ma ing M3 S%a,7&, %b,71&, %c,711& is uniquely decodable%this can be demonstrated by loo"ing at the follow-set after each target bit string inthe ma , because each bitstring is terminated as soon as we see a 7 bit whichcannot follow any e isting code to create a longer valid code in the ma , but

    unambiguously starts a new code&.

    Instantaneous codes

    A code is instantaneous %also said context-free & if no target bit string in the ma ing isa refi of the target bit string of a different source symbol in the same ma ing. Thismeans that symbols can be decoded instantaneously after their entire codeword isreceived.

    • The e am le ma ing M3 in the revious aragra h is not instantaneous becausewe don't "now after reading the bit string (7( if it encodes a (a( source symbol, or

    if it is the refi of the encodings of the (b( or (c( symbols.• An e am le of an instantaneous variable-length code is shown below.

    S m0!( C!,e/! ,

    14

  • 8/16/2019 ece project SOFT COPY

    16/51

    a 7

    b 17

    c 117

    d 111

    The source is one of four symbols) a, b, c or d. The binary codeword for each symbol is given.The encoding and decoding of a ortion of an e am le source sequence is given

    below)aabacda U 771771171117 U V7V7V17V7V117V111V7V U aabacda

    A, antages

    Advantage of a variable-length code is that unli"ely source symbols can beassigned longer code words and li"ely source symbols can be assigned shorter codewords, thus giving a low expected codeword length. For the above e am le, if the

    robabilities of %a, b, c, d& were , the e ected number of bits used tore resent a source symbol using the code above would be)

    .

    As the entro y of this source is 1.

  • 8/16/2019 ece project SOFT COPY

    17/51

  • 8/16/2019 ece project SOFT COPY

    18/51

    At this oint, no element has been given its com lete code yet, but we now "now that thecodes for ; and 2 will be e actly the same, e ce t for the last binary digit) ; will end in7 and 2 in 1.

    The combined node ;-and-2 is laced bac" with the other %as yet& uncombined

    elements, and given a weight equal to the sum of its leaf nodes) in this case, ? Z ? 1D.Again, we ta"e the two nodes with lowest weight, which are A, and ;-and-2, and jointhem into a larger node.

    % & 7 G Y 1 % & A 7 G Y 1 ; 2

    This time, when the node A-;-2 is ut bac" into the list of elements, all remainingelements have the same weight, 35. /hich two of the three are selected to be combinedfirst is not im ortant, at least not in the classical #uffman algorithm.

    /hen all nodes have been recombined into a single XX#uffman tree,'' then by starting atthe root and selecting 7 or 1 at each ste , you can reach any element in the tree. 2achelement now has a #uffman code, which is the sequence of 7's and 1's that re resents that

    ath through the tree.

    Bow, it should be fairly easy to see how such a tree, and such a set of codes, could be

    used for com ression. $f com ressing ordinary te t, for e am le, robably more than half of the A+ $$ character set could be left out of the tree altogether. Frequently usedcharacters, li"e X2' and XT' and XA,' will robably get much shorter codes, and even if some codes are actually made longer, they will be the ones that are used less often.

    #owever, there is also the question) how do you ass the tree along with the encodeddata[ $t turns out that there is a fairly sim le way, if you modify slightly the algorithmused to generate the tree.

    $n the classic #uffman algorithm, a single set of elements and weights could generatemulti le trees. $n the variation used by the ;eflate standard, there are two additional

    rules) elements that have shorter codes are laced to the left of those with longer codes.%$n our revious e am le, ; and 2 wind u with the longest codes, and so they would beall the way to the right.& Among elements with codes of the same length, those that comefirst in the element set are laced to the left. %$f ; and 2 end u being the only elementswith codes of that length, then ; will get the 7 branch and 2 the 1 branch, as ; comes

    before 2.&

    1?

  • 8/16/2019 ece project SOFT COPY

    19/51

    $t turns out that when these two restrictions are laced u on the trees, there is at most one ossible tree for every set of elements and their res ective code lengths. The code lengthsare all that we need to reconstruct the tree, and therefore all that we need to transmit.

    A, antages

    • The decoding delay is small in convolution codes since they o erate on smaller

    bloc"s of data

    • The storage hardware required by convolution decoder is less since the bloc"

    si*es are smaller

    P +ynchroni*ation roblem does not affect the erformance of convolution codes

    Disa, antages

    • onvolution codes are difficult to analy*e since there is com le .• onvolution codes are not develo ed much as com ared to bloc" codes.

    HU66MAN TREE E7AMP&E

    #uffman tree generated from the e act frequencies in the sentence (this is an e am le of a #uffman tree(. $t encodes this sentence in 134 bits as(711717171777171111117771711111717771711177717717717711117711117717771117

    1I

    http://upload.wikimedia.org/wikipedia/commons/f/fc/Huffman_tree.svg

  • 8/16/2019 ece project SOFT COPY

    20/51

    71171 1711117171111717771111171117171117177717111711711777777777(,re resenting about a 43\ com ression over A+ $$'s 5?? bits, not counting any s ace for re resenting the tree. Botice that the frequencies on each level fall between two adjacent

    owers of 5. The bit attern and frequency of each character are shown by the table below. Botice that some symbols have different frequencies but the same encoding

    length@ these articularly indicate laces where arithmetic coding would do b

    Cha 6 e* C!,e

    s ace < 111

    a : 717

    e : 777

    f 3 1171

    h 5 1717

    i 5 1777

    Cha 6 e* C!,e

    m 5 7111

    n 5 7717

    s 5 1711

    t 5 7117

    l 1 11771

    o 1 77117

    Cha 6 e* C!,e

    1 17711

    r 1 11777

    u 1 77111

    1 17717

    57

  • 8/16/2019 ece project SOFT COPY

    21/51

    CHAPTER-

    PRO8ECT DESCPIPTION

    9.1 4&OC: DIAGRAM

    +ymbol$n ut

    +end odewords Table

    2 changeode words

    Table.

    om are+tored within ut +ymbols

    +end matchedsignal andAddress to codeword table

    Read address;ata

    $n ut

    !ut ut

    51

  • 8/16/2019 ece project SOFT COPY

    22/51

    9.2 4&OC: DIAGRAM DESCRIPTION

    S m0!( in)+t'

    Bumber of messages and robability is ta"en as a symbol in ut.

    C!m)a e in)+t S m0!(s'The total robability of all message signals must be com ared with 1. if condition

    satisfies it continues to ne t bloc" otherwise it sto s there only.

    Sen, mat"he, signa( t! "!,e /! , ta0(e'$f above condition satisfied, then the message is sent to code word table for

    further rocess.

    9.# WOR:ING

    2nter the total number of message required for calculating #uffman coding@ assign robability for each message signal. hec" the #uffman coding condition i.e. ]sum of robability of message signal is equal to 1^.

    Bow ta"e number of source symbol . hec" the code al habet of si*e what we

    given. $f negative is+calar it is o", otherwise it goes to error. +calar ta"es the codingal habet. $f scalar is greater than coding al habet. $t will not wor", it goes to error.

    Bow source of symbol label and number of source symbol should be equal% _ B&, it will not wor" otherwise it goes to error. $t dis lays the out ut screen. $f out ut screen is false it will wor" otherwise it goes to error. Bow string com areout ut screen and dot if it true it will dis lays out ut, otherwise it goes to error.

    Bow create ]# FF=AB !;2 TR22^ %create a tree node for each of the number of tree node for each of the of the number of symbol& chec" the loo weight, childnodes, height, e osed, and dummy nodes.

    hec" dummy nodes are needed or not iteratively merge the dummy sub tree at atime, until only 1 sub tree is left. +ort e osed nodes in ascending order based onweight. ombine first node and new nodes of weight. This node has dummyingchildren, height of new sub tree.

    $f node is e osed, it is not a dummy arse code tree to generate code words,initiali*e return value, i.e. code words. Bow it start the rinting and get out ut.

    55

  • 8/16/2019 ece project SOFT COPY

    23/51

    9.3 MAT&A4 COMMANDDS'

    $+92 T!R True if array is a vector.

    $+92 T!R %9& returns logical true %1& if 9 is a 1 n or n 1 vector,

    /here n ` 7, and logical false %7& otherwise.

    =$B +mallest com onent.

    For vectors, =$B%C& is the smallest element in C. For matrices,

    =$B%C& is a row vector containing the minimum element from each

    olumn. For B-; arrays, =$B%C& o erates along the first

    Bon-singleton dimension.

    2B6T# of vector.

    2B6T#%C& returns the length of vector C. $t is equivalent

    To =AC %+$ 2%C&& for non-em ty arrays and 7 for em ty ones.

    $++ A AR True if array is a scalar.

    $++ A AR%+& returns logical true %1& if + is a 1 1 matri

    And logical false %7& otherwise.

    $+2=>TW True for em ty array.

    $+2=>TW%C& returns 1 if C is an em ty array and 7 otherwise. An

    2m ty array has no elements, that is rod %si*e%C&& 7.

    +TR => om are strings.

    TF +TR => %+1, +5& com ares the strings +1 and +5 and returns logical 1

    %true& if they are identical, and returns logical 7 %false& otherwise.

    F!>2B ! en file.

    F$; F!>2B %F$ 2BA=2& o ens the file F$ 2BA=2 for read access.

    53

  • 8/16/2019 ece project SOFT COPY

    24/51

    F$ 2BA=2 is a string containing the name of the file to be o ened.

    %!n > systems, F!>2B o ens files for binary read access.&

    29A 2 ecute string with =AT A0 e ression.

    29A %s&, where s is a string, causes =AT A0 to e ecute

    The string as an e ression or statement.

    F>R$BTF /rite formatted data to file.

    ! BT F>R$BTF %F$;, F!R=AT, A...& formats the data in the real

    >art of array A %and in any additional array arguments&, under

    ontrol of the s ecified F!R=AT string, and writes it to the file

    associated with file identifier F$;. ! BT is the number of bytes

    +uccessfully written. F$; is an integer file identifier obtained

    from F!>2B. $t can also be 1 for standard out ut %the screen& or 5

    for standard error. $f F$; is omitted, out ut goes to the screen.

    F!>2B ! en file.

    F$; F!>2B %F$ 2BA=2& o ens the file F$ 2BA=2 for read access.

    F$ 2BA=2 is a string containing the name of the file to be o ened.

    %!n > systems, F!>2B o ens files for binary read access.&

    +tatus fclose %fid& closes the

    + ecified file if it is o en, returning 7 if successful

    and -1 if unsuccessful. Argument fid is

    a file identifier associated with an o en file. %+ee fo en for

    a com lete descri tion of fid&.

    5:

  • 8/16/2019 ece project SOFT COPY

    25/51

    CHAPTER- I

    APP&ICATIONS

    #uffman coding today is often used as a (bac"-end( to some other com ressionmethod. ;2F AT2 %>H $>'s algorithm& and multimedia codes such as 8>26 and=>3 have a front-end model and quanti*ation followed by #uffman coding.

    $n many image sequence com ression a lications, #uffman coding is used toreduce statistical redundancy in quanti*ed transform coefficients. The #uffmancodeword table is often re-defined to reduce coding delay and table transmissionoverhead. ocal symbol statistics, however, may be much different from the

    global one manifested in the re-defined table. $n this a er, we ro ose adynamic #uffman coding method which can ada tively modify the givencodeword and symbol association according to the local statistics. !ver a certainset of bloc"s, local symbol statistics is observed and used to re-associate thesymbols to the code words in such a way that shorter codeword are assigned tomore frequency symbols. This modified code table is used to code the ne t set of

    bloc"s. A arameter is set u so that the relative degree of sensitivity of the localstatistics to the global one can be controlled. 0y erforming the samemodification to the code table using the decoded symbols, it is ossible to "ee uwith the code table changes in receiving side. The code table modificationinformation need not be transmitted to the receiver. Therefore, there is no e tra

    transmission overhead in em loying this method.

    54

  • 8/16/2019 ece project SOFT COPY

    26/51

    CHAPTER- II

    6UTURE SCOPE

    There is a lot of future sco e in this roject)

    1. The roject can be e tended to ;2- !=>R2++ the !=>R2++2; the image.

    5. onversion of image values %R60 Format& to W b r values of the image.

    This material will be resented here in the future. $n the mean time, lease e lore.

    Future sco e for wor" lies in getting more erformance metrics and some modificationsto theAlgorithm to im rove on the com ression figures. Also the algorithm can be a lied tovarious

    >rocessor architectures to get some more insight into the com ression.

    5D

  • 8/16/2019 ece project SOFT COPY

    27/51

    CHAPTER- III

    C!n"(+si!n

    $t is widely used for lossless com ression Technique, e loited for manysoftware and hardware a lication li"e 8>26, =>26, ;2F AT2 %>H $>Ks algorithm&and =>3.

    #uffman coding is still in wide use because of sim licity, high s eed lac" of encumbrance by atent. #uffman coding today is often used as a ]bac"-end ]to someother com ression m

    5

  • 8/16/2019 ece project SOFT COPY

    28/51

    CHAPTER I7

    MAT&A4 IN6ORMATION

    6EATURES O6 MAT&A4 USED IN THIS PRO8ECT

    =AT A0 is a high erformance language for technical com uting .$t integrates

    com utation visuali*ation and rogramming in an easy to use environment

    =at lab stands for matri laboratory. $t was written originally to rovide easy access to

    matri software develo ed by $B>A H %linear system ac"age& and 2$+>A H %2igen

    system ac"age& rojects.

    =AT A0 is therefore built on a foundation of so histicated matri software in

    which the basic element is matri that does not require re dimensioning

    T )i"a( +ses !$ MAT&A4

    1. =ath and com utation

    2. Algorithm develo ment

    #. ;ata acquisition

    3. ;ata analysis ,e loration ands visuali*ation

    9. +cientific and engineering gra hics

    The main $eat+ es !$ MAT&A4

    1. Advance algorithm for high erformance numerical com utation ,es ecially in the

    Field matri algebra

    5. A large collection of redefined mathematical functions and the ability to define

    oneKs own functions.

    3. Two-and three dimensional gra hics for lotting and dis laying data

    :. A com lete online hel system

    4. >owerful, matri or vector oriented high level rogramming language for

    individual a lications.

    D. Toolbo es available for solving advanced roblems in several a lication areas

    5?

  • 8/16/2019 ece project SOFT COPY

    29/51

    =AT A0

    =AT A0>rogramming language

    ser written G 0uilt in functions

    6ra hics5-; gra hics3-; gra hics

    olor and lightingAnimation

    om utationinear algebra+ignal rocessingJuadrature2tc

    2 ternal interface$nterface with andF!RTRAB>rograms

    Tool bo es+ignal rocessing$mage rocessing

    ontrol systems

    Beural Betwor"sommunicationsRobust control+tatistics

    5I

  • 8/16/2019 ece project SOFT COPY

    30/51

    6eat+ es an, "a)a0i(ities !$ MAT&A4

    The MAT&A4 S stem

    The =AT A0 system consists of five main arts)

    De e(!)ment En i !nment

    This is the set of tools and facilities that hel you use =AT A0 functions and files.

    =any of these tools are gra hical user interfaces. $t includes the =AT A0 des"to and

    ommand /indow, a command history, an editor and debugger, and browsers for

    viewing hel , the wor"s ace, files, and the search ath.

    The MAT&A4 Mathemati"a( 6+n"ti!n &i0 a This is a vast collection of com utational algorithms ranging from elementary

    functions, li"e sum, sine, cosine, and com le arithmetic, to more so histicated functions

    li"e matri inverse, matri 2igen values, 0essel functions, and fast Fourier transforms.

    The MAT&A4 &ang+age

    This is a high-level matri Garray language with control flow statements, functions,

    data structures, in utGout ut, and object-oriented rogramming features. $t allows both( rogramming in the small( to ra idly create quic" and dirty throw-away rograms, and

    ( rogramming in the large( to create large and com le a lication rograms.

    G a)hi"s

    =AT A0 has e tensive facilities for dis laying vectors and matrices as gra hs, as well

    as annotating and rinting these gra hs. $t includes high-level functions for two-

    dimensional and three-dimensional data visuali*ation, video rocessing, animation, and resentation gra hics. $t also includes low-level functions that allow you to fully

    customi*e the a earance of gra hics as well as to build com lete gra hical user

    interfaces on your =AT A0 a lications.

    37

  • 8/16/2019 ece project SOFT COPY

    31/51

    MAP &A4 P !g am A))(i"ati!n ) !g ams Inte $a"e ;API<

    This is a library that allows you to write and F!RTRAB rograms that interact

    with =AT A0. $t includes facilities for calling routines from =AT A0 %dynamic

    lin"ing&, calling =AT A0 as a com utational engine, and for reading and writing =AT-

    files.

    Sta ting MAT&A4

    !n /indows latforms, start =AT A0 by double-clic"ing the =AT A0 shortcut

    icon on your /indows des"to . !n B$C latforms, start =AT A0 by ty ing mat lab

    at the o erating system rom t. Wou can customi*e =AT A0 startu . For e am le, you

    can change the directory in which =AT A0 starts or automatically e ecute =AT A0

    statements in a scri t file named startu .m

    MAT&A4 Des=t!)

    /hen you start =AT A0, the =AT A0 des"to a ears, containing tools %gra hical

    user interfaces& for managing files, variables, and a lications associated with

    =AT A0. The following illustration shows the default des"to . Wou can customi*e the

    arrangement of tools and documents to suit your needs. For more information about the

    des"to tools.

    MAT&A4 WOR:ING EN IRONMENT

    MATLAB DESKTOP :- =at lab ;es"to is the main =at lab a lication window.

    The des"to contains five sub windows) the command window, the wor"s ace browser,

    the current directory window, the command history window, and one or more figure

    windows, which are shown only when the user dis lays a gra hic.

    31

  • 8/16/2019 ece project SOFT COPY

    32/51

    The command window is where the user ty es =AT A0

    commands and e ressions at the rom t %``& and where the out ut of those commands

    is dis layed. =AT A0 defines the wor"s ace as the set of variables that the user creates

    in a wor" session. The wor"s ace browser shows these variables and some information

    about them. ;ouble clic"ing on a variable in the wor"s ace browser launches the Array

    2ditor, which can be used to obtain information and income instances edit certain

    ro erties of the variables

    The current ;irectory tab above the wor"s ace tab shows the contents

    of the current directory, whose ath is shown in the current directory window. For

    e am le, in the windows o erating system the ath might be as follows)

    )Y=AT A0Y/or", indicating that directory ]wor"^ is a subdirectory of the main

    directory ]=AT A0^, /#$ # $+ $B+TA 2; $B ;R$92 . clic"ing on the arrow inthe current directory window shows a list of recently used aths.

    =AT A0 uses a search ath to find =-files and other =AT A0

    related files, which are organi*e in directories in the com uter file system. Any file run

    in =AT A0 must reside in the current directory or in a directory that is on search ath.

    0y default, the files su lied with =AT A0 and math wor"s toolbo es are included in

    the search ath. The easiest way to see which directories are on the search ath $t is good

    ractice to add any commonly used directories to the search ath to avoid re eatedly

    having the change the current directory.

    The ommand #istory /indow contains a record of the commands a

    user has entered in the command window, including both current and revious =AT A0

    sessions. >reviously entered =AT A0 commands can be selected and re-e ecuted from

    the command #istory window by right clic"ing on a command or sequence of

    commands.

    Using the MAT&A4 E,it! t! " eate M-6i(es'

    35

  • 8/16/2019 ece project SOFT COPY

    33/51

    The =AT A0 editor is both a te t editor s eciali*ed for creating =-files and agra hical =AT A0 debugger. The editor can a ear in a window by itself, or it can be a

    sub window in the des"to . =-files are denoted by the e tension .m, as in i elu .m. The

    =AT A0 editor window has numerous ull-down menus for tas"s such as saving,

    viewing, and debugging files. 0ecause it erforms some sim le chec"s and also uses

    color to differentiate between various elements of code, this te t editor is recommended

    as the tool of choice for writing and editing =-functions.

    Getting He()'

    The rinci al way to get hel online is to use the =AT A0 hel browser, o ened as a se arate window either by clic"ing on the question mar" symbol %[&

    on the des"to toolbar, or by ty ing hel browser at the rom t in the command window.

    The hel 0rowser is a web browser integrated into the =AT A0 des"to that dis lays a

    #y erte t =ar"u anguage %#T= & documents.

    $t is good ractice to o en the #el 0rowser at the beginning of a

    =AT A0 session to have hel ed readily available during code develo ment or other

    =AT A0 tas".

    =-functions have two ty es of information that can be dis layed by the

    user. The first is called the #1 line, which contains the function name and alone line

    descri tion. The second is a bloc" of e lanation called the #el te t bloc". Ty ing hel

    at the rom t followed by a function name dis lays both the #1 line and the #el te t for

    that function in there command window. !ccasionally, this information can be more u to

    date than the documentation of the =-function in question. Ty ing loo" for edge-all at the

    rom t dis lays the #1 line of all functions that contain the word edge in either the #1

    line or the #el te t bloc". /ords that contain the characters edge also are detected. For

    e am le, the #1 line of a function containing the word olyedge in the #1 line or #el

    te t would also be dis layed.

    Sa ing an, Ret ie ing a W! = Sessi!n'

    33

  • 8/16/2019 ece project SOFT COPY

    34/51

    There are several ways to save and load an entire wor"

    session or selected wor"s ace variables in =AT A0. The sim lest is as follows.

    This o ens a directory window that allows naming the file

    and selecting any folder in the system in which to save it. To save a selected variable

    from the wor"s ace, select the variable with a left clic" and then right-clic" on the

    highlighted area. Then select +ave +election As from the menu that a ears. To select

    multi le variables, use shift clic" or control clic" in the familiar manner, and then use the

    rocedure just described for a single variable to load saved wor"s aces andGor variables,

    left-clic" on the folder icon on the toolbar of the wor"s ace 0rowser window.

    G a)h C!m)!nents

    3:

  • 8/16/2019 ece project SOFT COPY

    35/51

    A gra h, you need to define a coordinate system. Therefore every gra h is laced

    within a es, which are contained by the figure .The actual visual re resentation of the

    data is achieved with gra hics objects li"e lines and surfaces. These objects are drawn

    within the coordinate system defined by the a es, which =AT A0 automatically creates

    s ecifically to accommodate the range of the data. The actual data is stored as ro erties

    of the gra hics objects.

    P(!tting T!!(s

    >lotting tools are attached to figures and create an environment for creating

    6ra hs. These tools enable you to do the following)

    34

  • 8/16/2019 ece project SOFT COPY

    36/51

    >+elect from a wide variety of gra h ty es

    > hange the ty e of gra h that re resents a variable

    >+ee and set the ro erties of gra hics objects

    >Annotate gra hs with te t, arrows, etc.

    > reate and arrange sub lots in the figure

    > ;rag and dro data into gra hs

    ;is lay the lotting tools from the ie/ menu or by clic"ing the lotting tools

    $con in the figure toolbar, as shown in the following icture.

    E,it! De0+gge

    se the 2ditorG;ebugger to create and debug =-files, which are rograms you

    /rite to run =AT A0 functions. The 2ditorG;ebugger rovides a gra hical

    ser interface for te t editing, as well as for =-file debugging. To create or

    2dit an =-file use 6i(e @ Ne/ or 6i(e @ O)en , or use the edit function.

    3D

  • 8/16/2019 ece project SOFT COPY

    37/51

  • 8/16/2019 ece project SOFT COPY

    38/51

    C!,ing

    function C = huffman(D,W,varargin)

    3?

  • 8/16/2019 ece project SOFT COPY

    39/51

    disp( 'HUFFMAN C D!N" !# $ ##!%& N& !F A& $* %A%!&! !# +UA& N ' )

    a = input( ' nt r th no-of m ssag s.m/o0s' )1=21

    for i= 34a W(i) = input( ' nt r th pro/a/i0it. of ach m ssag ' )1 if W(i)52 rror( 'pro/a/i0it. of m ssag s.m/o0 must / positiv ' )1 nd = 6W(i)1

    nddisp( ' A& $* %A%!&! F M ##A" # M% ' )disp( )if ==3 disp( 'HUFFMAN C D!N" !# $ ##!%& ' )1

    0s rror( 'HUFFMAN C D!N" !# N $ ##!%& ' )

    ndD=718W=9: ; < > :?

    8 HUFFMAN Huffman ncod r-8 C = HUFFMAN(D,W) g n rat s a static minimum@varianc Huffman trand8 corr sponding cod /oo C for th sourc s.m/o0s Bith nonn gativ8 B ights giv n /. v ctor W, using a D@ar. output cod a0pha/ t,8 -g- D = 7 for a /inar. output cod a0pha/ t-8 W is an N@v ctor of nonn gativ sourc s.m/o0 B ights, Bh r N isth8 num/ r of sourc s.m/o0s-8 h g n rat d Huffman cod C minimi s th B ight d cod Bord0 ngth,8 -g- if th B ight is th pro/a/i0it. of th sourc s.m/o0, th n C8 minimi s th p ct d cod Bord 0 ngth-8 C is an N@v ctor of strings (i- - c 00 arra.) giving th8 cod Bords for ach of th N sourc s.m/o0s in W-88 C = HUFFMAN(D,W,&,'scr n') additiona00. disp0a.s a simp0 t t8 r ndition of th r su0ting Huffman cod tr , Bith th sourcs.m/o08 0a/ 0s giv n /. &- & is an N@v ctor of strings (i- - c 00 arra.)8 containing th 0a/ 0s for ach of th N sourc s.m/o0s-88 C = HUFFMAN(D,W,&,'dot') additiona00. cr at s a D fi0 d scri/ingth8 r su0ting Huffman cod tr , and runs "raphvi D to cr at th8 corr sponding $N" imag - h output fi0 s ar automatica00.8 tim @stamp d- h sourc s.m/o0 0a/ 0s ar giv n /. &, Bhich is an8 N@v ctor of strings (i- - c 00 arra.) containing th 0a/ 0s for

    ach8 of th N sourc s.m/o0s- $0 as nsur that "raphvi D isacc ssi/08 from th curr nt dir ctor. ( -g- /. adding it to th path)-88 Mu0tip0 output can / r Eu st d using a sing0 command, -g-8 C = HUFFMAN(D,W,&,'dot','scr n')

    3I

  • 8/16/2019 ece project SOFT COPY

    40/51

    8 A&!DA !N$U A*"UM N # 8 ch c v ctor W d scri/ing th nonn gativ sourc s.m/o0 B ightsif Gisv ctor(W) rror( '!nput argum nt W must / a v ctor-' )1

    nd if min(W) 5 2 rror( '!nput argum nt W must contain nonn gativ ntri s-' )1

    nd 8 num/ r of sourc s.m/o0sN = 0 ngth(W)1 8 ch c cod a0pha/ t si Dif Gissca0ar(D) rror( '!nput argum nt D must / a sca0ar-' )1

    nd cod A0pha/ t = '237:< >;I A%CD F"H!JK&MN $+*# U WL ' 1

    if D 0 ngth(cod A0pha/ t) rror(9 'Not nough 0it ra0 charact rs to accommodat r Eu st d coda0pha/ t1 ' --- 'p0 as modif. th sourc cod manua00. to add morcharact rs-' ?)1

    nd 8 sourc s.m/o0 0a/ 0sif Gis mpt.(varargin) & = vararginO3P1

    if Gisv ctor(&) rror( '!nput argum nt & must / a v ctor-' )1 nd

    if 0 ngth(&) G= N rror( '!nput argum nts W and & must / v ctors of th sam0 ngth-' )1 nd

    nd 8 output t.p soutput#cr n = fa0s 1outputDot = fa0s 1 for i = 740 ngth(varargin) output = vararginOiP1

    if strcmp(output, 'scr n' ) output#cr n = tru 1 0s if strcmp(output, 'dot' ) outputDot = tru 1 0s rror(9 '!nput argum nt ''' output ''' is not a r cogni d outputt.p -' ?)1 nd

    nd

    :7

  • 8/16/2019 ece project SOFT COPY

    41/51

    8 %U!&D HUFFMAN C D * 8 cr at a tr nod for ach of th N sourc s.m/o0sfor i = 34N H(i)-B ight = W(i)1 8 B ight H(i)-chi0dr n = 9?1 8 this nod has no chi0dr n H(i)-h ight = 21 8 this su/tr has h ight 2 H(i)- pos d = tru 1 8 this nod is pos d H(i)-dumm. = fa0s 1 8 this nod is not a dumm.

    nd 8 ch c if dumm. nod s ar n d d

    = f0oor((N@3) Q (D@3))1nDumm.Nod s = 21if (N@3) @ R(D@3) G= 2 nDumm.Nod s = ( 63) R (D@3) @ (N@3)1

    for i = 34nDumm.Nod s

    H(N6i)-B ight = 21 8 B ight H(N6i)-chi0dr n = 9?1 8 this nod has no chi0dr n H(N6i)-h ight = 21 8 this su/tr has h ight 2 H(N6i)- pos d = tru 1 8 this nod is pos d H(N6i)-dumm. = tru 1 8 this nod is a dumm. nd

    nd 8 it rativ 0. m rg D su/tr s at a tim , unti0 on0. 3 su/tr is 0 ftBhi0 sum(9H- pos d? == tru ) 3

    8 sort pos d nod s in asc nding ord r of B ight pos d!ndic s = find(9H- pos d? == tru )1 a00W ights = 9H-B ight?1 a00H ights = 9H-h ight?1 9 ,!? = sortroBs(9a00W ights( pos d!ndic s)'a00H ights( pos d!ndic s)'?, 93 7?)1 sort d!ndic s = pos d!ndic s(!)1

    8 com/in first D nod s into a n B nod com/in d!ndic s = sort d!ndic s(34D)1 for i = 34D H(com/in d!ndic s(i))- pos d = fa0s 1 nd

    ii = 0 ngth(H) 6 31 H(ii)-B ight = sum(a00W ights(com/in d!ndic s))1 8 sum of B ights H(ii)-chi0dr n = sort d!ndic s(34D)1 8 this nod has D chi0dr n H(ii)-h ight = ma (a00H ights(com/in d!ndic s)) 6 31 8 h ight of n Bsu/tr H(ii)- pos d = tru 1 8 this nod is pos d H(ii)-dumm. = fa0s 1 8 this nod is not a dumm.

    nd 8 $A*# C D * " N *A C D W *D# root!nd = find(9H- pos d? == tru )1

    :1

  • 8/16/2019 ece project SOFT COPY

    42/51

    if issca0ar(root!nd ) == fa0s rror( '!nt rna0 rror /ui0ding Huffman tr -' )1

    nd 8 initia0i r turn va0u , i- - cod Bordsfor i = 34N COiP = '' 1

    nd if outputDot 8 op n D output fi0 for Briting fi0 nam = 9 'dot-' dat str(noB, '....mmdd-HHMM##' )?1 fid = fop n(9fi0 nam '-t t' ?, 'B' )1

    fprintf(fid, 'digraph Huffman OSnran dir= %' )1nd

    8 pars th cod tr , / ginning from th rootpars Cod r (root!nd , '' )1

    if output#cr n 8 disp0a. statistics fprintf( 'SnSn# A !# !C#4' )1 fprintf( 'Sn Num/ r of sourc s.m/o0s N = 8d' , N)1

    if nDumm.Nod s 2 fprintf( 'Sn Num/ r of dumm. nod s add d = 8d' , nDumm.Nod s)1 nd

    tB = 21 for i = 34N tB = tB 6 W(i)1 nd fprintf( 'Sn ota0 B ight = sumOi=34NP WTi = 8g' , tB)1

    Bc0 = 21 for i = 34N Bc0 = Bc0 6 0 ngth(COiP) R W(i)1 nd fprintf( 'Sn (A) W ight d cod Bord 0 ngth = sumOi=34NP 0 ngth(CTi)R WTi = 8g' , Bc0)1

    B00 = 21 for i = 34N B00 = B00 6 0 ngth(&OiP) R W(i)1 nd fprintf( 'Sn (%) W ight d 0a/ 0 0 ngth = sumOi=34NP 0 ngth(&Ti)R WTi = 8g' , B00)1

    fprintf( 'Sn *atio (A) Q (%) = 8g' , Bc0 Q B00)1

    fprintf( 'SnSn' )1nd

    8 ca00 "raphvi dot if r Eu st dif outputDot fprintf(fid, 'SnPSn' )1

    :5

  • 8/16/2019 ece project SOFT COPY

    43/51

    fc0os (fid)1 va0(9 ' dot @ png ' fi0 nam '-t t @o ' fi0 nam '-png' ?)1

    8 disp0a. imag using d fau0t t rna0 program va0(9 ' ' fi0 nam '-png' ?)1

    8 disp0a. imag in MA &A% 89L, map? = imr ad(9fi0 nam '-png'?)1 8figur (3)1 8imag (L)1 8co0ormap(map)1 8a is off1 8a is imag 1

    nd

    8 N # D FUNC ! N#

    function pars Cod r (nod !nd ,nod Cod Bord) 8 $ars nod s in th cod tr r cursiv 0.-

    nod = H(nod !nd )1

    if output#cr n

    8 cr at padding string padding = 9 '' ?1 for 0 = 340 ngth(nod Cod Bord)1 padding = 9padding ' ' ?1 nd nd

    if output#cr n if nod !nd == root!nd root!ndicator = ' (* )' 1 0s root!ndicator = '' 1 nd nd

    if is mpt.(nod -chi0dr n) if nod -dumm. == tru 8 this is a dumm. 0 af nod if output#cr n fprintf( 'Sn8s9''8s'',8g?8s (DUMM )' , --- padding, nod Cod Bord,nod -B ight,root!ndicator)1 nd

    if outputDot fprintf(fid, 'SnN D !D8s 9shap =r cord,0a/ 0=V''8s''SSn98g?SSn(DUMM )8sV, st.0 =fi00 d,fi00co0or=0ightgr .?' , --- nod Cod Bord, nod Cod Bord, nod -B ight,root!ndicator)1 nd 0s 8 this is a sourc s.m/o0 (non@dumm. 0 af nod )

    :3

  • 8/16/2019 ece project SOFT COPY

    44/51

    COnod !nd P = nod Cod Bord1

    if output#cr n fprintf( 'Sn8s9''8s'',8g? ''8s''8s (# U*C )' , --- padding, nod Cod Bord, nod -B ight,&Onod !nd P, root!ndicator)1 nd

    if outputDot fprintf(fid, 'SnN D !D8s 9shap =r cord,0a/ 0=V''8s''SSn98g?SSn''8s''SSn(# U*C )8sV, st.0 =fi00 d,fi00co0or=sa0mon?' , --- nod Cod Bord, nod Cod Bord, nod -B ight,&Onod !nd P, root!ndicator )1 nd nd 0s 8 this nod is not a 0 af if output#cr n fprintf( 'Sn8s9''8s'',8g?8s' , ---

    padding, nod Cod Bord, nod -B ight, root!ndicator)1 nd

    if outputDot fprintf(fid, 'SnN D !D8s 9shap =r cord,0a/ 0=V''8s''SSn98g?SSn8sV, st.0 =fi00 d, fi00co0or=Bhit ?' , --- nod Cod Bord, nod Cod Bord, nod -B ight,root!ndicator)1 nd

    8 r curs into chi0d nod s for 0 = 340 ngth(nod -chi0dr n) chi0dCod Bord = 9nod Cod Bord, cod A0pha/ t(0)?1

    if outputDot if H(nod -chi0dr n(0))-dumm. == tru 8 chi0d is a dumm. nod fprintf(fid, 'SnN D !D8s @ N D !D8s 9sam tai0,0a/ 0=V8sV, st.0 =dott d?' , --- nod Cod Bord, chi0dCod Bord,cod A0pha/ t(0))1 0s 8 chi0d is not a dumm. nod fprintf(fid, 'SnN D !D8s @ N D !D8s 9sam tai0,0a/ 0=V8sV?' , --- nod Cod Bord, chi0dCod Bord,cod A0pha/ t(0))1 nd nd

    pars Cod r (nod -chi0dr n(0), chi0dCod Bord)1 nd nd nd

    nd

    ::

  • 8/16/2019 ece project SOFT COPY

    45/51

    function C = huffman(D,W,varargin)disp( 'HUFFMAN C D!N" !# $ ##!%& N& !F A& $* %A%!&! !# +UA&

    N ' )a = input( ' nt r th no-of m ssag s.m/o0s' )1

    =21for i= 34a W(i) = input( ' nt r th pro/a/i0it. of ach m ssag ' )1 if W(i)52 rror( 'pro/a/i0it. of m ssag s.m/o0 must / positiv ' )1 nd = 6W(i)1

    nddisp( ' A& $* %A%!&! F M ##A" # M% ' )disp( )if ==3 disp( 'HUFFMAN C D!N" !# $ ##!%& ' )1

    0s rror( 'HUFFMAN C D!N" !# N $ ##!%& ' )

    ndD=718W=9: ; < > :?8 HUFFMAN Huffman ncod r-8 C = HUFFMAN(D,W) g n rat s a static minimum@varianc Huffman trand8 corr sponding cod /oo C for th sourc s.m/o0s Bith nonn gativ8 B ights giv n /. v ctor W, using a D@ar. output cod a0pha/ t,8 -g- D = 7 for a /inar. output cod a0pha/ t-8 W is an N@v ctor of nonn gativ sourc s.m/o0 B ights, Bh r N isth8 num/ r of sourc s.m/o0s-8 h g n rat d Huffman cod C minimi s th B ight d cod Bord

    0 ngth,8 -g- if th B ight is th pro/a/i0it. of th sourc s.m/o0, th n C8 minimi s th p ct d cod Bord 0 ngth-8 C is an N@v ctor of strings (i- - c 00 arra.) giving th8 cod Bords for ach of th N sourc s.m/o0s in W-88 C = HUFFMAN(D,W,&,'scr n') additiona00. disp0a.s a simp0 t t8 r ndition of th r su0ting Huffman cod tr , Bith th sourcs.m/o08 0a/ 0s giv n /. &- & is an N@v ctor of strings (i- - c 00 arra.)8 containing th 0a/ 0s for ach of th N sourc s.m/o0s-88 C = HUFFMAN(D,W,&,'dot') additiona00. cr at s a D fi0 d scri/ingth8 r su0ting Huffman cod tr , and runs "raphvi D to cr at th8 corr sponding $N" imag - h output fi0 s ar automatica00.8 tim @stamp d- h sourc s.m/o0 0a/ 0s ar giv n /. &, Bhich is an8 N@v ctor of strings (i- - c 00 arra.) containing th 0a/ 0s for

    ach8 of th N sourc s.m/o0s- $0 as nsur that "raphvi D isacc ssi/08 from th curr nt dir ctor. ( -g- /. adding it to th path)-8

    :4

  • 8/16/2019 ece project SOFT COPY

    46/51

    8 Mu0tip0 output can / r Eu st d using a sing0 command, -g-8 C = HUFFMAN(D,W,&,'dot','scr n')

    8 A&!DA !N$U A*"UM N # 8 ch c v ctor W d scri/ing th nonn gativ sourc s.m/o0 B ightsif Gisv ctor(W) rror( '!nput argum nt W must / a v ctor-' )1

    nd if min(W) 5 2 rror( '!nput argum nt W must contain nonn gativ ntri s-' )1

    nd 8 num/ r of sourc s.m/o0sN = 0 ngth(W)1 8 ch c cod a0pha/ t si Dif Gissca0ar(D)

    rror( '!nput argum nt D must / a sca0ar-' )1nd

    cod A0pha/ t = '237:< >;I A%CD F"H!JK&MN $+*# U WL ' 1if D 0 ngth(cod A0pha/ t) rror(9 'Not nough 0it ra0 charact rs to accommodat r Eu st d coda0pha/ t1 ' --- 'p0 as modif. th sourc cod manua00. to add morcharact rs-' ?)1

    nd 8 sourc s.m/o0 0a/ 0sif Gis mpt.(varargin) & = vararginO3P1

    if Gisv ctor(&) rror( '!nput argum nt & must / a v ctor-' )1 nd

    if 0 ngth(&) G= N rror( '!nput argum nts W and & must / v ctors of th sam0 ngth-' )1 nd

    nd 8 output t.p soutput#cr n = fa0s 1outputDot = fa0s 1 for i = 740 ngth(varargin) output = vararginOiP1

    if strcmp(output, 'scr n' ) output#cr n = tru 1 0s if strcmp(output, 'dot' ) outputDot = tru 1 0s

    :D

  • 8/16/2019 ece project SOFT COPY

    47/51

    rror(9 '!nput argum nt ''' output ''' is not a r cogni d outputt.p -' ?)1 nd

    nd

    8 %U!&D HUFFMAN C D * 8 cr at a tr nod for ach of th N sourc s.m/o0sfor i = 34N H(i)-B ight = W(i)1 8 B ight H(i)-chi0dr n = 9?1 8 this nod has no chi0dr n H(i)-h ight = 21 8 this su/tr has h ight 2 H(i)- pos d = tru 1 8 this nod is pos d H(i)-dumm. = fa0s 1 8 this nod is not a dumm.

    nd 8 ch c if dumm. nod s ar n d d

    = f0oor((N@3) Q (D@3))1nDumm.Nod s = 21

    if (N@3) @ R(D@3) G= 2 nDumm.Nod s = ( 63) R (D@3) @ (N@3)1

    for i = 34nDumm.Nod s H(N6i)-B ight = 21 8 B ight H(N6i)-chi0dr n = 9?1 8 this nod has no chi0dr n H(N6i)-h ight = 21 8 this su/tr has h ight 2 H(N6i)- pos d = tru 1 8 this nod is pos d H(N6i)-dumm. = tru 1 8 this nod is a dumm. nd

    nd 8 it rativ 0. m rg D su/tr s at a tim , unti0 on0. 3 su/tr is 0 ftBhi0 sum(9H- pos d? == tru ) 3

    8 sort pos d nod s in asc nding ord r of B ight pos d!ndic s = find(9H- pos d? == tru )1 a00W ights = 9H-B ight?1 a00H ights = 9H-h ight?1 9 ,!? = sortroBs(9a00W ights( pos d!ndic s)'a00H ights( pos d!ndic s)'?, 93 7?)1 sort d!ndic s = pos d!ndic s(!)1

    8 com/in first D nod s into a n B nod com/in d!ndic s = sort d!ndic s(34D)1 for i = 34D H(com/in d!ndic s(i))- pos d = fa0s 1 nd

    ii = 0 ngth(H) 6 31 H(ii)-B ight = sum(a00W ights(com/in d!ndic s))1 8 sum of B ights H(ii)-chi0dr n = sort d!ndic s(34D)1 8 this nod has D chi0dr n H(ii)-h ight = ma (a00H ights(com/in d!ndic s)) 6 31 8 h ight of n Bsu/tr H(ii)- pos d = tru 1 8 this nod is pos d H(ii)-dumm. = fa0s 1 8 this nod is not a dumm.

    nd

    :

  • 8/16/2019 ece project SOFT COPY

    48/51

  • 8/16/2019 ece project SOFT COPY

    49/51

    8 ca00 "raphvi dot if r Eu st dif outputDot fprintf(fid, 'SnPSn' )1 fc0os (fid)1 va0(9 ' dot @ png ' fi0 nam '-t t @o ' fi0 nam '-png' ?)1

    8 disp0a. imag using d fau0t t rna0 program va0(9 ' ' fi0 nam '-png' ?)1

    8 disp0a. imag in MA &A% 89L, map? = imr ad(9fi0 nam '-png'?)1 8figur (3)1 8imag (L)1 8co0ormap(map)1 8a is off1 8a is imag 1

    nd

    8 N # D FUNC ! N#

    function pars Cod r (nod !nd ,nod Cod Bord) 8 $ars nod s in th cod tr r cursiv 0.-

    nod = H(nod !nd )1

    if output#cr n 8 cr at padding string padding = 9 '' ?1 for 0 = 340 ngth(nod Cod Bord)1 padding = 9padding ' ' ?1 nd nd

    if output#cr n if nod !nd == root!nd root!ndicator = ' (* )' 1 0s root!ndicator = '' 1 nd nd

    if is mpt.(nod -chi0dr n) if nod -dumm. == tru 8 this is a dumm. 0 af nod if output#cr n fprintf( 'Sn8s9''8s'',8g?8s (DUMM )' , --- padding, nod Cod Bord,nod -B ight,root!ndicator)1 nd

    if outputDot fprintf(fid, 'SnN D !D8s 9shap =r cord,0a/ 0=V''8s''SSn98g?SSn(DUMM )8sV, st.0 =fi00 d,fi00co0or=0ightgr .?' , ---

    :I

  • 8/16/2019 ece project SOFT COPY

    50/51

    nod Cod Bord, nod Cod Bord, nod -B ight,root!ndicator)1 nd 0s 8 this is a sourc s.m/o0 (non@dumm. 0 af nod ) COnod !nd P = nod Cod Bord1

    if output#cr n fprintf( 'Sn8s9''8s'',8g? ''8s''8s (# U*C )' , --- padding, nod Cod Bord, nod -B ight,&Onod !nd P, root!ndicator)1 nd

    if outputDot fprintf(fid, 'SnN D !D8s 9shap =r cord,0a/ 0=V''8s''SSn98g?SSn''8s''SSn(# U*C )8sV, st.0 =fi00 d,fi00co0or=sa0mon?' , --- nod Cod Bord, nod Cod Bord, nod -B ight,&Onod !nd P, root!ndicator )1 nd

    nd 0s 8 this nod is not a 0 af if output#cr n fprintf( 'Sn8s9''8s'',8g?8s' , --- padding, nod Cod Bord, nod -B ight, root!ndicator)1 nd

    if outputDot fprintf(fid, 'SnN D !D8s 9shap =r cord,0a/ 0=V''8s''SSn98g?SSn8sV, st.0 =fi00 d, fi00co0or=Bhit ?' , --- nod Cod Bord, nod Cod Bord, nod -B ight,root!ndicator)1 nd

    8 r curs into chi0d nod s for 0 = 340 ngth(nod -chi0dr n) chi0dCod Bord = 9nod Cod Bord, cod A0pha/ t(0)?1

    if outputDot if H(nod -chi0dr n(0))-dumm. == tru 8 chi0d is a dumm. nod fprintf(fid, 'SnN D !D8s @ N D !D8s 9sam tai0,0a/ 0=V8sV, st.0 =dott d?' , --- nod Cod Bord, chi0dCod Bord,cod A0pha/ t(0))1 0s 8 chi0d is not a dumm. nod fprintf(fid, 'SnN D !D8s @ N D !D8s 9sam tai0,0a/ 0=V8sV?' , --- nod Cod Bord, chi0dCod Bord,cod A0pha/ t(0))1 nd nd

    pars Cod r (nod -chi0dr n(0), chi0dCod Bord)1 nd

    47

  • 8/16/2019 ece project SOFT COPY

    51/51

    nd nd

    nd

    RE6ERENCES

    1. ;A9$; A. # FF=AB, +e t. 1II1, rofile 0ac"ground story) +cientificAmerican, . 4:-4?.

    5. www. ilin .com

    3. www.google.com

    :. www.icgst.com

    4. # FF=AB, ;. A. A method for the construction of minim redundancy codes. $n >roc.$R2 :7%1I41&, 17I?-1171.

    D. 6A A62R, R. 6. 9ariations on a theme by #uffman. $222 Trans. $nj Theory $T-

    5:, D %Bov.1I