0% found this document useful (0 votes)
47 views9 pages

Listing Program NRZ-L

The document contains MATLAB code for generating and plotting various line coding schemes including NRZ-L, NRZ-M, NRZ-S, RZ-AMI, Unipolar RZ, Bipolar RZ, BiPhase-M, and BiPhase-L. For each scheme, the code generates a random binary data signal, encodes it using the specified line coding technique, takes the FFT to calculate the spectrum, and plots the original data signal, encoded signal, and signal spectrum in a 3 subplot figure. The code then labels each figure with the name of the line coding technique plotted.
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)
47 views9 pages

Listing Program NRZ-L

The document contains MATLAB code for generating and plotting various line coding schemes including NRZ-L, NRZ-M, NRZ-S, RZ-AMI, Unipolar RZ, Bipolar RZ, BiPhase-M, and BiPhase-L. For each scheme, the code generates a random binary data signal, encodes it using the specified line coding technique, takes the FFT to calculate the spectrum, and plots the original data signal, encoded signal, and signal spectrum in a 3 subplot figure. The code then labels each figure with the name of the line coding technique plotted.
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/ 9

LISTING PROGRAM NRZ-L

jmlbit=100;
x=randint(1,jmlbit,[0 1], 0);
%Sinyal NRZ-L
subplot(3,1,1);
stairs(x);
axis([1 length(x) -1 2]);
title 'Sinyal Informasi';
y=2*x-1;
subplot(3,1,2);
stairs(y);
axis([1 length(x) -2 2]);
title 'Sinyal NRZ-L';
s=fft(x,2048);
f=0:2048-1;
subplot(3,1,3);
plot(f,20*log10(abs(s)));
title 'Spektrum NRZ-L'
HASIL PLOT SINYAL INFORMASI, SINYAL NRZ-L & SPEKTRUM NRZ-L

LISTING PROGRAM NRZ-M


jmlbit=100;
x=randint(1,jmlbit,[0 1], 0);

%NRZ-M
figure(5)
subplot(3,1,1);
stairs(x);
axis([1 length(x) -1 2]);
title 'Sinyal Informasi';
for n=1:length(x)
if (n==1)
data_out=x(n);
data1(n)=x(n);
else
if (x(n)==0)
data1(n)=data_out;
elseif (x(n)==1)
if (data_out==0)
data_out=1;
else
data_out=0;
end
data1(n)=data_out;
end
end
end
datafix=2*data1-1;
subplot(3,1,2)
stairs(datafix)
axis([1 length(x) -2 2])
title 'Sinyal NRZ-M'
s=fft(datafix,2048);
f=0:2047;
subplot(3,1,3);
plot(f,20*log10(abs(s)))
title 'Spektrum NRZ-M';

HASIL PLOT SINYAL INFORMASI, SINYAL NRZ-M & SPEKTRUM NRZ-M

LISTING PROGRAM NRZ-S


% NRZ-S
figure(6)
subplot(3,1,1)
stairs(x)
axis([0 length(x) -1 2])
title 'Sinyal Informasi';
for n=1:length(x)
if (n==1)
data_out=x(n);
data1(n)=x(n)-1;
else
if (x(n)==1)
data1(n)=data1(n-1);
elseif (x(n)==0)
if (data1(n-1)==1)
data_out=0;
else
data_out=1;
end
data1(n)=data_out;
end
end
end
datafix=2*data1-1;
subplot(3,1,2)
stairs(datafix)
axis([1 length(x) -2 2])
title 'Sinyal NRZ-S'
s=fft(datafix,2048);
f=0:2047;
subplot(3,1,3);

plot(f,20*log10(abs(s)))
title 'Spektrum NRZ-S';
HASIL PLOT SINYAL INFORMASI, SINYAL NRZ-S & SPEKTRUM NRZ-S

LISTING PROGRAM RZ-AMI


%AMI-RZ
figure(2)
subplot(3,1,1);
stairs(x);
axis([1 length(x) -0.5 1.5]);
title 'Sinyal Informasi';
x(1)=1;
xx=x;
for k=2:length(x);
if x(k-1)==0 && x(k)==1
xx(k)=-1;
end
end
subplot(3,1,2);
stairs(xx);
axis([1 length(x) -1.5 1.5]);
title 'Sinyal AMI-RZ';
s=fft(xx,2048);
f=0:2047;
subplot(3,1,3);
plot(f,20*log10(abs(s)));
title 'Spektrum AMI-RZ'

HASIL PLOT RZ-AMI

LISTING PROGRAM UNIPOLAR RZ


