Lab 2
Lab 2
Submitted by
- Header/Footer Yes No
- Spelling Yes No
Total Score
Date:
Signature
List of Figures
Figure 1. Console output of Problem 1 9
Experimental Results
Problem 1:
Ts = 0.01;
n_levels = 8;
max_val = 8;
t = linspace(0, 1, 500);
n = 0:100;
x_original = 8*cos(4*pi*t);
x_sampled = 8*cos(4*pi*n/100);
figure;
subplot(2,1,1);
plot(t, x_original); hold on;
stem(n*Ts, x_sampled, 'r');
title('Original and Sampled Signals');
subplot(2,1,2);
plot(t, x_original); hold on;
stem(n*Ts, x_quantized, 'g');
for i = 1:length(quant_levels)
line([0 1], [quant_levels(i) quant_levels(i)], 'LineStyle', '--', 'Color', 'k');
end
title('Original and Quantized Signals');
Result
figure;
subplot(2, 1, 1);
plot(t, x_original, 'b-', 'LineWidth', 1.5); hold on;
stem(n*Ts, x_sampled, 'r.', 'MarkerSize', 10);
stem(n*Ts, x_quantized, 'go', 'MarkerSize', 6);
title('Original, Sampled, and Quantized Signals');
legend('Original x(t)', 'Sampled x[n]', 'Quantized x_q[n]');
subplot(2, 1, 2);
stem(n*Ts, quant_error, 'k.', 'MarkerSize', 10);
title('Quantization Error: \epsilon[n] = x[n] - x_q[n]');
for i = 1:length(x)
if x(i) < -max_val
x(i) = -max_val;
elseif x(i) > max_val - step
x(i) = max_val - step;
end
[~, idx] = min(abs(x(i) - levels));
x_q(i) = levels(idx);
end
end
switch func_type
case 1
A = input('Enter amplitude A: ');
w = input('Enter angular frequency w: ');
func_handle = @(t) A*sin(w*t);
case 2
A = input('Enter amplitude A: ');
w = input('Enter angular frequency w: ');
func_handle = @(t) A*cos(w*t);
case 3
num_terms = input('How many terms to add? ');
amplitudes = zeros(1, num_terms);
frequencies = zeros(1, num_terms);
term_types = zeros(1, num_terms);
for i = 1:num_terms
term_types(i) = input('Type (1-sine, 2-cosine): ') - 1;
amplitudes(i) = input('Enter amplitude A: ');
frequencies(i) = input('Enter angular frequency w: ');
end
func_handle = @(t) evaluate_sum(t, amplitudes, frequencies, term_types);
end
figure;
plot(t_values, x_values, 'b-', 'LineWidth', 1.5); hold on;
stem(t_values, y_values, 'r.');
title(['Quantized Signal with R = ', num2str(R), ' V, B = ', num2str(B), ' bits']);
legend('Input Signal', 'Quantized Signal');
step_size = R / (2^B);
fprintf('Step size: %.6f Volts\n', step_size);
end
function y = quantized_example(x, R, B)
step = R / (2^B);
levels = (-R/2):step:(R/2-step);
y = zeros(size(x));
for i = 1:length(x)
The main challenges were signal range alignment and custom binary code mapping. Ensuring
the 8V cosine signal properly mapped to 8 quantization levels required careful step size
calculation. The custom binary coding scheme with non-sequential codes needed a direct lookup
table approach.
Key Points
The lab confirmed that the 6.02 dB per bit relationship for SQNR is fundamental to quantization
system design. Quantization error behaves as approximately white noise for properly designed
systems, enabling predictable performance analysis. The choice of binary coding scheme affects
error resilience, with Gray coding providing superior single-bit error protection compared to
natural binary coding.
These concepts are essential for understanding ADC specifications and designing digital signal
processing systems. The relationship between resolution, dynamic range, and power
consumption guides practical ADC selection for applications ranging from audio processing to
precision measurement systems.
THE END