You are on page 1of 2

PRACTICAL 7

TVISHA PATEL
22BCE361

Aim:
Implementation of Pulse Code Modulation: Sampling, Quantisation and

Digitisation of various types of waveforms

f=7;
a=10;

original_t = linspace(0, 1/f);


original_sig = a* sin(2 *%pi * f * original_t);

sampling_rate = 2*f;
sampling_t = 1/f;

sampled_time = linspace(0, sampling_t, sampling_rate);


sampled_signal = a*sin(2 * %pi * f* sampled_time);

subplot(2, 1, 1);
plot(original_t, original_sig);
title("Original Signal");
xgrid();

subplot(2, 1, 2);
plot(sampled_time, sampled_signal,'o');
title("Sampled Signal");
xgrid();

levels = 8;
bits = 3;

q_range = linspace(-a,a,levels);

q_values = zeros(1, sampling_rate);


for i = 1:sampling_rate
for j =1:levels
if sampled_signal(i) >= q_range(j) && sampled_signal(i) < q_range(j+1)
q_values(i) = j-1;
break;
end
end
end

disp("Quantized Values:");
disp(q_values);

bin_q_values = dec2bin(q_values,bits);
disp("Binary Quantized Values:");
disp(bin_q_values);

You might also like