%UNIPOLAR-RZ
figure(3)
subplot(3,1,1);
stairs(x);
axis([1 length(x) -0.5 1.5]);
title 'Sinyal Informasi';
t=0:1/48:100-1/48;
p1=ones(16,1);p2=zeros(32,1);
p=[p1;p2];
y=p*x;
z=reshape(y,1,[]);
subplot(3,1,2);
plot(t,z);
axis([1 length(x) -1.5 1.5]);
title 'Sinyal Unipolar-RZ';
s=fft(z,2048);
f=0:2047;
subplot(3,1,3);
plot(f,20*log10(abs(s)))
title 'Spektrum Unipolar-RZ';

HASIL PLOT SINYAL INFORMASI ,SINYAL UNIPOLAR-RZ & SPEKTRUM UNIPOLARRZ

LISTING PROGRAM BIPOLAR-RZ


% BIPOLAR-RZ
figure(4)
subplot(3,1,1);
stairs(x);
axis([1 length(x) -0.5 1.5]);
title 'Sinyal Informasi';
xx=2*x-1;
t=0:1/48:100-1/48;
p1=ones(16,1); p2=zeros(32,1);
p=[p1;p2];
y=p*xx;
z=reshape(y,1,[]);
subplot(3,1,2)
plot(t,z)
axis([1 length(x) -1.5 1.5]);
title 'Sinyal Bipolar-RZ';
s=fft(z,2048);
f=0:2047;
subplot(3,1,3);
plot(f,20*log10(abs(s)))
title 'Spektrum Bipolar-RZ';

HASIL PLOT SINYAL INFORMASI, SINYAL BIPOLAR-RZ & SINYAL SPEKTRUM


BIPOLAR-RZ

LISTING PROGRAM BIPHASE-M


% Bi-Phase M
figure(8)
subplot(3,1,1)
stairs(x)
axis([0 length(x) -0.5 1.5])
title 'Sinyal Informasi';
bitrate = 1;
T = length(x)/bitrate; % full time of bit sequence
k = 200;
N = k*length(x);
dt = T/N;
t = 0:dt:T;
y = zeros(1,length(t)); % output signal
for n = 0:length(x)-1
if n==1
y(n*k+1:(n+0.5)*k) = -1;
y((n+0.5)*k+1:(n+1)*k) = 1;
data=y;
else
if (x(n+1)==1)
if y(((n-1)+0.5)*k+1:((n)-1)*k)==1
y(n*k+1:(n+0.5)*k) = 1;
y((n+0.5)*k+1:(n+1)*k) = 1;
else
y(n*k+1:(n+0.5)*k) = -1;
y((n+0.5)*k+1:(n+1)*k) = -1;
end
data=y;
elseif (x(n+1)==0)

if y(((n-1)+0.5)*k+1:((n)-1)*k)==1
y(n*k+1:(n+0.5)*k) = 1;
y((n+0.5)*k+1:(n+1)*k) = -1;
else
y(n*k+1:(n+0.5)*k) = -1;
y((n+0.5)*k+1:(n+1)*k) = 1;
end
data=y;
end
end
end
subplot(3,1,2)
plot(t,data)
axis([1 length(x) -1.5 1.5])
title 'Sinyal BiPhase M'
s=fft(data,2048);
f=0:2047;
subplot(3,1,3);
plot(f,20*log10(abs(s)))
title 'Spektrum BiPhase M';
HASIL PLOT SINYAL INFORMASI , SINYAL BIPHASE-M & SPEKTRUM BIPHASE-M

LISTING PROGRAM BIPHASE L


% Bi-Phase L
figure(7)
subplot(3,1,1)
stairs(x)
axis([0 length(x) -0.5 1.5])
title 'Sinyal Informasi';
bitrate = 1;

T = length(x)/bitrate; % full time of bit sequence


k = 200;
N = k*length(x);
dt = T/N;
t = 0:dt:T;
y = zeros(1,length(t)); % output signal
for n = 0:length(x)-1
if (x(n+1)==1)
y(n*k+1:(n+0.5)*k) = -1;
y((n+0.5)*k+1:(n+1)*k) = 1;
data=y;
elseif (x(n+1)==0)
y(n*k+1:(n+0.5)*k) = 1;
y((n+0.5)*k+1:(n+1)*k) = -1;
data=y;
end
end
subplot(3,1,2)
plot(t,data)
axis([1 length(x) -1.5 1.5])
title 'Sinyal BiPhase L'
s=fft(data,2048);
f=0:2047;
subplot(3,1,3);
plot(f,20*log10(abs(s)))
title 'Spektrum BiPhase L';
HASIL PLOT SINYAL INFORMASI, SINYAL BIPHASE-L & SPEKTRUM BIPHASE-L

You might also like