0% found this document useful (0 votes)
96 views11 pages

Codificacion en Matlab

The document describes code for several line coding schemes including unipolar NRZ, unipolar RZ, bipolar RZ, AMI RZ, and Manchester coding. It provides MATLAB functions to generate signals for each coding scheme using a sample input signal. It also includes plots of signal waveforms, power spectral densities, autocorrelation functions, and constellations for each line coding scheme.

Uploaded by

Jorge Jmms
Copyright
© Attribution Non-Commercial (BY-NC)
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)
96 views11 pages

Codificacion en Matlab

The document describes code for several line coding schemes including unipolar NRZ, unipolar RZ, bipolar RZ, AMI RZ, and Manchester coding. It provides MATLAB functions to generate signals for each coding scheme using a sample input signal. It also includes plots of signal waveforms, power spectral densities, autocorrelation functions, and constellations for each line coding scheme.

Uploaded by

Jorge Jmms
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 11

CODIGO UNRZ

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CDIGO DE LNEA UNIPOLAR NRZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UNRZ(h)
close all;
a = 10;
tb = 100;
n=1;
h=[0 0 0 1 0 1 0 0 0 1];%SEAL DE ENTRADA ELEGIDA
L=length(h);
h(L+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
subplot(2,2,1);
d=plot(t,y);grid on;
title('Codigo de Linea UNIPOLAR NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('zero');
else
if h(n+1)==0
y=(t<n)-0*(t==n);
else
y=(t<n)+1*(t==n);
end
subplot(2,2,1);
d=plot(t,y);grid on;
title('Codigo de Linea UNIPOLAR NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -0.5 1.5]);
disp('one');
end
n=n+1;
end
%-------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%ESPECTRO DE POTENCIA DE UNIPOLAR NRZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
%ELIJO:
tb=200;
fsup=2/tb;%POR LA FRECUENCIA DE MUESTRO
f=[-fsup:fsup/1000:fsup];
di=[zeros(1,length(f)/2) 1 zeros(1,length(f)/2)];

g=(a^2*tb*(sinc(f*tb)).^2)+(a^2)*di/4;
subplot(2,2,2)
plot(f,g,'m','LineWidth',2)
grid on
title('ESPECTRO DE POTENCIA DE UNIPOLAR NRZ');
%-------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%AUTOCORRELACIN DE UNIPOLAR NRZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
tb=1;
tau=[-2*tb -tb 0 tb 2*tb];
rt=[a^2/4 a^2/4 a^2/2 a^2/4 a^2/4];
subplot(2,2,3);
plot(tau,rt,'m','LineWidth',3)
grid on
title('FUNCIN DE AUTOCORRELACIN UNIPOLAR NRZ');
%-------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CONSTELACIN DE UNIPOLAR NRZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
tb=1;
u=[0 a*(tb)^(1/2)];
p=[0 0];
subplot(2,2,4);
plot(u,p,'o','LineWidth',10)
title('CONSTELACIN DE UNIPOLAR NRZ')
grid on;

Resultados

CODIGO URZ
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CDIGO DE LNEA UNIPOLAR RZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function unipolar_RZ(h)
close all ;clc;
a=1;
tb=10;
n=1;
h=[0 0 0 1 0 1 0 0 0 1];%SEAL DE ENTRADA ELEGIDA
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
subplot(2,2,1);
d=plot(t,y,'r');
grid on
title('Codigo de Linea UNIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -0.5 1.5]);
disp('zero');
else
if h(n+1)==0
y=(t<n-0.5);
else
y=(t<n-0.5)+1*(t==n);
end
subplot(2,2,1);
d=plot(t,y,'r');
grid on;
title('Codigo de Linea UNIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -0.5 1.5]);
disp('one');
end
n=n+1;
end
%---------------------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%ESPECTRO DE POTENCIA DE UNIPOLAR RZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
tb=200;%LO CAMBIAMOS
fsup=4/tb;
f=[-fsup:fsup/1000:fsup];
indice=1;
n=length(f);

while(f(indice)<fsup)
if(f(indice)==-3)
y(indice)=a^2/(36*pi*pi);
indice=indice+1;
y(n)=1;
end
if(f(indice)==-1)
y(indice)=a^2/(4*pi*pi);
indice=indice+1;
y(n)=1;
end
if(f(indice)==0)
y(indice)=a^2/(pi*pi);
indice=indice+1;
y(n)=1;
end
if(f(indice)==1)
y(indice)=a^2/(4*pi*pi);
indice=indice+1;
y(n)=1;
end
if(f(indice)==3)
y(indice)=a^2/(36*pi*pi);
indice=indice+1;
y(n)=1;
else
y(indice)=0;
indice=indice+1;
y(n)=0;
end
end
g=a^2*(tb/16)*(sinc(f*(tb/2))).^2+ y;
subplot(2,2,2);
plot(f,g,'r','LineWidth',2)
grid on
title('DENSIDAD ESPECTRAL DE POTENCIAL UNIPOLAR NRZ');

%---------------------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CONSTELACIN DE UNIPOLAR RZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
tb=1;
t=[0 a*(tb/4)^(1/2)];
y=[0 0];
subplot(2,2,3);
plot(t,y,'o','LineWidth',10)
axis ([0 a/(2)^(1/2) -1 1])
title('Constelacin del Cdigo de Linea RZ')
grid on;

%----------------------------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%FUNCIN DE AUTOCORREACIN DE UNIPOLAR RZ %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tb=1;
a=1;
tau=[-1.5*tb -tb -0.5*tb 0 0.5*tb tb 1.5*tb];
rt=[0 a^2/4 0 a^2/2 0 a^2/4 0]
subplot(2,2,4);
plot(tau,rt,'r','LineWidth',3)
grid on
title('AUTOCORRELACIN DEL UNIPOLAR RZ');
Resultados

CODIGO BNRZ
%%%%%%%%%%%%%%%%%%%%%%
%%
CDIGO DE BNRZ %%
%%%%%%%%%%%%%%%%%%%%%%
function BRZ(h)
%Ejemplo:
h=[0 0 0 1 0 1 0 0 0 1];
%BRZ(h)
clf;
n=1;
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0

if h(n+1)==0
y=-(t<n-0.5)-(t==n);
else
y=-(t<n-0.5)+(t==n);
end
d=plot(t,y);grid on;
title('Line code BIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('zero');
else
if h(n+1)==0
y=(t<n-0.5)-1*(t==n);
else
y=(t<n-0.5)+1*(t==n);
end
d=plot(t,y);grid on;
title('Line code BIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('one');
end
n=n+1;
end

CODIGO AMI RZ
%%%%%%%%%%%%%%%%%%%%%%
%%CDIGO DEL AMI RZ %%
%%%%%%%%%%%%%%%%%%%%%%
function AMI_RZ(h)
clc;
close all;
a = 1;
tb = 1;
n=1;
h=[0 0 0 1 0 1 0 0 0 1];%Seal de entrada (6 bits dia + 4 bits mes)
l=length(h);
h(l+1)=1;
ami=-1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
if ami==1
y=-(t==n);
else
y=(t==n);
end
end
subplot(2,2,1);
d=plot(t,y,'g');
grid on;
title('CDIGO AMI RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('zero');
else
ami=ami*-1;
if h(n+1)==0
if ami==1
y=(t<n-0.5);
else
y=-(t<n-0.5);
end
else
if ami==1
y=(t<n-0.5)-(t==n);
else
y=-(t<n-0.5)+(t==n);
end
end
subplot(2,2,1);
d=plot(t,y,'r');
grid on;
title('CDIGO AMI RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);

disp('one');
end
n=n+1;
end
%------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%FUNCIN DE AUTOCORRELACIN DE AMI RZ %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ELIJO
a=1;
%ELIJO
tb=100;
tau=[-1.5*tb -tb -0.5*tb 0 0.5*tb tb 1.5*tb];
rt=[0 -a^2/8 0 a^2/4 0 -a^2/8 0];
subplot(2,2,2);
plot(tau,rt,'r','LineWidth',3)
grid on
title('AUTOCORRELACIN DE AMI RZ')
%------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%ESPECTRO DE POTENCIA DE AMI RZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
tb=100;
fsup=6/tb;
f=[-fsup:fsup/1000:fsup];
g=((a.^2).*tb.*((sinc(f.*tb./2)).^2).*((sin(pi*f*tb./2)).^2))./4;
subplot(2,2,3)
plot(f,g,'b','LineWidth',2)
grid on
title('ESPECTRO DE POTENCIA DE AMI RZ')

%-------------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CONSTELACIN DE AMI RZ %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1;
tb=100;
u=[-(a*(tb)^(1/2))/(2^(1/2)) 0 (a*(tb)^(1/2))/(2^(1/2))];
p=[0 0 0];
subplot(2,2,4);
plot(u,p,'O','LineWidth',10)
title('Constelacion Cdigo de Linea AMI RZ')
grid on

Resultados

CODIGO MANCHESTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CDIGO DE LNEA MANCHESTER %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function MANCHESTER(h)
%Example:
h=[0 0 0 1 0 1 0 0 0 1];
%MANCHESTER(h)
clf;
n=1;
h=~h;
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=-(t<n)+2*(t<n-0.5)+1*(t==n);
else
y=-(t<n)+2*(t<n-0.5)-1*(t==n);
end
d=plot(t,y);grid on;
title('Line code MANCHESTER');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('one');
else
if h(n+1)==0
y=(t<n)-2*(t<n-0.5)+1*(t==n);

else
y=(t<n)-2*(t<n-0.5)-1*(t==n);
end
d=plot(t,y);grid on;
title('Line code MANCHESTER');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -1.5 1.5]);
disp('zero');
end
n=n+1;
end
%-------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%ESPECTRO DE POTENCIA DE MANCHESTER %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
tb=1;
nb=6;
a=2;
fsup=4/tb;
f=[-fsup:fsup/1000:fsup];
g=((a.^2/4).*tb.*((sinc(f.*tb./2)).^2).*((sin(pi*f*tb./2)).^2));
plot(f,g,'b','LineWidth',3)
grid on
title('Densidad Espectral de potencia del Codigo Manchester')
end
%------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%FUNCIN DE AUTOCORRELACIN MANCHESTER %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ELIJO
figure
a=2;
nb=6;
tb=1;
tau=[-2*tb -tb 0 tb 2*tb];
rt=[0 -a^2/2 a^2 -a^2/2 0];
plot(tau,rt,'g','LineWidth',3)
grid on
title('AUTOCORRELACIN DE MANCHESTER')

Resultados

You might also like