Professional Documents
Culture Documents
In the case of rounding, the step size is divided into upper and lower halves. The value in the upper
half are stepped into the next level and the value in the lower half remains in that level.
Example -1:
Quantization and encoding of the Signal: x(t)=sin(2π10t)+ sin(2π50t)+ sin(2π100t) Uniform
Code:
clc; close all; clear all; t=0:.001:.1;
y=sin(2*pi*10*t)+sin(2*pi*50*t)+sin(2*pi*100*t);
subplot(1,4,1), plot(t,y) title ('Analog Signal');
Fs=300; i=1;
for j=1: round((length(t)-1)/((max(t)-min(t))*Fs)):length(t) ts(i)=t(j);
ys(i)=y(j); i=i+1; end C=[6 7 8]; for w=1:3 b=C(w); L=2^b;
del=(max(ys)-min(ys))/(L-1);
for i=1:L l(i)=min(ys)+del*(i-1);
end yq=ys; for i=1:length(l)-1
temp= yq>l(i) & yq<l(i+1) & abs(yq-l(i))<abs(yq-l(i+1));
yq(temp)=l(i);
temp= yq>l(i) & yq<l(i+1) & abs(yq-l(i))>abs(yq-l(i+1));
yq(temp)=l(i+1); end
for p=1:length(t) yr(p)=interp1(ts,yq,t(p)); end
subplot (1,4,w+1), stem(t,yr) title
(['Quantized for Bits: ', num2str(b)]) end
Output:
Encoding: The coding process in an A/D converter assigns a unique binary number to each
quantization level. If L is the number of levels, then L levels can be represented by b bits. where
2b = L or b = log2 L.
Encoding the Quantized Sequence:
clc; close all; clear all; t=0:.0001:.1;
y=sin(2*pi*10*t)+sin(2*pi*50*t)+sin(2*pi*100*t);
subplot(2,2,1), plot(t,y) title ('Analog Signal');
Fs=600; i=1;
for j=1:round((length(t)-1)*10/Fs):length(t) ts(i)=t(j);
ys(i)=y(j); i=i+1; end B=[2 6 9]; for w=1:3 b=B(w);
L=2^b;
del=(max(ys)-min(ys))/(L-1);
for i=1:L
l(i)=min(ys)+del*(i-1);
end yq=ys; for
i=1:length(l)-1
temp= yq>l(i) & yq<l(i+1) & abs(yq-l(i))<abs(yq-l(i+1));
yq(temp)=l(i);
temp= yq>l(i) & yq<l(i+1) & abs(yq-l(i))>abs(yq-l(i+1));
yq(temp)=l(i+1); end
for z=1:length(yq)
ye(z)=round((yq(z)-min(yq))/del); end
if w==1 encoded_3=dec2bin(ye);
elseif w==2 encoded_4=dec2bin(ye);
else encoded_6=dec2bin(ye); end
subplot (2,2,w+1), stairs(ts,ye)
title(['Quantized Bits: ', num2str(B(w))]) end
display(encoded_3) display(encoded_4)
display(encoded_6)
Output:
Conclusion:
In conclusion, converting an analog signal to a digitally coded signal involves a process called
analog-to-digital conversion. This process samples the continuous analog signal at regular
intervals, quantizes the sampled values, and represents them as binary numbers. This enables the
transmission, storage, and processing of the signal using digital systems, providing improved
accuracy and reliability in various applications.