Line Coding
Line Coding
%Mark
M(1)=1;
for k=1:n;
M(k+1)=xor(M(k), a(k));
end
%Space
S(1)=1;
for k=1:n
S(k+1)=not(xor(S(k), a(k)));
end
%Plotting Waves
subplot(5, 1, 1); bpuls(U)
axis([1 n+2 -2 2])
title('Unipolar NRZ')
grid on
subplot(5, 1, 2); bpuls(P)
axis([1 n+2 -2 2])
title('Polar NRZ')
grid on
subplot(5, 1, 3); bpuls(B)
axis([1 n+2 -2 2])
title('Bipolar NRZ')
grid on
subplot(5, 1, 4); bpuls(M)
axis([1 n+2 -2 2])
title('NRZ-Mark')
grid on
subplot(5, 1, 5); bpuls(S)
axis([1 n+2 -2 2])
title('NRZ-Space')
grid on
%unipolar
yu=fft(U, 512);
pu=yu.*conj(yu)/512;
%polar
yp=fft(P, 512);
pp=yp.*conj(yp)/512;
%bipolar
yb=fft(B, 512);
pb=yb.*conj(yb)/512;
%Mark
ym=fft(M, 512);
pm=ym.*conj(ym)/512;
%Space
ys=fft(S, 512);
ps=ys.*conj(ys)/512;
legend('Unipolar','Polar','Bipoalr','Mark','Space')
hold off
size(f)
function bpuls(a)
n=length(a);
b=a;
b(n+1)=b(n); %retaining last value for entire last duration
stairs(b,'linewidth',2)
axis([1 length(b) min(b)-0.5 max(b)+0.5])