0% found this document useful (0 votes)
23 views8 pages

Lab Report4

Datacom Lab Report 4

Uploaded by

Rishat Ryan
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)
23 views8 pages

Lab Report4

Datacom Lab Report 4

Uploaded by

Rishat Ryan
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/ 8

Title:

Study of Digital to Digital Conversion (Line Coding) Using MATLAB


Abstract:
The objective of this experiment was to understand the use of MATLAB for solving communication
engineering problems. It also developed an understanding of Digital to Digital Conversion (Line Coding)
using MATLAB
Introduction:
Line Coding: Line coding is the process of converting digital data to digital signals. We assume that data,
in the form of text, numbers, graphical images, audio or video, are stored in computer memory as
sequences of bits. Line coding converts a sequence of bits to a digital signal. At the sender, digital data are
encoded into a digital signal; at the receiver, the digital data are recreated by decoding the digital signal.
Signal Elements and Data Elements:
Let us distinguish between a data element and a signal element. In data communications, our goal is to
send data elements. A data element is the smallest entity that can represent a piece of information: this is
the bit. In digital data communications, a signal element carries data elements. A signal element is the
shortest unit (timewise) of a digital signal. In other words, data elements are what we need to send; signal
elements are what we can send.

S = c * N * (1/r); [S = Signal Rate, c = case factor, N = Data Rate, r = (Number of Data


Elements)/(Number of Signal Elements)]
Bandwidth: We know that a digital signal that carries information is nonperiodic. We also know that the
bandwidth of a nonperiodic signal is continuous with an infinite range. However, most digital signals we
encounter in real life have a bandwidth with finite values. In other words, the bandwidth is theoretically
infinite, but many of the components have such a small amplitude that they can be ignored. The effective
bandwidth is finite. From now on, when we talk about the bandwidth of a digital signal, we need to
remember that we are talking about this effective bandwidth.
Multilevel: The desire to increase the data rate or decrease the required bandwidth has resulted in the
creation of many schemes. The goal is to increase the number of bits per baud by encoding a pattern of m
data elements into a pattern of n signal elements. We only have two types of data elements (0s and 1s),
which means that a group of m data elements can produce a combination of 2mdata patterns. We can have
different types of signal elements by allowing different signal levels. If we have L different levels, then
we can produce Ln combinations of signal patterns. If 2m = Ln, then each data pattern is encoded into one
signal pattern. If 2m < Ln, data patterns occupy only a subset of signal patterns. The subset can be
carefully designed to prevent baseline wandering, to provide synchronization, and to detect errors that
occurred during data transmission. Data encoding is not possible if 2m > Ln because some of the data
patterns cannot be encoded
1 9 4 1 1 4 0 - 2
A B C D E F G H

4 bit Binary to Bit Stream of 12 Bits


E-> 1 -> 0001
F-> 4 -> 0100
G-> 0 -> 0000
12 bit data stream = 0001 0011 0010
Performance Task 1: Polar NRZ-L assuming bit rate is 4kbps.
Code:
bit_stream = [0 0 0 1 0 1 0 0 0 0 0 0 ];
no_bits = length(bit_stream);
bit_rate = 4000; % 4 kbps
pulse_per_bit = 1; % for unipolar NRZ
pulse_duration = 1 / (pulse_per_bit * bit_rate); % pulse duration
no_pulses = no_bits * pulse_per_bit;
samples_per_pulse = 500;
fs = samples_per_pulse / pulse_duration; % sampling frequency
t = 0:1/fs:(no_pulses * pulse_duration) - 1/fs; % sampling interval
no_samples = length(t);
dig_sig = zeros(1, no_samples);
max_voltage = 5;
min_voltage = 0; % Unipolar NRZ uses 0 for low level
% Create the digital signal
for i = 1:no_bits
if bit_stream(i) == 1
dig_sig((i-1) * samples_per_pulse + 1:i * samples_per_pulse) = max_voltage * ones(1,
samples_per_pulse);
else
dig_sig((i-1) * samples_per_pulse + 1:i * samples_per_pulse) = min_voltage * ones(1,
samples_per_pulse);
end
end
plot(t, dig_sig, 'linewidth', 1.5);
grid on;
xlabel('Time in seconds');
ylabel('Voltage');
ylim([min_voltage - max_voltage * 0.2, max_voltage + max_voltage * 0.2]);
title(['Unipolar NRZ for ', num2str(bit_stream)]);
Figure 1: Unipolar NRZ

Performance Task 2: Manchester assuming bit rate is 2 kbps.


Code:
bit_stream = [0 0 0 1 0 1 0 0 0 0 0 0 ]; % Define the bit stream correctly
no_bits = length(bit_stream);
bit_rate = 2000; % 2 kbps
pulse_per_bit = 2;
pulse_duration = 1 / (pulse_per_bit * bit_rate);
no_pulses = no_bits * pulse_per_bit;
samples_per_pulse = 500;
fs = samples_per_pulse / pulse_duration; % Sampling frequency
t = 0:1/fs:(no_pulses * pulse_duration); % Sampling interval
no_samples = length(t);
dig_sig = zeros(1, no_samples);
max_voltage = +2;
min_voltage = -2;
for i = 1:no_bits
j = (i - 1) * pulse_per_bit;
if bit_stream(i) == 1
dig_sig((j * samples_per_pulse) + 1 : (j + 0.5) * samples_per_pulse)
= max_voltage * ones(1, samples_per_pulse / 2);
dig_sig(((j + 0.5) * samples_per_pulse) + 1 : (j + 1) *
samples_per_pulse) = min_voltage * ones(1, samples_per_pulse / 2);

