Aim
The aim of this experiment is to implement Pulse Code Modulation (PCM) on a cosine wave
signal, demonstrating the key steps involved in the modulation process—sampling,
quantization, and encoding—and evaluating the quality of the signal using metrics such as
Bitrate, Mean Squared Error (MSE), and Quantization Noise.
Introduction
Pulse Code Modulation (PCM) is a digital technique used to represent analog signals. It
involves converting the continuous analog signal into a digital format by sampling the signal
at regular intervals, quantizing the sampled values to a finite set of levels, and encoding these
values into a binary format. PCM is widely used in various fields, such as digital telephony,
audio recording, and video transmission, due to its ability to accurately represent analog
signals while minimizing noise. Key parameters like Bitrate and MSE are used to assess the
effectiveness of PCM in signal representation and transmission.
CODE:
A=6; % amplitude of the signal
fm=9; % frequency of the signal
fs=60; % sampling frequency
n=9; % number of bits for quantization
t=0:1/(100*fm):1; % Time vector
x=A*cos(2*pi*fm*t); % Analog signal generation
ts=0:1/fs:1; % Time vector for sampled frequency
xs=A*cos(2*pi*fm*ts); % Sampled signal xs
x1=xs+A; % Shifting of sampled signal
x1=x1/(2*A); % Normalize
L=(-1+2^n); % Levels for quantization
x1=L*x1; % Scaled normalized signal
xq=round(x1); % Rounding off for quantization
r=xq/L;
r=2*A*r;
r=r-A;
y=[];
for i=1:length(xq)
d=dec2bin(xq(i),n);
y=[y double(d)-48];
end
MSE=sum((xs-r).^2)/length(x);
Bitrate=n*fs;
Stepsize=2*A/L;
QNoise=((Stepsize)^2)/12;
% Plot 1: Original Signal and Sampled Signal
figure(1)
plot(t,x,'color',[0.5 0 0.5],'linewidth',2) % Purple color for the original signal
title('Sampling')
ylabel('Amplitude')
xlabel('Time t(in sec)')
hold on
stem(ts,xs,'color',[0.2 0.6 0.2],'linewidth',2) % Green color for sampled signal
hold off
legend('Original Signal','Sampled Signal');
grid
% Plot 2: Quantization and Levels
figure(2)
stem(ts,x1,'color',[0 0.7 0.7],'linewidth',2) % Cyan for sampled signal after adding levels
title('Quantization')
ylabel('Levels L')
hold on
stem(ts,xq,'r','linewidth',2) % Red color for quantized signal
plot(ts,xq,'--r') % Red dashed line for quantized signal
plot(t,(x+A)*L/(2*A),'--b') % Blue dashed line for reconstructed signal
grid
hold off
legend('Sampled Signal','Quantized Signal');
% Plot 3: Binary Signal Encoding
figure(3)
stairs([y y(length(y))],'color',[0.8 0.4 0],'linewidth',2) % Orange for binary encoding
title('Encoding')
ylabel('Binary Signal')
xlabel('Bits')
axis([0 length(y) -1 2])
grid
% Plot 4: Add name and ID in the final plot
figure(4)
text(0.2, 0.6, 'V Divya CCE22045', 'FontSize', 14, 'FontWeight', 'bold');
axis off; % Hide axes
OUTPUT:
Inference:
The implementation of Pulse Code Modulation (PCM) on a cosine wave illustrates the
essential stages of sampling, quantization, and encoding. The accuracy of signal
reconstruction improves with a higher number of quantization bits, leading to reduced
distortion, as shown by a lower Mean Squared Error (MSE). While quantization introduces
Quantization Noise, increasing the resolution (bit depth) helps mitigate this effect. The
Bitrate represents the amount of data needed for transmission, which increases with the
number of bits. This experiment underscores the balance between signal quality and the data
bandwidth required in digital communication systems.