Skip to main content
Engineering LibreTexts

7.6: Numerical Experiment (Huffman Codes)

  • Page ID
    9994
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The paragraph below contains Lincoln's Gettysburg Address. Ignore special symbols like periods and ignore the distinction between lowercase and uppercase letters. Compute the relative frequency of occurrence for each of the 26 letters of the alphabet. Write a MATLAB program to generate a binary tree for the Huffman code of the Gettysburg Address. When you have generated the code, compute the average code word length

    \[L=\sum_{i=1}^{26} \frac{n_{i}}{N} l_{i} \nonumber \]

    where \(\frac{n_{i}}{N}\) is the relative frequency for symbol \(i\) and \(l_i\) is the code word length for symbol \(i\). Compare \(L\) with the entropy

    \[H=-\sum_{i=1}^{26} \frac{n_{i}}{N} \log _{2} \frac{n_{i}}{N}=\sum_{i=1}^{26} \frac{n_{i}}{N} \log _{2} \frac{N}{n_{i}} \nonumber \]

    and compare \(L\) to \(\log_2 26\). Interpret your findings.

    Gettysburg Address

    Fourscore and seven years ago, our fathers brought forth upon this
    continent a new nation, conceived in liberty and dedicated to the proposition
    that all men are created equal. Now we are engaged in a great civil war,
    testing whether that nation or any nation so conceived and so dedicated can
    long endure. We are met on a great battlefield of that war. We have come
    to dedicate a portion of that field as a final resting-place for those who have
    given their lives that that nation might live. It is altogether fitting and proper
    that we should do this. But in a larger sense, we cannot dedicate, we cannot
    consecrate, we cannot hallow this ground. The brave men, living and dead,
    who struggled here have consecrated it far above our power to add or detract.
    The world will little note nor long remember what we say here, but it can
    never forget what they did here. It is for us the living rather to be dedicated
    here to the unfinished work which they who fought here have thus far so nobly
    advanced. It is rather for us to be here dedicated to the great task remaining
    before us–that from these honored dead we take increased devotion to that
    cause for which they gave the last full measure of devotion–that we here
    highly resolve that these dead should not have died in vain, that this nation
    under God shall have a new birth of freedom, and that government of the
    people, by the people, for the people shall not perish from the Earth.
                  -Abraham Lincoln, November 19, 1863

    This page titled 7.6: Numerical Experiment (Huffman Codes) is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Louis Scharf (OpenStax CNX) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.