0% found this document useful (0 votes)
166 views9 pages

Lab 5 DC

The document describes a digital communication lab experiment on quantization with variable precision levels. It involves simulating a composite signal consisting of two sinusoidal signals with different sampling frequencies, quantizing the signal with varying number of significant digits using different quantization methods, computing the quantization error and signal-to-quantization noise ratio (SQNR). The output section describes quantizing a simple 100 Hz sinusoid sampled at different bit depths and plotting the results, as well as quantizing a recorded voice signal to different bit depths and listening to observe the effects on quality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views9 pages

Lab 5 DC

The document describes a digital communication lab experiment on quantization with variable precision levels. It involves simulating a composite signal consisting of two sinusoidal signals with different sampling frequencies, quantizing the signal with varying number of significant digits using different quantization methods, computing the quantization error and signal-to-quantization noise ratio (SQNR). The output section describes quantizing a simple 100 Hz sinusoid sampled at different bit depths and plotting the results, as well as quantizing a recorded voice signal to different bit depths and listening to observe the effects on quality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

DEPARTMENT OF COMPUTER & SOFTWARE

ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI

EC-431 Digital Communication

Lab Number 05

Name Abdullah Khan Warraich


De 41 -CE – B
Reg No 266049
Effects of Quantization with variable
precision levels
Simulate a DTCV sampled composite signal of 𝑓𝑑1=125 samples/sec and
𝑓𝑑2=150 samples/sec with length of the signal be 250 samples. Take the
desired number of significant digits from user as an input. Then choose the
method of Quantization (round-off, floor & ceil) and apply to the signal
generated above. Compute the quantization error signals and SQNR.

Code:
% Parameters fd1 = 125; % Sampling frequency of the first signal fd2 = 150; % Sampling
frequency of the second signal N = 250; % Length of the signal digits = input('Enter number of
significant digits: '); % Number of significant digits method = input('Enter quantization method
(round-off/floor/ceil): ', 's'); % Quantization method

% Generate the two component


signals

t = (0:N-1); x1 =
sin(2*pi*fd1*t/fd1)
; x2 =
sin(2*pi*fd2*t/fd2)
;

% Add the two signals to get the composite


signal x = x1 + x2;

% Quantize the signal


switch method

case 'round-off'

xq =
round(x*10^digits)/10^digits; case
'floor'

xq = floor(x*10^digits)/10^digits;
case 'ceil'

xq = ceil(x*10^digits)/10^digits;
otherwise
error('Invalid quantization
method!'); end

% Compute the quantization error


signal e = xq - x;

% Compute the SQNR

SQNR = 10*log10(var(x)/var(e));

% Plot the original and quantized


signals

figure;
subplot(2,1,1);
plot(t, x);
title('Original
Signal');
xlabel('Time
(samples)');
ylabel('Amplitude')
; subplot(2,1,2);
plot(t, xq);
title('Quantized
Signal');
xlabel('Time
(samples)');

ylabel('Amplitude');

% Plot the quantization error signal

figure; plot(t, e);


title('Quantization Error
Signal'); xlabel('Time
(samples)');

ylabel('Amplitude');

% Display the SQNR

disp(['SQNR = ', num2str(SQNR), '


dB']);
Output
Simple sinusoid quantized to various bits per
sample
Generate a 100 Hz sinusoid sampled at 10000 samples/sec and quantized
at 1_bit/sample. Now increase the bit depth for various numbers of bits
per sample (2, 3, 4, 5, 6, 7, 8) and attach plots.

Code:

f = 100;

fs = 10000;

t = (0:fs-1) / fs;

% Define number of bits per sample


n_bits = [1, 2, 3, 4, 5, 6, 7, 8];

% Initialize figure
figure;
for i = 1:length(n_bits)

x = sin(2 * pi * f * t);

n = n_bits(i);

x_quantized = round((2^n - 1) * (x + 1) / 2) / (2^n - 1) * 2 - 1;

% Plot quantized signal


subplot(length(n_bits), 1, i);
plot(t, x_quantized);
ylim([-1.1 1.1]);

title(sprintf('%d-bit quantized signal',


n)); xlabel('Time (s)'); end

Output:
Audio signal quantization to various bits per
sample
Use your recorded voice in last session and quantize it at 1 bit /sample.
Change bit depth to 2,3,4 and then listen and take notes of your
observations. Decide no. of bits for audio until quality stops improving.
Code:
% Load audio file

[x, Fs] =
audioread('PinkPanther30.wav');

% Set number of bits for quantization


num_bits = [1, 2, 3, 4];

% Plot original audio signal


figure;

plot(x); title('Original
Audio Signal');
xlabel('Sample
Number');

ylabel('Amplitude');

% Play back original audio


sound(x, Fs);

% Pause to allow audio playback to complete


pause(length(x)/Fs);

% Simulate quantization at different bit


depths for i = 1:length(num_bits) %
Compute quantization step size

q = 2^(num_bits(i)-1);

% Quantize audio signal

x_quantized = round(x*q)/q;
% Plot quantized audio signal

figure;
plot(x_quantized);

title(sprintf('Quantized Audio Signal (%d Bits)', num_bits(i)));


xlabel('Sample Number');

ylabel('Amplitude');

% Play back quantized audio

sound(x_quantized, Fs);

% Pause to allow audio playback to


complete pause(length(x_quantized)/Fs);
end

Output:

You might also like