EC21B1005-Tharak L4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Communication Systems Practice

Exp (No.4): (Pulse code Modulation and Demodulation)

E THARAKA RAM(EC21B1005)
February 29, 2024

Aim
• To perform Pulse Code Modulation and demodulation using MATLAB.

5
Software Used

00
Latest Version of MATLAB.

Pulse code Modulation


B1
Theory
Pulse Code Modulation (PCM) is a digital modulation technique used to represent analog
signals with digital data. It involves three main steps:
21

0.1 sampling
The continuous analog signal is sampled at regular intervals, capturing its amplitude at each
sampling instant.
EC

Let x(t) represent the continuous analog signal. The sampled signal xs (t) is obtained by
multiplying x(t) with an impulse train p(t) (sampling function):

xs (t) = x(t) · p(t)

0.2 Quantization
Each sampled amplitude is quantized into a discrete digital value. This involves assigning a
digital code to represent each sampled amplitude. The resolution of quantization, determined
by the number of bits used, affects the fidelity of the reconstructed signal.
Each sample of xs (t) is quantized into a discrete level. Let Q represent the quantization
function. The quantized signal xq (t) can be expressed as:

xq (t) = Q[xs (t)]

1
0.3 Encoding
After quantization, the digital codes representing the sampled amplitudes are transmitted or
stored. This sequence of digital codes is the PCM signal.
Each quantized sample xq (t) is assigned a digital code. Let C represent the encoding function.
The encoded signal xe (t) can be represented as:

xe (t) = C[xq (t)]

The PCM signal x(t) can be expressed as:

x(t) = C[Q[x(t) · p(t)]]

0.4 Demodulation(Decoding)
At the receiving end, the PCM signal is decoded to reconstruct the original analog signal. This

5
involves reversing the quantization process and converting the digital codes back into analog
amplitudes. The decoded signal is then reconstructed using interpolation or other techniques.

00
In PCM, the demodulation process is also known as decoding. It involves reversing the quan-
tization process and converting the digital codes back into analog amplitudes.
Let y(t) represent the reconstructed analog signal after demodulation. The demodulation
process involves the following steps:
B1
1. Decoding: Each digital code xe (t) representing the quantized samples is decoded to
obtain the quantized samples xq (t). Let D represent the decoding function. The decoded
signal xd (t) can be expressed as:

xd (t) = D[xe (t)]


21

2. Reconstruction: The quantized samples xq (t) are converted back into analog ampli-
tudes to reconstruct the original analog signal y(t). This process may involve interpola-
tion or other techniques depending on the quantization scheme used.
EC

Combining these steps, the reconstructed analog signal y(t) can be expressed as:

y(t) = Reconstruction[D[xe (t)]]

PCM offers advantages such as noise immunity, ease of signal processing, and compatibility
with digital systems. It finds applications in telecommunications, audio recording, and data
transmission.

2
MATLAB code and waveforms
%E THARAKA RAM
%EC21B1005
% Define parameters
n = 4;
fm = 10;
fs = 200;
Vmax = 5;
L = 2^n;
t = 0:1/fs:1;
% Number of bits for quantization
% Frequency of the message signal
% Sampling frequency
% Maximum value of the message signal
% Number of quantization levels

05
% Time vector
% Generate message signal
signal = Vmax * sin(2 * pi * fm * t);
% Plot original message signal
figure;
subplot(321);
plot(t, signal, ’black’);
0
B1
title(’Message Signal’);
sgtitle(’EKAMBARAM THARAKA RAM’)
% Sampled Signal
subplot(322);
stem(t, signal);
21

grid on;
title(’Sampled Signal’);
% Quantization
Vmin =-Vmax;
del = (Vmax- Vmin) / L;
EC

QLevels = Vmin:del:Vmax;
% Quantization step size
% Quantization levels
% Calculate quantization levels
q=zeros(size(QLevels)-1);
for i=1:(length(QLevels)-1)
q(i)=(QLevels(i)+QLevels(i+1))/2;
end
% Define codebook for encoding
q_f=zeros(size(q));
for i=1:length(q)
q_f(i)=i-1;
end
code=Vmin-(del/2):del:Vmax+(del/2);
% Quantize the signal
[quantized_sig,indx]=custom_quantiz(signal,QLevels);
% Plot quantized signal

