0% found this document useful (0 votes)
32 views12 pages

To Convert The Analog Signal Into Digital Pulses

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 12

To convert the analog signal into digital pulses, we need to follow the process of sampling, quantization,

and encoding. Let's solve for each of the parameters given:

1. Solve for Ta: Ta = 1 / Freq Ta = 1 / 2000 Ta = 0.0005 seconds

2. Sampling interval, Ts: Ts = Ta / n Ts = 0.0005 / 2 Ts = 0.00025 seconds

3. Solve for fs: fs = 1 / Ts fs = 1 / 0.00025 fs = 4000 Hz

4. Solve for the sampled value, V, at each sampling instant: We have 11 sampling instants, so the
sampled values will be: V1 = -1 V2 = -0.5 V3 = 0 V4 = 0.5 V5 = 1 V6 = 0.5 V7 = 0 V8 = -0.5 V9 = -1
V10 = -0.5 V11 = 0

5. Solve for step-size: The range of the analog signal is -1 to +1 V, and we are using 2 bits for
quantization. Therefore, the step-size is given by: Step-size = (max range of analog signal) /
(number of quantization levels - 1) Step-size = 2 / (2^2 - 1) Step-size = 0.67

6. Solve for the Index and quantized value: The quantized value is obtained by rounding the
sampled value to the nearest quantization level, and the index is obtained by mapping the
quantized value to its binary representation.

Index and Quantized Value table:

Sampled Value Quantized Value Index (Binary)

-1 -1 00

-0.5 -1 00

0 0 01

0.5 1 10

1 1 10

0.5 1 10

0 0 01

-0.5 -1 00

-1 -1 00

-0.5 -1 00

0 0 01

7. Show on the graph the quantized discrete pulses: To graph the quantized discrete pulses, we
can use a step function with vertical steps at each sampling instant. The height of each step
represents the quantized value obtained from the table above.
% Define parameters

fs = 44000; % Sampling frequency (Hz)

T = 1/fs; % Sampling interval (s)

t = 0:T:(1/1000); % Time vector (s)

f = 2000; % Analog signal frequency (Hz)

A = 1; % Analog signal amplitude (V)

n = 2; % Number of bits for quantization

q = 2*A/(2^n-1); % Quantization step size (V)

levels = -A:q:A; % Quantization levels (V)

% Generate analog signal

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

% Sample analog signal

Ts = 1/f;

t_sampled = 0:Ts:(1/1000);

x_sampled = A*sin(2*pi*f*t_sampled);

% Quantize sampled signal

x_quantized = quantize(x_sampled, levels, q);

% Encode quantized signal

x_encoded = encode(x_quantized, levels);

% Plot signals

subplot(4,1,1)

plot(t,x,'b')

title('Analog Signal')

xlabel('Time (s)')
ylabel('Amplitude (V)')

subplot(4,1,2)

stem(t_sampled,x_sampled,'r','Marker','none')

title('Sampled Signal')

xlabel('Time (s)')

ylabel('Amplitude (V)')

subplot(4,1,3)

stairs(t_sampled,x_quantized,'g')

title('Quantized Signal')

xlabel('Time (s)')

ylabel('Amplitude (V)')

subplot(4,1,4)

stairs(t_sampled,x_encoded,'m')

title('Encoded Signal')

xlabel('Time (s)')

ylabel('Binary Code')

% Helper functions

function x_quantized = quantize(x, levels, q)

x_quantized = round(x/q)*q;

x_quantized(x_quantized>max(levels)) = max(levels);

x_quantized(x_quantized<min(levels)) = min(levels);

end

function x_encoded = encode(x_quantized, levels)

x_encoded = zeros(size(x_quantized));
for i = 1:length(levels)

x_encoded(x_quantized == levels(i)) = i-1;

end

end

You might also like