dig_sig(((j + 1) * samples_per_pulse) + 1 : (j + 1.5) *


samples_per_pulse) = min_voltage * ones(1, samples_per_pulse / 2);
dig_sig(((j + 1.5) * samples_per_pulse) + 1 : (j + 2) *
samples_per_pulse) = max_voltage * ones(1, samples_per_pulse / 2);
else
dig_sig((j * samples_per_pulse) + 1 : (j + 0.5) * samples_per_pulse)
= min_voltage * ones(1, samples_per_pulse / 2);
dig_sig(((j + 0.5) * samples_per_pulse) + 1 : (j + 1) *
samples_per_pulse) = max_voltage * ones(1, samples_per_pulse / 2);

dig_sig(((j + 1) * samples_per_pulse) + 1 : (j + 1.5) *


samples_per_pulse) = max_voltage * ones(1, samples_per_pulse / 2);
dig_sig(((j + 1.5) * samples_per_pulse) + 1 : (j + 2) *
samples_per_pulse) = min_voltage * ones(1, samples_per_pulse / 2);
end
end

figure;
plot(t, dig_sig, 'linewidth', 1.5);
grid on;
xlabel('Time in seconds');
ylabel('Voltage');
ylim([min_voltage - max_voltage * 0.2, max_voltage + max_voltage * 0.2]);
title(['Manchester for ', num2str(bit_stream)]);
Performance Task 3: Polar NRZ-L assuming bit rate is 4kbps.
Code 3:
bit_stream = [0 0 0 1 0 1 0 0 0 0 0 0 ];
no_bits = length(bit_stream);
bit_rate = 5000;
pulse_per_bit = 1;
pulse_duration = 1;
no_pulses = no_bits * pulse_per_bit;
samples_per_pulse = 500;
fs = samples_per_pulse / pulse_duration;
t = 0:1/fs:(no_pulses * pulse_duration);
no_samples = length(t);
dig_sig = zeros(1, no_samples);
max_voltage = 2;
avg_voltage = 0;
min_voltage = -2;
inv_bit = 1;

for i = 1:no_bits
if bit_stream(i) == 1
if inv_bit == 1
dig_sig(((i-1)*samples_per_pulse + 1):i*samples_per_pulse) =
max_voltage * ones(1, samples_per_pulse);
inv_bit = 0;
else
dig_sig(((i-1)*samples_per_pulse + 1):i*samples_per_pulse) =
min_voltage * ones(1, samples_per_pulse);
inv_bit = 1;
end
else
dig_sig(((i-1)*samples_per_pulse + 1):i*samples_per_pulse) =
avg_voltage * ones(1, samples_per_pulse);
end
end

% Plot the AMI signal


figure;
plot(t, dig_sig, 'linewidth', 1.5);
grid on;
xlabel('Time in seconds');
ylabel('Voltage');
ylim([min_voltage - (max_voltage * 0.2), max_voltage + (max_voltage * 0.2)]);
title(['AMI for ', num2str(bit_stream)]);
Code:4

Performance Task 4: MLT-3 assuming bit rate is 10 kbps.


Code:
bit_stream = [0 0 0 1 0 1 0 0 0 0 0 0 ];
no_bits = length(bit_stream);
bit_rate = 10000;
pulse_per_bit = 1;
pulse_duration = 1 / bit_rate;
no_pulses = no_bits * pulse_per_bit;
samples_per_pulse = 500;
fs = samples_per_pulse / pulse_duration;
t = 0:1/fs:(no_pulses * pulse_duration) - 1/fs;
no_samples = length(t);
dig_sig = zeros(1, no_samples);
max_voltage = 2;
min_voltage = -2;
neutral_volt = 0;
last_state = neutral_volt;
prev_last_state = min_voltage;

for i = 1:no_bits
if bit_stream(i) == 1
if last_state == max_voltage
dig_sig(((i-1) * samples_per_pulse + 1):(i * samples_per_pulse))
= neutral_volt * ones(1, samples_per_pulse);
last_state = neutral_volt;
prev_last_state = max_voltage;
elseif last_state == min_voltage
dig_sig(((i-1) * samples_per_pulse + 1):(i * samples_per_pulse))
= neutral_volt * ones(1, samples_per_pulse);
last_state = neutral_volt;
prev_last_state = min_voltage;
else
if prev_last_state == max_voltage
dig_sig(((i-1) * samples_per_pulse + 1):(i *
samples_per_pulse)) = min_voltage * ones(1, samples_per_pulse);
last_state = min_voltage;
prev_last_state = neutral_volt;
else
dig_sig(((i-1) * samples_per_pulse + 1):(i *
samples_per_pulse)) = max_voltage * ones(1, samples_per_pulse);
last_state = max_voltage;
prev_last_state = neutral_volt;
end
end
else
dig_sig(((i-1) * samples_per_pulse + 1):(i * samples_per_pulse)) =
last_state * ones(1, samples_per_pulse);
end
end

% Plot the MLT-3 signal


figure;
plot(t, dig_sig, 'linewidth', 1.5);
grid on;
xlabel('Time in seconds');
ylabel('Voltage');
ylim([min_voltage - (max_voltage * 0.2), max_voltage + (max_voltage * 0.2)]);
title(['MLT-3 for bits: ', num2str(bit_stream)]);

You might also like