CT321: DSP Lab - 4: Discrete Cosine Transform
CT321: DSP Lab - 4: Discrete Cosine Transform
1. The Discrete Cosine Transform (written as DCT henceforth) is defined for an N point sequence as:
N −1
π (2n + 1)k
C (k) = α(k) ∑ x [n] cos
2N
, k = 0, . . . , N − 1
n =0
where
r
1
α(k) = , k = 0,
rN
2
= , k 6= 0,
N
and the Inverse DCT is defined as
N −1
π (2n + 1)k
x [n] = ∑ α(k )C (k ) cos
2N
, n = 0, . . . , N − 1
k =0
Note that this is a transform from R N to R N for a real valued signal. DCT is also an orthogonal
transform, i.e., if the matrix representing DCT is D then DD T = D T D = Id. Plot the 8 basis
vectors for the case N = 8. MATLAB functions dct.m and idct.m compute the DCT and IDCT
respectively and work similar to fft.m and ifft.m. DCT and its variants are extensively used
to compress data. Compressed audio files like AAC, MP3, compressed image files like JPEG and
compressed video files like MPEG all heavily rely on DCT.
2. Let x be a long discrete sequence. Write a MATLAB function dctcompress.m that takes in x, a
window length L, and number of DCT coefficients to store per window M. For every window
containing L samples, compute the L DCT coefficients, but store only the first M coefficients in
a separate vector y. The output of your function should be the sequence y. Similarly write a
MATLAB function dctdecompress.m that takes in this sequence y, the window length L, and
the number of DCT coefficients per window M. Reconstruct an approximation to the original
sequence x̃ by assuming the remaining L − M DCT coefficients per window to be zero.
3. Use the file lab4.wav to obtain the input sequence x. You can use the MATLAB function wavread.m
to read a .wav file. Compress this sequence using different values of L and M, and subjectively de-
termine the highest compression ratio using which the reconstructed sequence still makes sense.
Compute the sum of squared error between the original and reconstructed sequence.
1
and
C p (k ) = C (k ),k = 0, . . . , N − (2p + 2)
= 0,k = N − (2p + 1), . . . , N − 1
Compute xd f t p [n] and xdct p [n], the inverse DFT and inverse DCT of X p (k ) and C p (k) respectively.
Compare these sequences with the original sequence x [n] by computing the sum of squared error
for all values of p and also plot the original and reconstructed sequences in the same figure. Com-
pare the compression performance of DFT and DCT for the given sequence. You should try to
do a similar comparison for a different sequence, maybe a block from lab4.wav as an assignment
which you need not submit.
Instructions
1. Name your report as ID-no_lab4.pdf. Reports written in LATEX will fetch one extra mark.
2. Collect the files: ID-no_lab4.pdf, dctcompress.m and dctdecompress.m in a single zip file named
ID-no_lab4, and submit by uploading the zip file on courses.daiict.ac.in.
3. Submit only one zip file per group, where a group should not contain more than 3 students.
Clearly mention the group members in the report and code. Please do not change groups.
4. Submissions must be done within 5 days of the lab, i.e., Monday’s batch should submit by
Friday midnight.