Project 2: Non-Uniform PCM CODEC in the Presence of Noise
This project aims to simulate a simple audio system communication system over an AWGN channel. The
system includes a PCM CODEC with -law companding. The project is divided into two stages:
• Stage 1: Converting the audio file into a polar digital sequence and assessing the effects of sampling and
quantization on the quality of the audio file.
• Stage 2: Passing the polar sequence through an AWGN channel and recovering the audio file at the
receiver.
General Logistics of the Project
• The project will be implemented by teams of two or three students.
• Stage 1 of the project will be submitted by Sunday May 15th (soft-deadline).
• Stage 2 of the project will be submitted by Thursday May 22nd (hard-deadline).
• You need to submit a viable code that runs without problem in addition to sample audio files of your
findings.
• You need to submit a report of findings, i.e., the maximum downsampling factor, the minimum number of
quantization bits, and the minimum SNR that result in an acceptable quality for the received audio file.
• Selected groups will require to defend their project in front of me and/or the TAs.
Stage 1: Converting the Audio File into a Polar Digital Sequence and
Investigation of Sampling and Quantization Effects
In stage 1, we aim to construct a PCM Encoder with a compressing stage that is able to convert an audio file
into a polar digital sequence according to the following block diagram:
For Stage 1, you need to submit the following results
1. A viable code of the PCM Encoder for arbitrary .
2. A viable code of the PCM Decoder that can recover the analog audio file.
3. Block diagram of the designed PCM decoder.
4. Recovered audio files with and 32 with no companding. Provide sufficient comments and
explanations of the resultant behavior in the report.
5. Recovered audio files with and 3 with no companding. Provide sufficient comments and
explanations of the resultant behavior in the report.
6. Recovered audio files with with and without an expander in the PCM decoder. Provide sufficient
comments and explanations of the resultant behavior in the report.
1
7. By observing the quality of the recovered (output) audio file, identify the maximum downsampling factor
N, the minimum number of bits R for sufficiently clear audio signal.
Initialization
It is advisable to initialize the code by using
clc;
clear all;
System Parameters and Reading the Audio File
It is adviable to collect all controlling parameters of the code at the beginning of the code as follows. In stage
1, we have the following parameters: the downsampling factor the number of bits per sample and the
companding factor
downsampling_factor=2;
bits_per_sample=10;
companding_factor=255;
Read the accompained audio file using the audioread MATLAB built-in function. It is important to read the
sampling frequency of the original audio file.
Downsampling Effects
Downsampling by a factor of Nimplies keeping 1 sample and throwing the next samples. Hence, one
can implement downsampling by either the command downsample or using a simple indexing that chooses a
sample every Nsamples.
Note: Upon recovering the signal again, you need to save (or simply sound) your signal with the sampling rate
to keep the "tempo" of the song as the original.
Uniform Quantization Effects
It is required to design a general mid-rise uniform quantizer with R bits. This can be implemented using the
MATLAB command quantiz. The function requires defining the following:
• Partitions: These are the distinct endpoints of different ranges (decision levels), specified as a row vector.
• Codebook: Quantization value (representation levels) for each partition, specified as a row vector.
In your report, you need to speicify the partitions and codebook for the designed quantizer. The function
provides the quantized sample value in addition to the index of the level as:
2
[index,signal_quantized] = quantiz(signal,partition,codebook);
Line Coding: Polar Code
The final stage of the PCM encoder is the line code. Line coding represents each quantization level with
a binary code. This can be done by converting the index vector that is provided by the quantizer into bits.
You can use the function dec2bin to convert from decimal to binary string. You need to
serialize the output into a row vector. You may need to convert the data type of
the output to double (instead of character). At the end of this step, you will
have a binary vector representing the audio file. We denote this vector by b.
To represent the output bits using polar coding, we use th following simple linear
transformation:
bits_polar=2*bits-1;
In your report, explain why this linear transformation implements polar line code.
Companding
The MATLAB function compand implements the compressor/expander of the law. You need to investigate
the effect of companding on the quality of the audio signal. In addition, you need to investigate what happens
when you bypass the expander in the decoder.
PCM Decoder
You need to design the PCM decoder such that the audio file is recovered successfully at the receiver from the
polar sequence . Note that as a sanity check, if , , and no companding, the output audio file
should be exactly the same as the original audio file.
Bonus for Stage 1:
• Save the audio file with a sampling frequency that is equal to the original sampling frequency Provide
sufficient comments and explanations of the resultant behavior in the report.
• Implement the mid-tread version of the PCM CODEC.
• Implement differential encoding instead of polar line code. Adjust the decision threshold and detection
accordingly.
3
Stage 2: Investigation of the Effect of AWGN on the Audio File recovery
In stage 2, we aim to investigate the effect of AWGN noise on the the polar sequence transmission and the
recovered audio file. The overall system is as follows:
For Stage 2, you need to submit the following results
1. A viable code for the overall system in the presence of noise.
2. A BER curve showing the probability of error versus the SNR . Provide sufficient comments and
explanations of the resultant behavior in the report.
3. The recovered audio files with SNR=0, 5, 10, 15 dB without downsampling. and with 24-bit quantization.
AWGN Noise Generation
To generate AWGN noise, we use the function randn which generates i.i.d. Gaussian distributed samples with
zero mean and unit variance, i.e., To generate the noise according to the required SNR, we note
first that with a polar sequence , the power of the transmitted sequence is 1, hence the power of
noise is equal to . We first get the SNR in linear scale as:
Next, we generate a noise vector n as follows:
noise_vector=1/sqrt(SNR)*randn(1,length(transmitted_signal));
received_signal=transmitted_signal+noise_vector;
where transmitted_signal corresponds to the polar sequence
Detection
4
To detect the received signal, we need to use a threshold device. The threshold device compares received
sequence with zero, i.e., it gets the sign of the received sample according to:
detected_polar=sign(received_signal);
detected_bits=1/2*(detected_polar+1);
Probability of Error Calculation
To calculate the probability of error, we simply count the number of different bits from the detected bits and the
original bits from the quantizer. we divide the number of errors by the length of the transmitted signal to find the
probability.