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

CSP 3

Uploaded by

sriya bonkuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

CSP 3

Uploaded by

sriya bonkuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Name: B.

Sriya
Roll no:EC22B1101
Date: 29-01-2025

Experiment 3: Pulse Coded Modulation

Aim:
The goal of this experiment is to understand how Pulse Code Modulation (PCM)
works by converting a sinusoidal signal into a digital format at different quantization
levels (N=1,2,3,4N = 1, 2, 3, 4). We’ll explore how increasing the number of bits
improves the accuracy of the digital representation.
Specifically, we will:
1. Convert the signal into discrete levels (quantization) and encode it in binary
(PCM).
2. Reconstruct the signal through PCM decoding.
3. Analyze the effects of quantization, including the error introduced and how it
changes with N.
4. Compare the Signal-to-Quantization-Noise Ratio (SQNR) between simulated
and theoretical values.
5. Visualize the original, quantized, encoded, and decoded signals, along with
their frequency spectra.
6. Summarize the findings in a table to see how increasing bit depth improves
signal quality.

Theory:
Pulse Code Modulation (PCM) is a technique used to digitally represent an analog
signal by performing sampling, quantization, and encoding. The accuracy of the
digitized signal depends on the number of bits (NN) used for quantization.
1. Sampling
An analog signal is sampled at regular intervals to obtain discrete-time values.
According to the Nyquist-Shannon theorem, the sampling rate (fs) must be at least
twice the highest frequency component of the signal to avoid aliasing.
2. Quantization
Each sampled value is mapped to the nearest discrete level within a fixed range. The
total number of quantization levels (L) is determined by:
L= 2^N
where N is the number of bits used for encoding. The resolution of quantization is
defined by the step size (δ\delta):
δ=xmax−xmin/L−1
where xmax and xmin represent the maximum and minimum amplitudes of the
signal.
Since the quantized values are approximations of the original samples, quantization
noise is introduced. The maximum quantization error is given by:
Max Quantization Error=δ/2
3. Encoding
Each quantized value is assigned a unique binary code of N bits, forming a digital
sequence that represents the signal. This process is known as PCM encoding.
4. Decoding
The encoded binary values are converted back into discrete amplitude levels to
reconstruct the signal. Due to quantization, the decoded signal is an approximation of
the original input.
5. Signal-to-Quantization-Noise Ratio (SQNR)
The Signal-to-Quantization-Noise Ratio (SQNR) is a key parameter for evaluating the
quality of the quantized signal. It is expressed as:
SQNR (theoretical)=6.02N+1.76(in dB)
where N represents the number of bits used for quantization. A higher N results in
improved SQNR, reducing quantization distortion.
The simulated SQNR can be computed as:
SQNR (simulated)=10log10(Signal Power/Quantization Noise Power)
This theoretical framework provides insight into the role of PCM in digitizing signals
while balancing precision and efficiency in communication and signal processing
applications.
Codes:
1. fs = 1000;
t = 0:1/fs:1;
f = 5;
x = sin(2 * pi * f * t);
N_values = [1, 2, 3, 4];
figure;
for i = 1:length(N_values)
N = N_values(i);
L = 2^N;
x_max = max(abs(x));
q_step = 2 * x_max / L;
x_quantized = round(x / q_step) * q_step;
% PCM Encoding (Binary representation)
x_indices = round((x + x_max) / q_step);
x_bin = dec2bin(x_indices, N);
% Plot original and quantized signals
subplot(2, 2, i);
plot(t, x, 'b', 'LineWidth', 1.5);
hold on;
stairs(t, x_quantized, 'r', 'LineWidth', 1);
hold off;
title(['PCM Quantization for N = ', num2str(N)]);
xlabel('Time (s)');
ylabel('Amplitude');
legend('Original Signal', 'Quantized Signal');
grid on;
end
2.
fs = 1000;
t = 0:1/fs:1;
f = 5;
x = sin(2*pi*f*t);
N = 3;
L = 2^N;
x_max = max(abs(x));
q_step = (2 * x_max) / L;
% Quantization Process
x_quantized = round(x / q_step) * q_step;
% PCM Encoding
x_indices = round((x + x_max) / q_step);
x_bin = dec2bin(x_indices, N);
% PCM Decoding (Reconstruction)
x_decoded = (x_indices * q_step) - x_max;
% Quantization Error
quant_error = x - x_quantized;
% Plot the Signals
figure;
subplot(3,2,1);
plot(t, x, 'b', 'LineWidth', 1.5);
title('Message Signal (Original)');
xlabel('Time (s)'); ylabel('Amplitude'); grid on;
subplot(3,2,2);
stairs(t, x_quantized, 'r', 'LineWidth', 1.2);
title('Quantized Signal');
xlabel('Time (s)'); ylabel('Amplitude'); grid on;
subplot(3,2,3);
stairs(t, quant_error, 'k', 'LineWidth', 1.2);
title('Quantization Error');
xlabel('Time (s)'); ylabel('Error'); grid on;
subplot(3,2,4);
stairs(t, x_decoded, 'g', 'LineWidth', 1.2);
title('Decoded Signal');
xlabel('Time (s)'); ylabel('Amplitude'); grid on;
% Convert binary string to numeric array
x_bin_num = double(x_bin) - '0';
% Resample time vector to match binary length
t_bin = linspace(0, 1, length(x_indices));
% Plot PCM encoded signal (Binary Waveform)
subplot(3,2,5);
hold on;
for i = 1:N
stairs(t_bin, x_bin_num(:,i) + (N-i), 'LineWidth', 1.2); % Plot each bit stream
end
title('PCM Encoded Signal (Binary Representation)');
xlabel('Time (s)'); ylabel('Binary Levels'); grid on;
% Spectra Calculation
X_f = abs(fft(x));
Xq_f = abs(fft(x_quantized));
Xd_f = abs(fft(x_decoded));
f_axis = linspace(0, fs, length(t));
% Plot the Spectra
figure;
subplot(3,1,1);
plot(f_axis, X_f, 'b');
title('Spectrum of Message Signal');
xlabel('Frequency (Hz)'); ylabel('Magnitude'); grid on;
subplot(3,1,2);
plot(f_axis, Xq_f, 'r');
title('Spectrum of Quantized Signal');
xlabel('Frequency (Hz)'); ylabel('Magnitude'); grid on;
subplot(3,1,3);
plot(f_axis, Xd_f, 'g');
title('Spectrum of Decoded Signal');
xlabel('Frequency (Hz)'); ylabel('Magnitude'); grid on;

