Вы находитесь на странице: 1из 11

III.

SIMULACION EN MATLAB DE LOS DIFERENTES CODIGOS

CODIGO NRZu (SIN RETORNO A CERO – UNIPOLAR)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CÓDIGO DE LÍNEA UNIPOLAR NRZ%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function UNRZ(h)
close all;
a = 10;
tb = 100;
n=1;
h=[0 0 0 1 0 1 0 0 0 1];%SEÑAL 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');
%--------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%AUTOCORRELACIÓN 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('FUNCIÓN DE AUTOCORRELACIÓN UNIPOLAR NRZ');
%--------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CONSTELACIÓN 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('CONSTELACIÓN DE UNIPOLAR NRZ')
grid on;

Resultados
CODIGO RZu (CON RETORNO A CERO – UNIPOLAR)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CÓDIGO DE LÍNEA 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];%SEÑAL 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');

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CONSTELACIÓN 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('Constelación del Código de Linea RZ')
grid on;

%----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%FUNCIÓN DE AUTOCORREACIÓN 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('AUTOCORRELACIÓN DEL UNIPOLAR RZ');

Resultados

CODIGO NRZb (SIN RETORNO A CERO – BIPOLAR)

%%%%%%%%%%%%%%%%%%%%%%
%% CÓDIGO 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

Resultados
CODIGO AMI RZ (ALTERNATE MARK INVERSION)

%%%%%%%%%%%%%%%%%%%%%%
%%CÓDIGO 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];%Señal 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('CÓDIGO 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('CÓDIGO 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

%-------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%FUNCIÓN DE AUTOCORRELACIÓN 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('AUTOCORRELACIÓN 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')

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CONSTELACIÓN 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 Código de Linea AMI RZ')
grid on
Resultados

CODIGO MANCHESTER

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%CÓDIGO DE LÍNEA 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
%-------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%FUNCIÓN DE AUTOCORRELACIÓN 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('AUTOCORRELACIÓN DE MANCHESTER')
Resultados

Вам также может понравиться