Experiment No: 06: Roll No:07 Group No:04 PROGRAM: To Generate Line Codes and Plot Their PSD
Experiment No: 06: Roll No:07 Group No:04 PROGRAM: To Generate Line Codes and Plot Their PSD
GROUP NO:04
EXPERIMENT NO: 06
PROGRAM: To generate Line Codes and plot their psd.
clc;
clear all;
close all;
Nb=input('enter no of bits to be transmitted');
b=input('data to be coded:');
NRZ_out=[];
RZ_out=[];
Manchester_out=[];
Bipolar_out=[];
j=1; Vp=5; %Vp is the peak voltage +v of the waveform
fs=60;
%NRZ polar code
for i=1:length(b)
if b(i)==1
NRZ_out =[NRZ_out [1 1 1 1 1 1]*(Vp)];
elseif b(i)==0
NRZ_out =[NRZ_out [-1 -1 -1 -1 -1 -1]*(Vp)];
end
end
%RZ unipolar code
for i=1:length(b)
if b(i)==1
RZ_out=[RZ_out [1 1 1 0 0 0]*Vp];
elseif b(i)==0
RZ_out=[RZ_out [0 0 0 0 0 0]*(Vp)];
end
end
% Manchester code
for i=1:length(b)
if b(i)==1
Manchester_out=[Manchester_out [1 1 1 -1 -1 -1]*Vp];
elseif b(i)==0
Manchester_out=[Manchester_out [-1 -1 -1 1 1 1]*(Vp)];
end
end
% Bipolar code
for i=1:length(b)
if b(i)==1
if rem(j,2)==0
Bipolar_out=[Bipolar_out [-1 -1 -1 0 0 0]*Vp];
j=j+1;
else
Bipolar_out=[Bipolar_out [1 1 1 0 0 0]*Vp];
j=j+1;
end
else
Bipolar_out=[Bipolar_out [0 0 0 0 0 0]*Vp];
end
end
%Plots of line codes
figure(1),stem((1:Nb*6)/6,NRZ_out);
hold on
xlabel('bits');
ylabel('NRZ polar code');
figure(2),stem((1:Nb*6)/6,RZ_out);
xlabel('bits');
ylabel('RZ Unipolar code');
hold on
figure(3),stem((1:Nb*6)/6,Manchester_out);
hold on
xlabel('bits');
ylabel('Manchester code');
figure(4),stem((1:Nb*6)/6,Bipolar_out);
xlabel('bits');
ylabel('bipolar code');
%autocorreletion function
[ACF_1,lags_1,bounds]=autocorr(NRZ_out,47,0,[]);
[ACF_2,lags_2,bounds]=autocorr(RZ_out,47,0,[]);
[ACF_3,lags_3,bounds]=autocorr(Bipolar_out,47,0,[]);
[ACF_4,lags_4,bounds]=autocorr(Manchester_out,47,0,[]);
figure(6); plot(lags_1,ACF_1);hold on;stem(lags_1,ACF_1);
xlabel('lags');
ylabel('autocorrelation of NRZ polar');
[Pxx_1,w_1] = pwelch(Manchester_out);
figure(5),a=plot(w_1,Pxx_1);
set(a,'color',[1 0 1],'LineWidth',2.0); %Magenta color
[Pxx_2,w_2] = pwelch(NRZ_out);
hold on;
figure(5), y=plot(w_2,Pxx_2);
set(y,'color',[1 0 0],'LineWidth',2.0); %red
[Pxx_3,w_3] = pwelch(RZ_out);
hold on;
figure(5), z=plot(w_3,Pxx_3);
set(z,'color',[0 1 0],'LineWidth',2.0); %green
[Pxx_4,w_4] = pwelch(Bipolar_out);
hold on;
figure(5), c=plot(w_4,Pxx_4);
set(c,'color',[0 0 1],'LineWidth',2.0); %blue
OBSERVATIONS:
2
NRZ polar code
-1
-2
-3
-4
-5
0 1 2 3 4 5 6 7 8
bits
5
4.5
3.5
RZ Unipolar code
2.5
1.5
0.5
0
0 1 2 3 4 5 6 7 8
bits
2
Manchester code
-1
-2
-3
-4
-5
0 1 2 3 4 5 6 7 8
bits
1
bipolar code
-1
-2
-3
-4
-5
0 1 2 3 4 5 6 7 8
bits
1
0.8
0.6
autocorrelation of NRZ polar
0.4
0.2
-0.2
-0.4
-0.6
0 5 10 15 20 25 30 35 40 45 50
lags
1
autocorrelation of RZ unipolar
0.5
-0.5
0 5 10 15 20 25 30 35 40 45 50
lags
0.8
0.6
autocorrelation of Bipolar
0.4
0.2
-0.2
-0.4
-0.6
-0.8
0 5 10 15 20 25 30 35 40 45 50
lags
1
0.8
0.6
autocorrelation of Manchester
0.4
0.2
-0.2
-0.4
-0.6
0 5 10 15 20 25 30 35 40 45 50
lags
35 NRZ Polar
RZ unipolar
30
Manchester
Bipolar
25
PSD
20
15
10
0
0 0.5 1 1.5 2 2.5 3 3.5
normalized frequency