Hridayesh Rana 23BEC042
Practical File
DIGITAL COMMUNICATION LAB (EC-317)
Academic Year 2025-26
Submitted by
Name: Hridayesh Rana
Roll No.: 23BEC042
Branch: ECE
Semester: 5th
To
Dr. Sandeep Kumar Singh
Assistant Professor
E&CE Department
Electronics & Communication Engineering Department
NATIONAL INSTITUTE OF TECHNOLOGY, HAMIRPUR
Hamirpur, Himachal Pradesh - 177005 (India)
1
Hridayesh Rana 23BEC042
INDEX
S NO. EXPERIMENT DATE PAGE NO. SIGNATURE
To study the operation of Pulse
1. Code Modulation (PCM). 15.8.25 3-10
To study the operation of Pulse
Code Modulation (PCM) using
2. 21.8.25 11-19
NRZ line encoding.
3. To study the operation of Amp- 01.9.25 20-23
litude Shift Key (ASK).
4. To study the operation of Fre- 06.9.25 24-29
quency Shift Key (FSK).
5. To study the operation of Phase 15.09.25 30-34
Shift Key (PSK).
6. To study the differential encod- 22.09.25 34-38
ing and decoding.
Experiment 1:
2
Hridayesh Rana 23BEC042
Aim: To study PCM generation and reconstruction
PART1 : MATLAB CODE:
clc;
close all;
clear all;
% --- User Inputs ---
n = input('Enter n value for n-bit PCM system : ');
samples = input('Enter number of samples in a period : ');
% --- Analog Signal Generation ---
Am = 8; % message amplitude
x = 0:(2*pi/samples):4*pi;
s = Am*sin(x);
subplot(3,1,1);
plot(s);
grid on;
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% --- Sampling ---
subplot(3,1,2);
stem(s);
grid on;
title('Sampled Signal');
ylabel('Amplitude--->');
3
Hridayesh Rana 23BEC042
xlabel('Time--->');
% --- Quantization ---
M = 2^n; % number of quantization levels
vmax = Am;
vmin = -vmax;
S = (vmax-vmin)/M; % step size
part = vmin+S:S:vmax-S; % decision boundaries
code = vmin+(S/2):S:vmax-(S/2); % quantized levels
% --- Manual Quantization (Replaces quantiz function) ---
% Calculate the index for each sample by finding the nearest level
ind_0based = round((s - vmin - S/2) / S);
% Clamp indices to be within the valid range [0, M-1]
ind_0based(ind_0based < 0) = 0;
ind_0based(ind_0based >= M) = M-1;
% For getting the quantized value 'q', we need a 1-based index for MATLAB arrays.
ind_1based = ind_0based + 1;
q = code(ind_1based); % Look up the quantized value from the codebook
ind = ind_0based; % Use the 0-based index for binary encoding
subplot(3,1,3);
stem(q,'.');
grid on;
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% --- Encoding ---
figure
4
Hridayesh Rana 23BEC042
code1 = de2bi(ind,'left-msb', n); % decimal to binary, MSB first
k = 1;
l1 = length(ind);
for i = 1:l1
for j = 1:n
coded(k) = code1(i,j);
k = k+1;
end
end
subplot(2,1,1);
stairs(coded); grid on;
axis([0 100 -0.5 1.5]); % Adjusted axis for better view
title('Encoded Signal');
ylabel('Amplitude');
xlabel('Bits--->');
% --- Decoding (Demodulation) ---
qunt = reshape(coded,n,length(coded)/n);
index = bi2de(qunt','left-msb'); % convert binary back to decimal
q_demod = vmin+(S/2) + S*index; % get quantized values back
subplot(2,1,2);
grid on;
plot(q_demod);
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
5
Hridayesh Rana 23BEC042
OUTPUT:
PART 2: SIMULINK
6
Hridayesh Rana 23BEC042
Blocks required (with block properties):
1)Sine wave block
4)Uniform encoder block
2)Pulse generator block
5)Integer to bit convertor block
6)Uniform decoder
3)Sample and hold block
7
Hridayesh Rana 23BEC042
8)scope block
9)Bit to integer convertor block
7)Analog filter design
Final simulink model:
8
Hridayesh Rana 23BEC042
Output:
a)Input signal sine wave of 5 V amplitude and 12.56 rad/sec freq b)digital sampling signal of period 0.05 sec
c) sample and hold output (pcm modulated wave)
a) Input sine wave
b) Before low pass filter (demodulated)
c) After low pass filter (demodulated)
9
Hridayesh Rana 23BEC042
Experiment – 2
Aim: To study NRZ L(line), M (mark) and S (space) transmission scheme
PART 1: MATLAB CODE
clc;
close all;
clear all;
% --- USER INPUTS ---
n = input('Enter n value for n-bit PCM system : ');
samples = input('Enter number of samples in a period : ');
nrz_type = input('Enter NRZ encoding type ("L" for Level, "M" for Mark, "S" for Space): ','s');
10
Hridayesh Rana 23BEC042
% --- ANALOG SIGNAL GENERATION ---
Am = 8; % amplitude
x = 0:(2*pi/samples):4*pi;
s = Am*sin(x);
figure;
subplot(6,1,1);
plot(s);
grid on;
title('Analog Signal');
ylabel('Amplitude');
xlabel('Time');
% --- SAMPLING ---
subplot(6,1,2);
stem(s,'filled');
grid on;
title('Sampled Signal');
ylabel('Amplitude');
xlabel('Time');
% --- QUANTIZATION ---
M = 2^n; % number of quantization levels
vmax = Am;
vmin = -vmax;
S = (vmax-vmin)/M; % step size
part = vmin+S:S:vmax-S; % decision boundaries
code = vmin+(S/2):S:vmax-(S/2); % quantized levels
ind_0based = round((s - vmin - S/2) / S);
11
Hridayesh Rana 23BEC042
ind_0based(ind_0based < 0) = 0;
ind_0based(ind_0based >= M) = M-1;
ind_1based = ind_0based + 1;
q = code(ind_1based);
subplot(6,1,3);
stem(q,'filled');
grid on;
title('Quantized Signal');
ylabel('Amplitude');
xlabel('Time');
% --- ENCODING (to bits) ---
code1 = de2bi(ind_0based, n, 'left-msb'); % matrix size [samples, n]
coded = reshape(code1', 1, []); % columnwise to a single bit stream
subplot(6,1,4);
stairs(coded,'LineWidth',1.3);
grid on;
axis([0 length(coded) -0.5 1.5]);
title('Encoded Signal (PCM bits)');
ylabel('Bits');
xlabel('Bit Index');
% --- NRZ ENCODING ---
samples_per_bit = 10; % for visualization, number of points per bit
N_bits = length(coded);
% Generate time vector for expanded NRZ signal
bit_time = repelem(coded, samples_per_bit);
12
Hridayesh Rana 23BEC042
time_nrz = (0:length(bit_time)-1);
% --- NRZ LOGIC ---
switch upper(nrz_type)
case 'L' % NRZ-Level
nrz_wave = bit_time;
enc_title = 'NRZ-L Encoded Signal';
case 'M' % NRZ-Mark
mark_level = 0;
mark_vec = zeros(1,N_bits);
for i=1:N_bits
if coded(i)==1
mark_level = 1 - mark_level;
end
mark_vec(i) = mark_level;
end
nrz_wave = repelem(mark_vec, samples_per_bit);
enc_title = 'NRZ-M Encoded Signal';
case 'S' % NRZ-Space
space_level = 0;
space_vec = zeros(1,N_bits);
for i=1:N_bits
if coded(i)==0
space_level = 1 - space_level;
end
space_vec(i) = space_level;
end
nrz_wave = repelem(space_vec, samples_per_bit);
enc_title = 'NRZ-S Encoded Signal';
otherwise
13
Hridayesh Rana 23BEC042
error('Invalid NRZ type. Use "L", "M", or "S"');
end
% --- PLOT NRZ ENCODED SIGNAL ---
subplot(6,1,5);
stairs(time_nrz, nrz_wave, 'LineWidth', 1.5);
grid on;
ylim([-0.2 1.2]);
title(enc_title);
xlabel('Time');
ylabel('Level');
% --- DECODING (DEMODULATION from bits) ---
qunt = reshape(coded, n, length(coded)/n);
index = bi2de(qunt', 'left-msb');
q_demod = vmin + (S/2) + S*index;
subplot(6,1,6);
plot(q_demod,'LineWidth',1.3);
grid on;
title('Demodulated Signal');
ylabel('Amplitude');
xlabel('Sample Index');
output:
user prompt 1 : no of bits = 3, samples per second = 50, nrz L
14
Hridayesh Rana 23BEC042
user prompt 2 : no of bits = 3, samples per second = 50, nrz M
user prompt 2 : no of bits = 3, samples per second = 50, nrz S
15
Hridayesh Rana 23BEC042
PART B: SIMULINK (*note: nrz L is same as pcm, nrz s is not of nrz m, making the
model of nrz m which can further be used to obtain nrz s)
BLOCKS REQUIRED (with block properties):
Blocks same as pcm, :
1)pulse wave generator
4) uniform encoder
2)sine wave generator
5)integer to bit converter
3) sample and hold
16
Hridayesh Rana 23BEC042
Now taking pcm as input to nrz circuit:
6) xor gate
9) gain
7)delay
10) scope
8) boolean to double converter
Final Simulink model:
17
Hridayesh Rana 23BEC042
Output:
a)input sine wave
b)sampling signal
18
Hridayesh Rana 23BEC042
c)pulse code modulated signal or nrz-l
d)nrz-m signal
Experiment – 3
Aim: To study Ask modulation and demodulation
PART 1: MATLAB CODE
clc; close all; clear;
% --- USER INPUTS ---
b = input('Enter the Bit stream (e.g. [1 0 1 1 0 0]) : ');
n = length(b);
Fs = 1000; % Sampling frequency
Fc = 10; % Carrier frequency
Tb = 1; % Bit duration
t = 0:1/Fs:n*Tb; % Total time
% --- Generate message signal ---
19
Hridayesh Rana 23BEC042
msg = zeros(1,length(t));
for i=1:n
msg((i-1)*Fs*Tb+1:i*Fs*Tb) = b(i);
end
% --- Carrier signal ---
carrier = sin(2*pi*Fc*t);
% --- ASK Modulation ---
ASK = msg .* carrier;
% --- PLOTS ---
subplot(4,1,1); plot(t, msg); title('Message Signal (Binary)'); axis([0 n -0.2 1.2]); grid on;
subplot(4,1,2); plot(t, carrier); title('Carrier Signal'); grid on;
subplot(4,1,3); plot(t, ASK); title('ASK Signal'); grid on;
% --- ASK Demodulation ---
ASK_demod = ASK .* carrier;
ASK_filtered = lowpass(ASK_demod, Fc/2, Fs); % Simple LPF
demod_bits = ASK_filtered > 0.3;
subplot(4,1,4); plot(t, demod_bits); title('Demodulated Bits'); axis([0 n -0.2 1.2]); grid on;
OUTPUT:
20
Hridayesh Rana 23BEC042
PART B: SIMULINK
BLOCKS REQUIRED (with block properties):
1) Sine Wave Block
21
Hridayesh Rana 23BEC042
3) Product block
2) Pulse generator block
4) Scope Block
Final Simulink model
22
Hridayesh Rana 23BEC042
OUTPUT:
a) Sine carrier 5v 10 rad/sec b)pulse input series 0101010 c) ask modulated signal d) ask demodulated
signal
Experiment 4
23
Hridayesh Rana 23BEC042
Aim: To study frequency shift keying modulation and demodulation
PART 1: MATLAB CODE
clc; close all; clear;
% --- USER INPUTS ---
b = input('Enter the Bit stream (e.g. [1 0 1 1 0 0]) : ');
n = length(b);
Fs = 1000; % Sampling frequency (lower for visibility)
Fc1 = 10; % Carrier frequency for bit '1'
Fc0 = 5; % Carrier frequency for bit '0'
Tb = 1; % Bit duration (1 second per bit for clear view)
t = 0:1/Fs:n*Tb; % Total time
% --- Generate message signal (binary for reference) ---
msg = zeros(1,length(t));
for i=1:n
msg((i-1)*Fs*Tb+1:i*Fs*Tb) = b(i);
end
% --- FSK Modulation ---
fsk = zeros(1,length(t));
for i=1:n
idx = (i-1)*Fs*Tb+1:i*Fs*Tb;
if b(i) == 1
fsk(idx) = sin(2*pi*Fc1*t(idx)); % freq for '1'
else
fsk(idx) = sin(2*pi*Fc0*t(idx)); % freq for '0'
end
end
24
Hridayesh Rana 23BEC042
% --- PLOTS ---
subplot(4,1,1); plot(t, msg, 'LineWidth',1.5);
title('Message Signal (Binary)'); axis([0 n -0.2 1.2]); grid on;
subplot(4,1,2); plot(t, sin(2*pi*Fc1*t),'r');
title('Carrier for bit 1 (10 Hz)'); grid on;
subplot(4,1,3); plot(t, sin(2*pi*Fc0*t),'g');
title('Carrier for bit 0 (5 Hz)'); grid on;
subplot(4,1,4); plot(t, fsk,'b');
title('FSK Modulated Signal'); grid on;
% --- FSK Demodulation ---
demod_bits = zeros(1,n);
for i=1:n
idx = (i-1)*Fs*Tb+1:i*Fs*Tb;
x = fsk(idx);
c1 = sum(x .* sin(2*pi*Fc1*t(idx))); % correlation with Fc1
c0 = sum(x .* sin(2*pi*Fc0*t(idx))); % correlation with Fc0
if c1 > c0
demod_bits(i) = 1;
else
demod_bits(i) = 0;
end
end
% --- Plot Demodulated Output ---
figure;
stem(0:n-1, demod_bits,'filled','LineWidth',1.5);
title('Demodulated Bit Stream');
xlabel('Bit index'); ylabel('Bit value');
25
Hridayesh Rana 23BEC042
axis([0 n-1 -0.2 1.2]); grid on;
PART B : SIMULINK
26
Hridayesh Rana 23BEC042
Required blocks (with block properties):
1) Sine wave block 1 3) Pulse generator block
4) Switch block
2) Sine wave block 2
5) Scope block
Final Simulink model:
27
Hridayesh Rana 23BEC042
OUTPUT:
a) input digital signal 10101010
b) fsk modulated signal
c) sin carrier wave 1
d) sin carie wave 2
Experiment 5
28
Hridayesh Rana 23BEC042
Aim: To study phase shift keying modulation and demodulation
PART 1: MATLAB CODE
clc; close all; clear;
% --- Parameters ---
bit_stream = [1 0 1 1 0]; % Example bits
num_bits = length(bit_stream);
Fs = 200; % Sampling frequency (Hz)
Fc = 5; % Carrier frequency (Hz)
Tb = 0.5; % Bit duration (s)
N = Fs*Tb; % Samples per bit
t = (0:(num_bits*N-1))/Fs; % Time vector
% --- NRZ encoding (1 -> +1, 0 -> -1) ---
nrz_wave = repelem(2*bit_stream-1, N);
% --- Carrier ---
carrier = cos(2*pi*Fc*t);
% --- BPSK modulation ---
bpsk_signal = nrz_wave .* carrier;
% --- Demodulation ---
bp_demod = bpsk_signal .* carrier;
bp_filtered = lowpass(bp_demod, Fc/2, Fs);
29
Hridayesh Rana 23BEC042
% --- Bit recovery ---
recovered_bits = zeros(1, num_bits);
for i = 1:num_bits
idx = (i-1)*N+1 : i*N;
mean_val = mean(bp_filtered(idx));
recovered_bits(i) = mean_val > 0;
end
% --- Plots ---
subplot(4,1,1);
stairs(repelem(bit_stream,N), 'LineWidth',1.5);
title('Original Bit Stream'); ylim([-0.2 1.2]); grid on;
subplot(4,1,2);
plot(t, nrz_wave,'LineWidth',1.5);
title('NRZ Waveform'); ylim([-1.2 1.2]); grid on;
subplot(4,1,3);
plot(t, bpsk_signal,'LineWidth',1.2);
title('BPSK Modulated Signal'); grid on;
subplot(4,1,4);
stairs(repelem(recovered_bits,N),'LineWidth',1.5);
title('Demodulated Bit Stream'); ylim([-0.2 1.2]); grid on;
% --- Display results ---
disp('Original Bits: '), disp(bit_stream)
disp('Recovered Bits: '), disp(recovered_bits)
30
Hridayesh Rana 23BEC042
Output:
PART B : SIMULINK
31
Hridayesh Rana 23BEC042
Required blocks (with block properties):
1) Sine wave block 1 3) Pulse generator block
2) Sine wave block 2 4) Switch block
5) Scope block
Final Simulink model:
32
Hridayesh Rana 23BEC042
OUTPUT:
a) Sin wave 1
b) Sine wave 2 90 degee phase diff from sin wave 1
c) Digital input signal 10101010
d) Psk modulated wave
Experiment 6
33
Hridayesh Rana 23BEC042
Aim: To study differential phase shift keying modulation and demodulation
PART 1: MATLAB CODE
clc; clear; close all;
% --- Parameters ---
bit_stream = [1 0 1 1 0 0 1 1 0 1 0 1 0 0 1 1]; % Longer input bit stream
num_bits = length(bit_stream);
% --- DPSK Modulation (Differential Encoding using XOR) ---
dpsk_modulated = zeros(1, num_bits);
prev_bit = 0; % initial reference bit
for i = 1:num_bits
dpsk_modulated(i) = xor(bit_stream(i), prev_bit);
prev_bit = dpsk_modulated(i);
end
% --- DPSK Demodulation (Differential Decoding) ---
dpsk_demodulated = zeros(1, num_bits);
prev_bit = 0; % initial reference bit
for i = 1:num_bits
dpsk_demodulated(i) = xor(dpsk_modulated(i), prev_bit);
prev_bit = dpsk_modulated(i);
end
% --- Plotting ---
figure;
subplot(3,1,1);
34
Hridayesh Rana 23BEC042
stairs(bit_stream, 'LineWidth', 1.5);
title('Original Bit Stream');
ylim([-0.2 1.2]);
grid on;
subplot(3,1,2);
stairs(dpsk_modulated, 'LineWidth', 1.5);
title('DPSK Modulated (Differentially Encoded) Bits');
ylim([-0.2 1.2]);
grid on;
subplot(3,1,3);
stairs(dpsk_demodulated, 'LineWidth', 1.5);
title('DPSK Demodulated (Differentially Decoded) Bits');
ylim([-0.2 1.2]);
grid on;
% --- Display results ---
disp('Original Bits: '), disp(bit_stream)
disp('Modulated Bits: '), disp(dpsk_modulated)
disp('Demodulated Bits:'), disp(dpsk_demodulated)
OUTPUT:
35
Hridayesh Rana 23BEC042
PART B : SIMULINK
Required blocks (with block properties):
1) Bernoulli binary generator
2) Delay 1
3) 2 input XOR gate
36
Hridayesh Rana 23BEC042
4) scope
Final Simulink Model
OUTPUT:
37
Hridayesh Rana 23BEC042
a) input binary signal as generated by Bernoulli binary generator
b) dpsk modulated signal
c) demodulated signal (matches with input)
38