Sunteți pe pagina 1din 4

HW2

September 29, 2017


Andrew Emrazian - u0349111
CS 4600 – Computer Graphics

Part 1 – Audio Coding

This audio coding was an exercise of implementing the Discrete Cosine Transform (DCT) on a stream of audio signals. I
calculated an orthonormal basis in 𝑅𝑅 8 . This, Q, was constructed using the given equation
𝜋𝜋
𝑞𝑞𝑘𝑘𝑖𝑖 = 𝑠𝑠𝑘𝑘 cos �� � (𝑘𝑘 − 1) (2𝑖𝑖 − 1)�
16
In order to verify that I computed 𝑄𝑄 correctly, I checked that 𝑄𝑄 𝑇𝑇 𝑄𝑄 = 𝐼𝐼. I used matlab to verify this.

Q 1 2 3 4 5 6 7 8
Matrix
1 0.353553 0.353553 0.353553 0.353553 0.353553 0.353553 0.353553 0.353553
2 0.490393 0.415735 0.277785 0.097545 -0.09755 -0.27779 -0.41574 -0.49039
3 0.46194 0.191342 -0.19134 -0.46194 -0.46194 -0.19134 0.191342 0.46194
4 0.415735 -0.09755 -0.49039 -0.27779 0.277785 0.490393 0.097545 -0.41574
5 0.353553 -0.35355 -0.35355 0.353554 0.353553 -0.35355 -0.35355 0.353553
6 0.277785 -0.49039 0.097545 0.415735 -0.41574 -0.09755 0.490393 -0.27779
7 0.191342 -0.46194 0.46194 -0.19134 -0.19134 0.46194 -0.46194 0.191342
8 0.097545 -0.27779 0.415735 -0.49039 0.490393 -0.41574 0.277786 -0.09755

>> q1 >> q1’ * q1

q1 = ans =

0.3536 0.3536 0.3536 0.3536 0.3536 0.3536 0.3536 0.3536 1.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000
0.4904 0.4157 0.2778 0.0975 -0.0975 -0.2778 -0.4157 -0.4904 -0.0000 1.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000
0.4619 0.1913 -0.1913 -0.4619 -0.4619 -0.1913 0.1913 0.4619 -0.0000 0.0000 1.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000
0.4157 -0.0975 -0.4904 -0.2778 0.2778 0.4904 0.0975 -0.4157 0.0000 0.0000 0.0000 1.0000 -0.0000 0.0000 -0.0000 -0.0000
0.3536 -0.3536 -0.3536 0.3536 0.3536 -0.3536 -0.3536 0.3536 -0.0000 0.0000 -0.0000 -0.0000 1.0000 0.0000 -0.0000 -0.0000
0.2778 -0.4904 0.0975 0.4157 -0.4157 -0.0975 0.4904 -0.2778 0.0000 -0.0000 -0.0000 0.0000 0.0000 1.0000 0.0000 0.0000
0.1913 -0.4619 0.4619 -0.1913 -0.1913 0.4619 -0.4619 0.1913 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 1.0000 -0.0000
0.0975 -0.2778 0.4157 -0.4904 0.4904 -0.4157 0.2778 -0.0975 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 1.0000

I then implemented the DCT and InversDCT functions that use the Q basis to get the added sum of each signal
contributions to the whole in which InverseDCT find the original signal. However, I removed most of the calculated
signals, the lowest 5 of the 8 frequencies. The results, while not great in quality, were surprisingly impressive.

1 void DCT(float* x, const float* y, const float* q, int size);

1 void InverseDCT(float* y, const float* x, const float* q, int size);

1
Lossless Lossy (coefficients 3-4 discarded)
Train

Handel

Gong

2
Part 2 – Image Coding

With coding the Discrete Cosine Transform (DCT) with images, I instead used an equation to directly compute the DCT
rather than using a pre-computed basis

7 7
𝜋𝜋 𝜋𝜋
𝐹𝐹(𝑢𝑢, 𝑣𝑣) = 𝐶𝐶𝑢𝑢 𝐶𝐶𝑣𝑣 � � 𝑓𝑓(𝑥𝑥, 𝑦𝑦) cos �� � (2𝑥𝑥 + 1)𝑢𝑢� cos �� � (2𝑦𝑦 + 1)𝑣𝑣�
16 16
𝑥𝑥=0 𝑦𝑦=0
1
⎧ for 𝑢𝑢 = 0
𝐶𝐶𝑢𝑢 = 2√2
⎨ 1
⎩ 2 else

The main challenge with this was getting the correct indexing of the image arrays. In an effort to simplify the rest of the
process, I created a temporary 8 x 8 array for the current sub-block of the image that I was processing. This allows for
the block data to be contiguous when calculating the DCT and Inverse DCT. I created two helper functions to make it
somewhat easier on the eyes. Intermediate matrix C contains the coefficients that are used to reconstruct the block
after DCT.

1 void DCTBlock(const float* A, float* C);

1 void InverseDCTBlock(const float* C, float* B);

I discarded most of the coefficients in the example images below. In particular, indices where i + j > 3 were discarded.
With 5/8 of the coefficients containing signal information about the lower frequencies missing. Images with decent
quality were reconstructed. The image results below make sense. The detail is lost on the camera after lossy
compression because the coeffect contribution would greater in one of the higher indexed basis blocks (one of the lower
right matrices which correspond to higher indices).

3
Lossless Lossy (i + j > 3)
Camerman

Mandi

Moon

S-ar putea să vă placă și