3
subplot(323);
stairs(t, quantized_sig, ’black’);
grid on;
title(’Quantized Signal’);
% Encode quantized signal
encoded_sig = de2bi(indx);
subplot(324);
stairs(t,encoded_sig);
title(’Encoded Signal’);
xlabel(’Time’);
ylabel(’Binary Value’);
% Quantization error
quantization_error = signal- quantized_sig;
% Plot quantization error signal
subplot(325);
plot(t, quantization_error, ’black’);

05
grid on;
title(’Quantization Error Signal’);
% Demodulation (Filtering)
N = 200;
n1 =-((N- 1) / 2):1/fs:((N- 1) / 2);
w = 2 * pi * fm;
hd = sin(w * n1) ./ (n1 * pi);
0
B1
demodulated_signal = filter(hd, 3, quantized_sig);
% Plot demodulated signal
subplot(326);
plot(t, demodulated_signal, ’black’);
title(’Demodulated Signal’);
21

% Plot FFTs
figure;
subplot(311);
plot(t, abs(fft(signal)), ’black’);
title(’Message Signal FFT’);
EC

sgtitle(’EKAMBARAM THARAKA RAM’)


subplot(312);
plot(t, abs(fft(quantized_sig)), ’black’);
title(’Quantized Signal FFT’);
subplot(313);
plot(t, abs(fft(demodulated_signal)), ’black’);
title(’Demodulated Signal FFT’);
% Calculate theoretical signal-to-noise ratio (SQNR)
signal_power = var(signal);
noise_power = (del^2) / 12;
T_SQNR = signal_power / noise_power;
T_SQNR_DB = 10 * log10(T_SQNR);
% Print theoretical SQNR results
fprintf(’Theoretical SQNR = %f\n’, T_SQNR);
fprintf(’Theoretical SQNR in dB = %f\n’, T_SQNR_DB);
% Calculate practical signal-to-noise ratio (SQNR)
P_SQNR = signal_power / var(quantization_error);

4
P_SQNR_DB = 10 * log10(P_SQNR);
% Print practical SQNR results
fprintf(’Practical SQNR = %f\n’, P_SQNR);
fprintf(’Practical SQNR in dB = %f\n’, P_SQNR_DB);
function [quantized_signal, indices] = custom_quantiz(input_signal, quantization_level
% Sort the quantization levels in ascending order
quantization_levels = sort(quantization_levels);
% Initialize the quantized signal and indices
quantized_signal = zeros(size(input_signal));
indices = zeros(size(input_signal));
% Loop through each sample in the input signal
for i = 1:length(input_signal)
% Find the nearest quantization level for the current sample
[~, idx] = min(abs(quantization_levels- input_signal(i)));
% Assign the corresponding quantization level to the quantized signal
quantized_signal(i) = quantization_levels(idx);

5
% Store the index of the quantization level
indices(i) = idx;

00
end
end
B1
21
EC

Figure 1: Basic graphs for n=2

5
5
Figure 2: Spectrum for n=2

00
B1
21
EC

Figure 3: Basic graphs for n=3

Figure 4: Spectrum for n=3

6
Figure 5: Basic graphs for n=4

5
00
B1
21

Figure 6: Spectrum for n=4


EC

Figure 7: Basic graphs for n=5

7
Figure 8: Spectrum for n=5

5
Inference
The communication system encompassing signal sampling, quantization, encoding, modula-

00
tion, demodulation, and SNR evaluation. It begins by generating a sinusoidal message signal,
which is sampled and quantized into discrete levels. The quantized signal is encoded into
binary form, and quantization error is assessed. Demodulation is executed using a filter, with
FFT plots illustrating frequency domains. The script computes both theoretical and practical
B1
SNR values, enabling a comparison of expected and observed performance. Overall, it pro-
vides a hands-on demonstration of fundamental concepts in digital communication, offering
insights into signal fidelity and noise resilience within practical systems.

Observations
21

The experimentation on pulse code modulation and demodulation conducted with MATLAB
yielded noteworthy results. MATLAB’s signal processing package facilitated in-depth analysis
of PCM signals, enabling tasks such as spectrum analysis and modulation index computation
EC

with precision. Together, these platforms delivered invaluable insights into the intricacies of
FM modulation and demodulation techniques.

Results
The Pulse code modulation techniques and the demodulation of these modulated signals were
observed and the outputs were noted and verified by respective TAs.

You might also like