Professional Documents
Culture Documents
AbdurrafayBinKhurram CE41B DC LAB5
AbdurrafayBinKhurram CE41B DC LAB5
Digital Communication
Lab Number 5
SUBMITTED TO:
LE SIR HAMZA SHAMI
SUBMITTED BY:
Abdurrafay Bin Khurram
Reg # 282912
DE- 41 Dept B
Tasks:
Code:
clear; close all; clc;
if (q < 1)
throw(MException('Bit Depth has to be atleast 1'));
end
i = 1;
xlims = [0 149];
ylims = [-1.1 1.1];
disp(['SQNR for signal with Fs=' num2str(1 / fd1) ' Hz is: '
num2str(SQNR) ' dB.']);
subplot(2, 2, i);
plot(n, x1, n, x1q);
3
xlabel('Indexes');
ylabel('Amplitude');
xlim(xlims);
ylim(ylims);
legend('DTCV', 'DTDV');
title('Quantization of Signal');
subplot(2, 2, i + 1);
plot(n, x1e);
xlabel('Indexes');
ylabel('Amplitude');
xlim(xlims);
ylim(ylims);
title('Error in Quantization');
i = i + 2;
end
Output:
4
Code:
clear;
close all;
clc;
fd1 = 1/100;
n = 0:499;
xlims = [0 149];
ylims = [-1.1 1.1];
i = 1;
for bd = 1:9
x1 = sin(2 * pi * fd1 * n);
Px1 = sum(abs(x1) .^ 2) / length(x1);
x1q = roundtowardvec(x1, -1:2 / (2 ^ bd - 1):1, 'round');
x1e = x1 -x1q;
Pe1 = sum(abs(x1e) .^ 2) / length(x1e);
subplot(3, 3, i)
plot(n, x1, n, x1q);
xlabel('Indexes');
ylabel('Amplitude');
xlim(xlims);
ylim(ylims);
legend('DTCV', 'DTDV');
title(['Quantization of Signal with BitDepth=' num2str(bd)]);
i = i + 1;
end
5
Output:
Code:
clear; clc;
[signal, Fs] = audioread('file.mp3');
i = 1;
x1 = signal(100000:150000, 1);
6
xlims = [0 length(x1)];
ylims = [-0.5 0.5];
for bd = 1:9
Px1 = sum(abs(x1) .^ 2) / length(x1);
x1q = roundtowardvec(x1, -1:2 / (2 ^ bd - 1):1, 'round');
x1e = x1 -x1q;
Pe1 = sum(abs(x1e) .^ 2) / length(x1e);
subplot(3, 3, i)
plot(x1);
hold on;
plot(x1q);
xlabel('Indexes');
ylabel('Amplitude');
xlim(xlims);
ylim(ylims);
legend('DTCV', 'DTDV');
title(['Quantization of Signal with BitDepth=' num2str(bd)]);
i = i + 1;
if (bd == 8)
sound(x1q);
end
end
Output: