ECE317 Lab5 Digital Signal Processing
Important Disclaimer
The goal of this laboratory experiment is to demonstrate the basic ideas behind transform-
based signal compression.
The method used in this lab is greatly simplified compared to real audio compression
standards such as MP3, AAC, or other modern codecs.
Real audio compression systems include many additional techniques such as
• psychoacoustic models
• adaptive bit allocation
• perceptual weighting
• quantization strategies
• entropy coding
None of these sophisticated techniques are implemented in this lab.
Instead, the goal is simply to illustrate the basic concept that signals can often be repre-
sented efficiently in the frequency domain. By keeping only the most important frequency-
domain coefficients, we can reconstruct an approximation of the signal while storing far fewer
values.
Introduction
Digital audio signals can require large amounts of storage if saved in raw form.
For example, CD-quality audio typically uses
• sampling rate: 44.1 kHz
• 16 bits per sample
• 2 channels (stereo)
The resulting data rate is approximately
44,100 × 16 × 2 = 1.41 Mbps.
Because of this large data rate, most audio distributed over the internet uses compression.
One common approach is transform coding. In this approach, short segments of the
signal are transformed into the frequency domain. Often, a large portion of the signal energy
is concentrated in a relatively small number of transform coefficients.
1
If only those important coefficients are retained, the signal can still be reconstructed with
acceptable quality.
In this lab you will explore this idea using two transforms:
• the Discrete Fourier Transform (DFT)
• the Discrete Cosine Transform (DCT)
Audio Signal
The audio file used in this experiment is
positive sound [Link]
The signal will be divided into frames of length
N = 64
samples.
Provided MATLAB Code
A MATLAB program named
Lab 5 DFT.m
is provided.
This code already performs the DFT-based portion of the experiment. The code
• reads the audio signal
• divides the signal into frames of length N = 64
• computes the DFT of each frame
• retains the first L low-frequency coefficients
• reconstructs the signal
• computes reconstruction error metrics
• generates several plots
You should use this provided code to complete the DFT portion of the lab.
Afterward, you will modify this code to perform the same experiment using the Discrete
Cosine Transform (DCT).
2
Part 1: Inspect the Original Signal
Plot the first 1000 samples of the original signal.
This should represent the time-domain waveform
x[n]
for
n = 1, 2, . . . , 1000.
Label the axes appropriately.
Part 2: Magnitude Spectrum of the DFT
Using the provided MATLAB code, compute the 64-point DFT of a representative frame of
the signal.
Plot the magnitude of the DFT
|X[k]|
as a function of the frequency index k.
This plot illustrates the concept of energy compaction. If most of the signal energy
appears in a relatively small number of coefficients, then it may be possible to keep only
those coefficients while still reconstructing a reasonable approximation to the original signal.
Part 3: DFT-Based Compression
Using the provided MATLAB code, perform the compression experiment using the Discrete
Fourier Transform.
For each frame:
1. Compute the 64-point DFT.
2. Retain only the first L low-frequency coefficients.
3. Set the remaining coefficients to zero.
4. Reconstruct the missing conjugate-symmetric coefficients.
5. Compute the inverse DFT to reconstruct the frame.
Perform this experiment for
L = 10, L = 5, L = 3.
3
DFT Compression Ratio
The DFT coefficients are generally complex-valued.
• The first coefficient (DC term) is purely real.
• The remaining L − 1 retained coefficients are complex.
Each complex coefficient requires two real numbers to store.
Therefore the total number of stored real values per frame is
1 + 2(L − 1) = 2L − 1.
The compression ratio is therefore
64
CRDF T = .
2L − 1
Discrete Cosine Transform (DCT)
The second part of this lab uses the Discrete Cosine Transform.
For a signal x[n] of length N , the DCT is defined as
N −1
X π 1
X[k] = x[n] cos n+ k
n=0
N 2
for
k = 0, 1, . . . , N − 1.
The inverse transform (IDCT) is
N −1
1 X π 1
x[n] = X[k] cos n+ k .
N k=0 N 2
Unlike the DFT, the coefficients produced by the DCT are real-valued. No complex
numbers appear in the transform.
Because of this property, the DCT is often more efficient for compression applications.
Using the DCT in MATLAB
MATLAB provides built-in functions for the DCT and its inverse.
X = dct(x)
xhat = idct(X)
These functions are used in essentially the same way as the FFT and inverse FFT func-
tions.
4
Part 4: DCT-Based Compression
Modify the provided MATLAB program so that it performs the same experiment using the
DCT instead of the DFT.
Compute the DCT of each frame and retain only the first L coefficients.
Because the DCT coefficients are real-valued, conjugate symmetry is not required.
DCT Compression Ratio
Since the DCT coefficients are real-valued, storing L coefficients requires storing only L real
numbers.
Therefore the compression ratio is
64
CRDCT = .
L
Part 5: Magnitude Spectrum of the DCT
For the same representative frame used earlier, compute the DCT and plot the magnitude
of the DCT coefficients
|C[k]|.
Compare this plot with the magnitude DFT plot.
Part 6: Matching Compression Ratios
Choose a value of L for the DCT that produces approximately the same compression ratio
as the DFT case. IMPORTANT: These will not be the same as used in the DFT
Repeat the DFT experiments with the DCT using these newly calculated values of L.
Comparison and Analysis
Compare the DFT and DCT methods using:
• time-domain plots
• magnitude coefficient plots
• MSE
• RMSE
• SNR
• listening tests
5
Discuss which transform provides better reconstruction quality for the same compression
ratio.
When examining the reconstructed signals, pay particular attention to the locations
where the signal transitions from one 64-sample frame to the next.
Questions:
• Do you notice any visible or audible artifacts near the frame boundaries (multiples of
64 samples)?
• Are these effects different when using the DFT versus the DCT?
• Provide a brief explanation of your observations.
Deliverables
Your lab report should include
• the time-domain plot of samples 1 through 100
• the magnitude DFT plot
• the magnitude DCT plot
• reconstruction plots
• MSE, RMSE, and SNR values
• compression ratios for both transforms
• answers to the boundary observation question