0% found this document useful (0 votes)
63 views7 pages

DC Lab 01

The document is a lab report submitted by Affra Nazir for the course EC-431 Digital Communication. It contains tasks to generate random binary numbers and perform pulse modulation using various line coding schemes: NRZ-L, RZ-L, Bi-Phase-L, and RZ-AMI. Code is provided to implement each of these schemes and plot the resulting waveforms. The plots show the pattern of pulses for each encoding over time.

Uploaded by

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

DC Lab 01

The document is a lab report submitted by Affra Nazir for the course EC-431 Digital Communication. It contains tasks to generate random binary numbers and perform pulse modulation using various line coding schemes: NRZ-L, RZ-L, Bi-Phase-L, and RZ-AMI. Code is provided to implement each of these schemes and plot the resulting waveforms. The plots show the pattern of pulses for each encoding over time.

Uploaded by

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

DEPARTMENT OF COMPUTER &

SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST,
RAWALPINDI

EC-431 Digital Communication

Lab Number 08

Submitted By:
Affra Nazir
CE 41 A
325292
LAB TASKS:

Task 1:
Generate random (uniform distributed) binary numbers with length 100000. Do the pulse
modulation by representing each bit (pulse) by 10 numerical values using the following line
codes:
1. NRZ-L
2. RZ-L (Bipolar-RZ)
3. Bi-Phase-L
4. RZ-AMI
The maximum magnitude of the pulse should be 1 and minimum should be -1.
Plot the waveform time[sec] vs amplitude[volts] to show the set pattern of respective pulses of
above-mentioned encoding schemes.

NRZ-L:
% Generate random binary numbers
binary_numbers = [1,1,1,0,0,0,1,0,1,1]

% Define pulse modulation parameters


bit_duration = 1; % duration of each bit in seconds
pulse_duration = 0.1; % duration of each pulse in seconds
num_samples_per_bit = round(bit_duration / pulse_duration); % number of samples per
bit
num_samples = length(binary_numbers) * num_samples_per_bit; % total number of
samples

% Generate pulse modulation waveform


pulse_waveform = zeros(1, num_samples);
for i = 1:length(binary_numbers)
if binary_numbers(i) == 0
pulse_waveform((i-1)*num_samples_per_bit + 1:i*num_samples_per_bit) = -1;
else
pulse_waveform((i-1)*num_samples_per_bit + 1:i*num_samples_per_bit) = 1;
end
end

% Generate time vector


time = linspace(0, num_samples*pulse_duration, num_samples);

% Plot the waveform


stairs(pulse_waveform);
xlabel('Time [sec]');
ylabel('Amplitude [volts]');
title('NRZ-L Pulse Modulation');
grid off;
OUTPUT:

RZ-L (Bipolar-RZ)
CODE;
% Generate a random binary sequence of length 100000
binary_seq = [1,1,0,0,1,0,0,0,1,0];

% Define the pulse amplitude and width


pulse_amp = 1;
pulse_width = 10;
% Initialize the pulse train
pulse_train = zeros(1,length(binary_seq)*pulse_width);

% Perform pulse modulation using RZ-L (Bipolar-RZ) line coding scheme


for i = 1:length(binary_seq)
if binary_seq(i) == 0
pulse_train((i-1)*pulse_width+1:i*pulse_width) = 0;
else
pulse_train((i-1)*pulse_width+1:i*pulse_width/2) = pulse_amp;
pulse_train(i*pulse_width/2+1:i*pulse_width) = -pulse_amp;
end
end

% Plot the waveform


t = linspace(0,length(binary_seq)*pulse_width,length(pulse_train));
plot(t,pulse_train);
xlabel('Time (s)');
ylabel('Amplitude (V)');
title('RZ-L (Bipolar-RZ) line coding scheme');

output:
Bi-Phase-L
Code:
% Generate random binary numbers with length 10
bits = randi([0 1], 1, 10);

% Pulse modulation using BI-PHASE L encoding


pulses = [];
for i = 1:length(bits)
if bits(i) == 0
pulse = [-1*ones(1, 5) ones(1, 5)];
else
pulse = [ones(1, 5) -1*ones(1, 5)];
end
pulses = [pulses pulse];
end

% Plot the waveform


t = 0:0.01:length(pulses)/100-0.01;
plot(t, pulses);
xlabel('Time (sec)');
ylabel('Amplitude (volts)');
output:

RZ-AMI:
Code:
% Generate random binary numbers
binaryData = [1,0,1,0,1,0,1,0,1,0]

% Perform RZ-AMI (Alternate Mark Inversion) pulse modulation


T = 10; % Number of samples per bit
Fs = 1000; % Sampling frequency (samples per second)
t = (0:length(binaryData)*T-1) / Fs; % Time vector

% Initialize the pulse modulation waveform


rzAmiWaveform = zeros(1, length(binaryData)*T);
previousLevel = 1; % Initialize the previous level to positive

% Perform pulse modulation


for i = 1:length(binaryData)
if binaryData(i) == 0
rzAmiWaveform((i-1)*T+1:i*T/2) = 0;
rzAmiWaveform(i*T/2+1:i*T) = 0;
else
if previousLevel == 1
rzAmiWaveform((i-1)*T+1:i*T/2) = 1;
rzAmiWaveform(i*T/2+1:i*T) = -1;
previousLevel = -1;
else
rzAmiWaveform((i-1)*T+1:i*T/2) = -1;
rzAmiWaveform(i*T/2+1:i*T) = 1;
previousLevel = 1;
end
end
end

% Plot the waveform


stairs(t, rzAmiWaveform);
xlabel('Time (s)');
ylabel('Amplitude (V)');
title('RZ-AMI Pulse Modulation');
ylim([-2, 2]);
grid on;

You might also like