CMS Lab-4 Report
Anand Bachker – 201000005
Revant Emani – 201000042
Yathin Prakash Kethepalli – 201000060
CSE
Question 1:
Code:
clc;
close all;
L = 6;
n = 400;
% No. of samples = 10 * Nyquist rate = 10 * (2 * maximum frequency) = 10
*(2 * 20)
% Sampling Operation
x=0:2*pi/n:0.5*pi; % n number of samples have to be selected
Am = 1;
s=Am*sin(20 * x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);
title('Sampled Signal at 10 times the Nyquist Rate');
ylabel('Amplitude--->'); xlabel('Time--->');
% Quantization Process
vmax=Am;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax;
code=vmin-(del/2):del:vmax+(del/2);
[ind,q]=quantiz(s,part,code);
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q); % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Output:
Question 2:
Code:
clc;
close all;
L = 6;
n = 400;
% Sampling Operation
x=0:2*pi/n:0.5*pi; % n1 number of samples have to be selected
Am = 1;
s=Am*sin(20 * x);
subplot(3,1,1);
plot(s);grid on;
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Quantization Process
vmax=Am;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of
del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized values
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,2);
stem(q);
% Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
y = lowpass(q,16000,1/400);
subplot(3,1,3);
plot(y);
% Display the Quantize values
title('Reconstructed Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Output:
Question 3:
Code:
clc;
close all;
L=input('Enter no. of quantization levels : ');
n=input('Enter number of samples in a period : ');
% Sampling Operation
x=0:1/n:0.2; % n1 number of samples have to be selected
Am=input('Enter the amplitude of the Sinusoidal signal:');
fm=input('Enter the frequency of the Sinusoidal signal:');
s=Am*sin(2*pi*fm*x);
subplot(3,1,1);
plot(s);grid on;
xlim([0 83])
ylim([-1 1])
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);
grid on;
xlim([0 83])
ylim([-1 1])
title('Sampled Signal');
ylabel('Amplitude--->'); xlabel('Time--->');
% Quantization Process
vmax=Am;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with
difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contain Quantized values
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);
grid on; % Display the Quantize values
xlim([0 83])
ylim([-1 1])
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Output:
out =
81×7 char array
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'
'0011001'
'1001100'
'1111111'
'1111111'
'1111111'
'1111111'
'1111111'
'1001100'
'0011001'
'0011001'