Submitted By:: Muhammad Maab Nawaz FA21-EEE-021
Submitted By:: Muhammad Maab Nawaz FA21-EEE-021
Generation of PCM Line codes and analyzing their Power Spectral Density
using MATLAB
%%All waveforms
HalfMark=ones(1,length(T)/2);
Halfspace=-ones(1,length(T)/2);
stepdownward=[HalfMark Halfspace];
stepupward=[Halfspace HalfMark];
Mark=ones(1,length(T));
Space=-ones(1,length(T));
%Polar Nrz
if strcmp(L1,Type)
for i=1:length(BITS)
if BITS(i)==1
Array=[Array ones(length(T))];
else
Array=[Array -ones(length(T))];
end
end
else
disp('')
end
% Unipolar Nrz
if strcmp(L2,Type)
for i=1:length(BITS)
if BITS(i)==1
Array=[Array ones(length(T))];
else
Array=[Array zeros(length(T))];
end
end
else
disp('')
end
% Unipolar RZ
if strcmp(L3,Type)
for i=1:length(BITS)
if BITS(i)==1
Array=[Array stepdownward];
else
Array=[Array zeros(1,length(T))];
end
end
else
disp('')
end
% Manchester
if strcmp(L4,Type)
for i=1:length(BITS)
if BITS(i)==1
Array=[Array stepdownward];
% y=1;
else
Array=[Array stepupward];
end
end
else
disp('')
end
% DelayModulation
if strcmp(L5,Type)
if BITS(1)==1
Array=[Array stepdownward];
else
Array=[Array Mark];
end
for i=2:length(BITS)
if BITS(i)==1
if Array(end-1)>0
Array=[Array stepdownward];
else
Array=[Array stepupward];
end
% y=1;
else
if BITS(i-1)==1
if Array(end-1)>0
Array=[Array Mark];
else
Array=[Array Space];
end
else
if Array(end-1)>0
Array=[Array Space];
else
Array=[Array Mark];
end
end
end
end
else
disp('')
end
plot(1:length(Array),Array,'bl')
grid on
grid minor
ylim([-2 2])
end
bits=[1 0 1 1 0 0 0 1 1 0 1];
Polar Nrz
UNIPolar Nrz
UNIPolar Rz
Manchester
DelayModulation
For random 30 bits
Polar Nrz
UNIPolar Nrz
UNIPolar Rz
Manchester
DelayModulation
Code#2
This code can also be done without concatenation method:
For Manchester:
clc;
clear all;
signal = [1 0 1 1 0 0 0 1 1 0 1];
fs = 1000;
T = 1/fs;
time = 0:1/fs:1-1/fs;
oness= ones(1, (length(time))/2);
zeross= -ones(1, (length(time))/2);
stepdown=[oness zeross];
stepup=[zeross oness];
% mod = zeros(length(time) .* length(bits));
mod=[];
for i = 1:length(signal)
if signal(i) == 1
mod((i-1)*length(time)+1:i*length(time)) = stepdown;
else
mod((i-1)*length(time)+1:i*length(time)) = stepup;
end
end
plot(mod);
ylim([-2 2])
title('Manchester');
grid on;
grid minor
For UNIpolarRZ:
clc;
clear all;
signal = [1 0 1 1 0 0 0 1 1 0 1];
fs = 1000;
T = 1/fs;
time = 0:1/fs:1-1/fs;
Fullbitzero=zeros(1, (length(time)));
oness= ones(1, (length(time))/2);
zeross= zeros(1, (length(time))/2);
stepdown=[oness zeross];
% mod = zeros(length(time) .* length(bits));
mod=[];
for i = 1:length(signal)
if signal(i) == 1
mod((i-1)*length(time)+1:i*length(time)) = stepdown;
else
mod((i-1)*length(time)+1:i*length(time)) = Fullbitzero;
end
end
plot(mod,linewidth=3);
ylim([-2 2])
title('unipolarRZ');
grid on;
grid minor
For UNIpolarNRZ:
clc;
clear all;
signal = [1 0 1 1 0 0 0 1 1 0 1];
fs = 1000;
T = 1/fs;
time = 0:1/fs:1-1/fs;
Fullbitzero=zeros(1, (length(time)));
Fullbitone=ones(1, (length(time)));
mod=[];
for i = 1:length(signal)
if signal(i) == 1
mod((i-1)*length(time)+1:i*length(time)) = Fullbitone;
else
mod((i-1)*length(time)+1:i*length(time)) = Fullbitzero;
end
end
plot(mod,linewidth=3);
ylim([-2 2])
title('unipolarNRZ');
grid on;
grid minor
For polarNRZ:
clc;
clear all;
signal = [1 0 1 1 0 0 0 1 1 0 1];
fs = 1000;
T = 1/fs;
time = 0:1/fs:1-1/fs;
Fullbitspace=-ones(1, (length(time)));
Fullbitone=ones(1, (length(time)));
mod=[];
for i = 1:length(signal)
if signal(i) == 1
mod((i-1)*length(time)+1:i*length(time)) = Fullbitone;
else
mod((i-1)*length(time)+1:i*length(time)) = Fullbitspace;
end
end
plot(mod,linewidth=3);
ylim([-2 2])
title('polarNRZ');
grid on;
grid minor
Conclusion
In this lab I learned about line codes and their role in digital communication. I
learned how these codes represent binary data as electrical signals, ensuring
reliable transmission. Furthermore, I explored the power spectral densities of
various line codes, allowing me to compare their frequency content and understand
their spectral characteristics. By implementing algorithms in MATLAB, I gained
practical experience coding Unipolar NRZ, Bipolar NRZ, Manchester, and Differential
Manchester line codes, solidifying my understanding of their workings. Overall, this
lab was an understanding Line codes and their implementation.