codificacion en matlab

13
CODIGO UNRZ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%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 %--------------------------------------------------------

Upload: jorge-mariano-mamani-soria

Post on 31-Dec-2015

49 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Codificacion en Matlab

CODIGO UNRZ

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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 ELEGIDAL=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 MUESTROf=[-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;

Page 2: Codificacion en Matlab

subplot(2,2,2)plot(f,g,'m','LineWidth',2)grid ontitle('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 ontitle('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 URZ

Page 3: Codificacion en Matlab

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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 ELEGIDAl=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 CAMBIAMOSfsup=4/tb;f=[-fsup:fsup/1000:fsup];indice=1;n=length(f);while(f(indice)<fsup) if(f(indice)==-3)

Page 4: Codificacion en Matlab

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; endendg=a^2*(tb/16)*(sinc(f*(tb/2))).^2+ y;subplot(2,2,2);plot(f,g,'r','LineWidth',2)grid ontitle('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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Page 5: Codificacion en Matlab

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 ontitle('AUTOCORRELACIÓN DEL UNIPOLAR RZ');

Resultados

CODIGO BNRZ

%%%%%%%%%%%%%%%%%%%%%%%% 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

Page 6: Codificacion en Matlab

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');endn=n+1;end

CODIGO AMI RZ

%%%%%%%%%%%%%%%%%%%%%%

Page 7: Codificacion en Matlab

%%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;

Page 8: Codificacion en Matlab

end %-------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FUNCIÓN DE AUTOCORRELACIÓN DE AMI RZ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ELIJOa=1;%ELIJOtb=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 ontitle('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 ontitle('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

Page 9: Codificacion en Matlab

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

Page 10: Codificacion en Matlab

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');endn=n+1;end%--------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ESPECTRO DE POTENCIA DE MANCHESTER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%figuretb=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 ontitle('Densidad Espectral de potencia del Codigo Manchester')end%-------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FUNCIÓN DE AUTOCORRELACIÓN MANCHESTER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ELIJOfigurea=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 ontitle('AUTOCORRELACIÓN DE MANCHESTER')

Resultados

Page 11: Codificacion en Matlab