0% found this document useful (0 votes)
3 views

Line codes_explanation

The document outlines a MATLAB script for generating and plotting various line coding techniques including NRZ and RZ encodings, as well as Manchester coding. It details the initialization of parameters, generation of random binary data, and the transformation of this data into different encoding formats. The results are visualized through multiple subplots to compare the different encoding schemes.

Uploaded by

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

Line codes_explanation

The document outlines a MATLAB script for generating and plotting various line coding techniques including NRZ and RZ encodings, as well as Manchester coding. It details the initialization of parameters, generation of random binary data, and the transformation of this data into different encoding formats. The results are visualized through multiple subplots to compare the different encoding schemes.

Uploaded by

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

1.

Initialization

clc
clear all
close all

• clc: Clears the command window, removing any previous outputs.


• clear all: Clears all variables in the workspace.
• close all: Closes all figure windows.

2. Generate Random Data

disp('Generated Random data is as follows')


data=randi([0,1],1,8); % This will generate a random data of 1's and 0's of length 8.
disp(data); % displays the generated random data

• disp('Generated Random data is as follows'): Displays a message indicating the random data
that is about to be shown.
• randi([0,1],1,8): Generates a random row vector of length 8, with values randomly chosen
between 0 and 1.
• disp(data): Displays the generated random data vector.

3. Set Bit Duration

nbits = 10;
bit_duration=ones(1,nbits); % This decides the duration of each bit

• nbits = 10: Defines the number of bits for the encoding process.
• bit_duration = ones(1, nbits): Creates a vector of length nbits where each element is 1. This
represents a bit duration of 1 for each bit.

4. Check for Even/Odd nbits and Adjust Bit Duration for RZ Encoding

if (mod(nbits,2) == 0)
bit_duration_rz = [ones(1,nbits/2), zeros(1,nbits/2)]; % This decides the duration of each bit
else
bit_duration_rz = [ones(1, floor(nbits/2)), zeros(1, ceil(nbits/2))];
end

• This checks whether nbits is even or odd using mod (nbits, 2).
o If nbits is even, it creates a vector of 1s for half of the duration, followed by 0s for the
other half.
o If nbits is odd, it splits the duration into approximately equal parts (with the floor and
ceiling of half the bits).

5. Generate Manchester Coding Data

data_mach = (data*2)-1;
bit_duration_mach = (bit_duration_rz*2)-1;

• data_mach = (data*2)-1: Converts the data vector (which contains 0s and 1s) into -1 and 1 by
multiplying by 2 and subtracting 1. This transformation is required for Manchester encoding.
• bit_duration_mach = (bit_duration_rz*2)-1: Similarly transforms the bit duration vector
bit_duration_rz to -1 and 1 for use with Manchester encoding.

6. Generate NRZ Line Codes (Non-Return to Zero)

Unipolar NRZ:

uni_nrz = kron(data,bit_duration); % performs kroneker product and stores in uni_nrz

• kron(data, bit_duration): The Kronecker product is used to repeat each bit in data for the
length of bit_duration. In this case, data is a sequence of 1s and 0s, and bit_duration
determines how long each bit lasts. uni_nrz holds the resulting sequence.

Polar NRZ:

data_p = data*2-1; % first convert the data into 1's and -1's
pol_nrz = kron(data_p, bit_duration);

• data_p = data*2 - 1: Converts the data from 0s and 1s to -1 and 1 for polar encoding.
• pol_nrz = kron(data_p, bit_duration): Performs the Kronecker product to create the polar
NRZ encoding.

7. Generate RZ Line Codes (Return to Zero)

Unipolar RZ:

uni_rz = kron(data, bit_duration_rz); % performs kroneker product and stores in uni_nrz

• kron(data, bit_duration_rz): Creates the unipolar RZ encoding by repeating the data using
bit_duration_rz.

Polar RZ:

data_p = data*2-1; % first convert the data into 1's and -1's
pol_rz = kron(data_p, bit_duration_rz);

• This creates the polar RZ encoding by converting the data to -1 and 1 and then performing the
Kronecker product with bit_duration_rz.
• The Kronecker product is a mathematical operation on two matrices (or vectors),
resulting in a larger matrix (or vector). It’s denoted by the symbol ⊗ and is used to
"expand" or "stretch" the dimensions of data in a particular way.
• In the context of the MATLAB code, the Kronecker product is used to repeat each bit
of the data sequence for a certain duration.

8. Generate Manchester Coding

mach = kron(data_mach, bit_duration_mach);

• kron(data_mach, bit_duration_mach): Creates the Manchester encoding by repeating the data


data_mach (which has been transformed to -1 and 1) with the modified bit_duration_mach.

9. Plotting the Results

subplot(5,1,1) % to display both unipolar and polar once can use subplot
plot(uni_nrz)
axis([0,length(uni_nrz),min(uni_nrz)-1,max(uni_nrz)+1])
title('Unipolar NRZ')

• subplot(5,1,1): This sets the layout of the plot to display 5 subplots (rows x columns) and
selects the first position.
• plot(uni_nrz): Plots the unipolar NRZ line code.
• axis(...): Adjusts the x and y-axis for better visibility.
• title('Unipolar NRZ'): Sets the title for this subplot.

subplot(5,1,2)
plot(pol_nrz)
axis([0,length(pol_nrz),min(pol_nrz)-1,max(pol_nrz)+1])
title('Polar NRZ')

• Similarly, this creates the second subplot for the polar NRZ encoding.

subplot(5,1,3)
plot(uni_rz)
title('Unipolar RZ')
axis([0,length(uni_rz),min(uni_rz)-1,max(uni_rz)+1])

• Plots the unipolar RZ encoding in the third subplot.

subplot(5,1,4)
plot(pol_rz)
title('Polar RZ')
axis([0,length(pol_rz),min(pol_rz)-1,max(pol_rz)+1])

• Plots the polar RZ encoding in the fourth subplot.

subplot(5,1,5)
plot(mach)
axis([0,length(mach),min(mach)-1,max(mach)+1])
title('Manchester coding')

• Plots the Manchester encoding in the fifth subplot.

You might also like