Digital Signal Processing Laboratory
Project submitted for the partial fulfillment
of the requirements for the degree of
Bachelor of Technology
in
Electronics and Communication Engineering
by
Student Name: Ritik Mittal - Roll No.: 22UEC111
Course Coordinator: Dr. Harish Chandra Kumawat
Department of Electronics and Communication Engineering
The LNM Institute of Information Technology, Jaipur
10 November 2024
Copyright © The LNMIIT 2024
All Rights Reserved
Contents
Chapter Page
1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 AIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Software used: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.1 My Compression function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.2 My De-Compression function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.3 Use custom DCT and IDCT function to compress and reconstruct any audio file. . . . . . . . . 2
1.3.4 Divide the whole audio file in nonoverlapping blocks of size 1 × 256. Use above function to
compress the whole audio file with coefficents saved according to the thresold values. . . . . . . 2
1.3.5 Repeat the above steps for given different thresold cases and make a table for mse and compres-
sion ratio for given thresold values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.6 Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
iii
Chapter 1
1.1 AIM
1. Discrete Cosine Transform and it’s energy compaction property.
2. Simulink based Audio compression.
1.2 Software used:
MATLAB
1.3 Observation
1.3.1 My Compression function
1 function D = myCompresion(b)
2 m = length(b);
3 beta = [sqrt(1/m), sqrt(2/m) * ones(1, m - 1)];
4 out = zeros(m, 1);
5 for k = 1 : m
6
7 for i = 1 : m
8 out(k,1) = out(k,1) + b(i) * cos(pi*(2*(i - 1) + 1)*(k - 1)/ (2 * m));
9 end
10 out(k,1) = out(k,1) * beta(k) ;
11 end
12 D = out;
1.3.2 My De-Compression function
2 function D = myDeCompresion(b)
3 m = length(b);
4 beta = [sqrt(1/m), sqrt(2/m) * ones(1, m - 1)];
5 out = zeros(m, 1);
6
7 for i = 1 : m
8 for k = 1 : m
9 out(i,1) = out(i,1) + beta(k) * b(k) * cos(pi * (2 * (i - 1) + 1) * (k - 1)
/ (2 * m));
10 end
1
11 end
12
13 D = out;
14 end
1.3.3 Use custom DCT and IDCT function to compress and reconstruct any audio file.
1 clc;
2 clear all;
3 close all;
4
5 [x, fs] = audioread(’handel.wav’, [1, 10000]);
6 z = myCompresion(x);
7 a = myDeCompresion(z);
8 soundsc(a, fs);
1.3.4 Divide the whole audio file in nonoverlapping blocks of size 1 × 256. Use above function to
compress the whole audio file with coefficents saved according to the thresold values.
1 clc;
2 clear all;
3 close all;
4
5 [x, fs] = audioread(’handel.wav’);
6 n = length(x);
7 x_rec = zeros(n, 1);
8 block = n / 256;
9
10 th_up = [0.09, 0.05, 0.01];
11 th_down = [-0.09, -0.05, -0.01];
12
13 for t = 1:3
14 for b = 1:285
15 temp = zeros(1, 256);
16
17 % Extract 256 samples
18 for j = 1:256
19 temp(j) = x((b - 1) * 256 + j);
20 end
21
22 % Apply compression
23 z = myCompresion(temp);
24
25 % Thresholding operation
26 for j = 1:256
27 if (z(j) >= th_down(t) && z(j) <= th_up(t))
28 z(j) = 0;
29 end
30 end
31
32 % Apply decompression
33 z_inv = myDeCompresion(z);
2
34
35 % Reconstruct the signal
36 for j = 1:256
37 x_rec((b - 1) * 256 + j, 1) = z_inv(j);
38 end
39 end
40 end
41
42 % Play reconstructed sound
43 soundsc(x_rec, fs);
1.3.5 Repeat the above steps for given different thresold cases and make a table for mse and compres-
sion ratio for given thresold values
1 clc;
2 clear all;
3 close all;
4
5 [x, fs] = audioread(’handel.wav’);
6
7 n = length(x);
8 x_rec = zeros(n, 1);
9 block = n / 256;
10
11 th_up = [0.09, 0.05, 0.01];
12 th_down = [-0.09, -0.05, -0.01];
13
14 mse = zeros(1, 3);
15 ratio = zeros(1, 3);
16
17 for t = 1:3
18 for b = 1:285
19 temp = zeros(1, 256);
20
21 % Extract 256 samples
22 for j = 1:256
23 temp(j) = x((b - 1) * 256 + j);
24 end
25
26 % Apply compression
27 z = myCompresion(temp);
28
29 % Thresholding operation
30 for j = 1:256
31 if (z(j) >= th_down(t) && z(j) <= th_up(t))
32 z(j) = 0;
33 end
34 end
35
36 % Apply decompression
37 z_inv = myDeCompresion(z);
38
39 % Reconstruct the signal
3
40 for j = 1:256
41 x_rec((b - 1) * 256 + j, 1) = z_inv(j);
42 end
43 end
44
45 % Calculate Mean Squared Error (MSE)
46 mse(t) = immse(x_rec, x);
47
48 % Calculate Compression Ratio (number of non-zero elements)
49 ratio(t) = nnz(z) / length(z); % Normalized by the length of z
50 end
51
52 % Plot MSE vs Compression Ratio
53 figure;
54 stem(ratio, mse, ’filled’);
55 xlabel(’Compression Ratio’);
56 ylabel(’Mean Squared Error (MSE)’);
57 title(’MSE vs Compression Ratio’);
58 grid on;
Figure 1.1
4
1.3.6 Simulink
Figure 1.2