3.
fs=1000;
t=0:1/fs:1;
f=5;
x=sin(2*pi*f*t);
N_values = [2, 3, 4, 5, 6];
for i=1:length(N_values)
N=N_values(i);
L=2^N;
x_max=max(x);
x_min=min(x);
delta=(x_max-x_min)/(L-1);
x_quantized = round((x - x_min) / delta) * delta + x_min;
max_quant_error=delta/2;
signal_power = mean(x.^2);
quantization_noise = mean((x - x_quantized).^2);
sqnr_db = 10 * log10(signal_power / quantization_noise);
fprintf('\nFor N = %d bits:\n', N);
fprintf('Number of quantization levels (L) = %d\n', L);
fprintf('Step size (delta) = %f\n', delta);
fprintf('Maximum quantization error = %f\n', max_quant_error);
fprintf('SQNR = %f dB\n', sqnr_db);
end
4.
fs = 1000;
t = 0:1/fs:1;
f = 5;
x = sin(2*pi*f*t);
N_values = 2:6;
simulated_SQNR = zeros(size(N_values));
theoretical_SQNR = 6.02 * N_values + 1.76;
for i = 1:length(N_values)
N = N_values(i);
L = 2^N; % Number of quantization levels
x_max = max(x);
x_min = min(x);
delta = (x_max - x_min) / (L - 1);
x_quantized = round((x - x_min) / delta) * delta + x_min;
max_quant_error = delta / 2;
signal_power = mean(x.^2);
quantization_noise = mean((x - x_quantized).^2);
sqnr_db = 10 * log10(signal_power / quantization_noise);
simulated_SQNR(i) = sqnr_db;
% Display results in command window
fprintf('\nFor N = %d bits:\n', N);
fprintf('Number of quantization levels (L) = %d\n', L);
fprintf('Step size (delta) = %f\n', delta);
fprintf('Maximum quantization error = %f\n', max_quant_error);
fprintf('Simulated SQNR = %f dB\n', sqnr_db);
fprintf('Theoretical SQNR = %f dB\n', theoretical_SQNR(i));
end
% Plotting
figure;
plot(N_values, simulated_SQNR, 'bo-', 'LineWidth', 2, 'MarkerSize', 8);
hold on;
plot(N_values, theoretical_SQNR, 'r--s', 'LineWidth', 2, 'MarkerSize', 8);
grid on;
xlabel('Number of Bits (N)');
ylabel('SQNR (dB)');
title('Simulated vs. Theoretical SQNR');
legend('Simulated SQNR', 'Theoretical SQNR', 'Location', 'best');

Bits(N) Quantization Stepsize Max Simulated Theoretical


Levels(L=2^N) Quantization SQNR(db) SQNR(db)(6.02N+1.76)
error
2 4 Computed Computed Simulated 6.02(2)+1.76=13.80
Value
3 8 Computed Computed Simulated 6.02(3)+1.76=19.82
Value
4 16 Computed Computed Simulated 6.02(4)+1.76=25.84
Value
5 32 Computed Computed Simulated 6.02(5)+1.76=31.86
Value
6 64 Computed Computed Simulated 6.02(6)+1.76=37.88
Value
Waveforms:
1.

2.
3.
4.

Inference:
1. Increasing N and its effect on quantization error and noise:
Higher N reduces quantization error and noise, improving signal accuracy.
2. Signal reconstruction with increasing N:
The reconstructed signal becomes closer to the original as N increases, with
reduced distortion.
3. SQNR change with increasing N:
SQNR improves as N increases, indicating better signal quality.
4. Comparison of simulated and theoretical SQNR values:
Simulated SQNR values match theoretical predictions, confirming the model’s
accuracy.
5. Effect of increasing N on quantization noise:
Higher N reduces quantization noise, resulting in a clearer signal.
6. PCM performance with increasing N:
PCM performs better with higher N, providing more accurate and less noisy
signal representation.
Result:
1. Pulse Code Modulation (PCM) was successfully applied to a sinusoidal signal at
different quantization levels (N=1,2,3,4N = 1, 2, 3, 4N=1,2,3,4).
2.As the number of bits (NNN) increased, both quantization error and noise
decreased, leading to higher SQNR values.
3.Simulated SQNR values closely matched the theoretical values, validating the
theoretical model.
4.Higher bit-depths resulted in better signal reconstruction, with reduced distortion
and noise, as seen in both the time-domain signal plots and frequency-domain
spectra.
The experiment confirmed that PCM effectively captures the characteristics of the
original signal while reducing distortion as bit-depth increases.

You might also like