# Lab 1: Lossless coding of audio and still images

## Task

The goal of the lab is to make simple random models for some different signals (audio and images), calculate entropies for the models and calculate data rates given Huffman coding of the signals. You don't have to find the actual codewords in the Huffman codes, only the resulting rates are important.The work should be done in groups of 1 or 2 students.

Examination of the lab is by written report.

## Audio signals

The audio signals consist of two music signals and one speech signal. The music signals are mono, sampled with 44.1 kHz sampling frequency and quantized to 8 bits/sample (256 levels). The speech signal is mono, sampled with 8 kHz sampling frequency and quantized to 8 bits/sample (256 levels).
In Matlab, WAV files can be easily read using the function **audioread**.
It will return a vector of samples, scaled so that they take values between -1 and 1.
To get integers between -128 and 127 just multiply the signal by 128.

### Entropy estimation

To get an idea of what theoretical performance can be expected, you should estimate some entropies. The entropies to be estimated are H(X_{i}), H(X

_{i},X

_{i+1}) (pair entropy) and H(X

_{i+1}| X

_{i}) (conditional entropy), assuming that the signal can be viewed as a stationary process X

_{i}.

### Memoryless Huffman coding

Calculate what data rate is achieved when simple Huffman coding of individual samples is done, independent of earlier samples.If you don't want to write your own Huffman coder, you can use this function (read the program code to understand how it works).

### Simple predictive coding

In order to take advantage of the memory (dependance) between neighbouring audio samples, you should do simple predictive coding. First you do a prediction p_{i}and then Huffman coding of the prediction error d

_{i}= x

_{i}-p

_{i}, where x

_{i}are the audio samples. Try the following two predictors:

- p
_{i}= x_{i-1} - p
_{i}= 2*x_{i-1}-x_{i-2}

Compare your data rates with the estimated entropies.

Also listen to the audio signals and comment on how the character of the audio affects the data rate.

## Still images

the images are greyscale images quantized to 8 bits/pixel, ie each pixel can take values between 0 (black) and 255 (white). There are three images to test: You can read images in Matlab using the function**imread**. It will return a two dimensional matrix of the type

**uint8**. In order to be able to properly manipulate data, you should convert the images to the data type

**double**(eg

**x=double(x);**).

### Entropy estimation

To get an idea of what theoretical performance can be expected, you should estimate some entropies. The entropies to be estimated are H(X_{i,j}), H(X

_{i,j},X

_{i+1,j}), H(X

_{i,j},X

_{i,j+1}) (pair entropy horizontally and vertically), H(X

_{i+1,j}| X

_{i,j}) and H(X

_{i,j+1}| X

_{i,j}) (conditional entropy horizontally and vertically).

### Memoryless Huffman coding

Calculate what data rates are achieved when simple Huffman coding of individual pixels is done, independent of surrounding pixels.### Simple predictive coding

In order to take advantage of the memory (dependance) between neighbouring pixels, you should do simple predictive coding. First you do a prediction p_{ij}and then Huffman coding of the prediction error d

_{ij}= x

_{ij}-p

_{ij}, where x

_{ij}are the pixel values. Try the following three predictors:

- p
_{i,j}= x_{i-1,j} - p
_{i,j}= x_{i,j-1} - p
_{i,j}= x_{i-1,j}+x_{i,j-1}-x_{i-1,j-1}

Compare the data rates with the estimated entropies.

Comment on how the content of the images affect the rates and entropies.

## Examination

Examination of the lab is by a short written report. Describe how you solved the problems and what your results are. Also include any program code you've written.
Send an electronic version of your report (in PDF format)
to Harald.
**Give the name, person number and email adress of every group member**.

## Deadline

Lab results are reported to Ladok at the same time as exam results, three times a year. If you want to get your points early, you should send in your report no later than**May 27th**.

## Questions?

If you have any questions about the lab, contact Harald.
Informationsansvarig: Harald Nautsch

Senast uppdaterad: 2019-03-25