3.1 Title: Analysis of PCM and DPCM Systems and Interpretation of Modulated and Demodulated Waveforms
3.2 Aim of the experiment:
To analyze the operation of Pulse Code Modulation (PCM) and Differential Pulse Code Modulation (DPCM) systems, interpret their modulated and demodulated waveforms, and investigate the magnitude spectrum of PCM signals for sampling frequencies of 4 kHz and 8 kHz
3.3 Theoretical background for the experiment:
Pulse Code Modulation (PCM): PCM is a digital modulation technique in which the analog signal is sampled, quantized, and encoded into a digital bit stream. The process involves:
Sampling: Converting a continuous-time signal into a discrete-time signal.
Quantization: Approximating sampled values to the nearest value within a finite set.
Encoding: Representing quantized values using binary codes.
Differential Pulse Code Modulation (DPCM): DPCM is an extension of PCM where only the difference between consecutive samples is quantized and encoded, reducing redundancy and improving bandwidth efficiency.
Key Equations:
Sampling Frequency: Where is the sampling frequency and is the maximum frequency of the analog signal.
Quantization Error: Where is the original sample value and is the quantized value.
3.4 Design:
Generate an analog sinusoidal signal as the input.
Implement PCM by sampling, quantizing, and encoding the signal.
Implement DPCM by encoding the difference between consecutive samples.
Perform demodulation for both PCM and DPCM systems to reconstruct the original signal.
3.5 Step-by-step procedure to carry out the experiment:
Define an analog input signal (e.g., a sine wave of 1 kHz frequency).
Sample the input signal at 4 kHz and 8 kHz.
Perform uniform quantization to encode the sampled values into PCM.
Calculate differences between consecutive samples for DPCM encoding.
Decode PCM and DPCM signals to reconstruct the original signal.
Compute the Fourier Transform of the PCM signal to obtain its magnitude spectrum.
Compare the original signal with the demodulated signals for accuracy.
3.6 Code:
Pulse Code Modulation
% Parameters
Fs = 1000; % Sampling frequency (Hz)
t = 0:1/Fs:1-1/Fs; % Time vector (1 second)
f = 5; % Signal frequency (Hz)
A = 1; % Signal amplitude
% Generate a sinusoidal signal
signal = A * sin(2 * pi * f * t);
% Plot the original signal
figure;
subplot(3, 1, 1);
plot(t, signal, 'b');
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% PCM Process
n_bits = 3; % Number of quantization levels (3 bits -> 2^3 = 8 levels)
% Normalize the signal to the range [0, 1]
signal_norm = (signal - min(signal)) / (max(signal) - min(signal));
% Quantize the signal
quant_levels = 2^n_bits;
quantized_signal = round(signal_norm * (quant_levels - 1));
% Plot the quantized signal
subplot(3, 1, 2);
stairs(t, quantized_signal, 'g');
title('Quantized Signal');
xlabel('Time (s)');
ylabel('Quantized Level');
grid on;
% Convert to binary (PCM encoding)
pcm_encoded = dec2bin(quantized_signal, n_bits); % Convert to binary matrix
% Display a sample of binary values for verification
disp('Sample PCM Encoded Values (Binary):');
disp(pcm_encoded(1:10, :)); % Display first 10 encoded samples
% PCM Decoding (Reconstruction)
decoded_signal = bin2dec(pcm_encoded) / (quant_levels - 1); % Convert back to decimal
decoded_signal = decoded_signal * (max(signal) - min(signal)) + min(signal); % Denormalize
% Plot the decoded signal
subplot(3, 1, 3);
plot(t, decoded_signal, 'r');
title('Decoded Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Superimpose original and decoded signals for comparison
figure;
plot(t, signal, 'k', t, decoded_signal, 'r--');
legend('Original Signal', 'Decoded Signal');
title('Comparison of Original and Decoded Signals');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
DPCM
% DPCM Implementation in MATLAB
% Step 1: Signal generation
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector (1 second duration)
f = 5; % Frequency of the signal (Hz)
signal = sin(2*pi*f*t); % Original signal
% Step 2: Quantization parameters
nBits = 4; % Number of bits for quantization
nLevels = 2^nBits; % Number of quantization levels
signal_min = min(signal);
signal_max = max(signal);
qLevels = linspace(signal_min, signal_max, nLevels); % Quantization levels
% Step 3: DPCM Encoding
encodedSignal = zeros(size(signal)); % Encoded signal (quantized differences)
prediction = 0; % Initialize prediction
quantizedIndices = zeros(size(signal)); % Store quantized indices for binary representation
for i = 1:length(signal)
% Compute the difference
difference = signal(i) - prediction;
% Quantize the difference
[~, idx] = min(abs(qLevels - difference));
quantizedDifference = qLevels(idx);
% Save the encoded difference
encodedSignal(i) = quantizedDifference;
quantizedIndices(i) = idx - 1; % Store the index (0-based
% Update the prediction (reconstruction)
prediction = prediction + quantizedDifference;
end
% Convert quantized differences to binary (DPCM encoded)
dpcmCode = dec2bin(quantizedIndices, nBits); % Binary encoding
% Step 4: DPCM Decoding
decodedSignal = zeros(size(encodedSignal));
prediction = 0; % Initialize prediction for decoding
for i = 1:length(encodedSignal)
% Reconstruct the signal
decodedSignal(i) = prediction + encodedSignal(i);
prediction = decodedSignal(i); % Update the prediction
end
% Step 5: Visualization
figure;
% Original signal
subplot(3, 1, 1);
plot(t, signal);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Encoded DPCM Signal (quantized indices)
subplot(3, 1, 2);
stairs(quantizedIndices,'g');
title('DPCM Encoded Signal (Quantized Indices)');
xlabel('Sample Index');
ylabel('Index');
% Reconstructed signal
subplot(3, 1, 3);
plot(t, decodedSignal);
title('Reconstructed Signal (DPCM Decoded)');
xlabel('Time (s)');
ylabel('Amplitude');
disp('DPCM Encoded Binary Data:');
disp(dpcmCode);
3.7 Observations and results:
The PCM signal represents the sampled and quantized version of the analog input.
The DPCM signal effectively reduces redundancy by encoding differences between samples.
The demodulated PCM and DPCM signals closely resemble the original analog signal.
The magnitude spectrum of the PCM signal shows discrete frequency components.
3.8 Plotting of the graph:
PCM
DPCM
3.9 Conclusion of the experiment: The PCM and DPCM system experiment using MATLAB successfully demonstrated the conversion of analog signals to digital form through quantization and encoding techniques. It highlighted how DPCM improves compression efficiency by encoding the difference between successive samples, reducing the bit rate.