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

Experiment No: 06: Roll No:07 Group No:04 PROGRAM: To Generate Line Codes and Plot Their PSD

The document describes an experiment to generate and plot different line codes including NRZ polar, RZ unipolar, Manchester, and bipolar codes. It generates the coded output for a sample data string, plots the time-domain waveforms and autocorrelation functions of each code, and calculates the power spectral density to compare the codes.

Uploaded by

shakil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Experiment No: 06: Roll No:07 Group No:04 PROGRAM: To Generate Line Codes and Plot Their PSD

The document describes an experiment to generate and plot different line codes including NRZ polar, RZ unipolar, Manchester, and bipolar codes. It generates the coded output for a sample data string, plots the time-domain waveforms and autocorrelation functions of each code, and calculates the power spectral density to compare the codes.

Uploaded by

shakil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ROLL NO:07

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');

hold on; figure(7);plot(lags_2,ACF_2);hold on;stem(lags_2,ACF_2);


xlabel('lags');
ylabel('autocorrelation of RZ unipolar');
hold on; figure(8);plot(lags_3,ACF_3);hold on;stem(lags_3,ACF_3);
xlabel('lags');
ylabel('autocorrelation of Bipolar');
hold on; figure(9);plot(lags_4,ACF_4);hold on;stem(lags_4,ACF_4);
xlabel('lags');
ylabel('autocorrelation of Manchester');

[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:

enter no of bits to be transmitted:8


data to be coded:[0 1 1 1 0 0 1 1]

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

PSD of different codes


40

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

You might also like