📄 line_code.m
字号:
function varargout = line_code(varargin)
%Data encoding simulation
%Author: Diego Orlando Barrag醤 Guerrero
%diegokillemall@yahoo.com
%PRIVATE TECHNICAL UNIVERSITY OF LOJA (ECUADOR)
%Long Live Judas Priest
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @line_code_OpeningFcn, ...
'gui_OutputFcn', @line_code_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before line_code is made visible.
function line_code_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to line_code (see VARARGIN)
hold off;
h=[1 1 0 1 0 0 1 1 0 1];
n=1;
h(11)=1;
while n<=10;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
d=plot(t,y);title('Codificaci髇 UNIPOLAR NRZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
else
if h(n+1)==0
y=(t<n)-0*(t==n);
else
y=(t<n)+1*(t==n);
end
d=plot(t,y);title('Code UNIPOLAR NRZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
% Choose default command line output for line_code
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes line_code wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = line_code_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in random.
function random_Callback(hObject, eventdata, handles)
% hObject handle to random (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=round(rand(1,1));
b=round(rand(1,1));
c=round(rand(1,1));
d=round(rand(1,1));
e=round(rand(1,1));
f=round(rand(1,1));
g=round(rand(1,1));
h=round(rand(1,1));
i0=round(rand(1,1));
j0=round(rand(1,1));
ran=[a,b,c,d,e,f,g,h,i0,j0];
set(handles.uno,'String',ran(1));
set(handles.dos,'String',ran(2));
set(handles.tres,'String',ran(3));
set(handles.cuatro,'String',ran(4));
set(handles.cinco,'String',ran(5));
set(handles.seis,'String',ran(6));
set(handles.siete,'String',ran(7));
set(handles.ocho,'String',ran(8));
set(handles.nueve,'String',ran(9));
set(handles.diez,'String',ran(10));
%-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
handles.bits=[a,b,c,d,e,f,g,h,i0,j0];
cod=get(handles.select_code,'Value');
switch cod
case 1
hold off;
h=handles.bits;
n=1;
h(11)=1;
while n<=10;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
d=plot(t,y);title('Code UNIPOLAR NRZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
else
if h(n+1)==0
y=(t<n)-0*(t==n);
else
y=(t<n)+1*(t==n);
end
d=plot(t,y);title('Code UNIPOLAR NRZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
case 2
hold off;
h =handles.bits;
n=1;
h(11)=1;
while n<=10;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=-(t<n)-(t==n);
else
y=-(t<n)+(t==n);
end
d=plot(t,y);title('Code POLAR NRZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
else
if h(n+1)==0
y=(t<n)-1*(t==n);
else
y=(t<n)+1*(t==n);
end
d=plot(t,y);title('Code POLAR NRZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
case 3
hold off;
h =handles.bits;
n=1;
h(11)=1;
while n<=10;
t=n-1:0.001:n;
%Graficaci髇 de los CEROS (0)
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
d=plot(t,y);title('Code UNIPOLAR RZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
%Graficaci髇 de los UNOS (1)
else
if h(n+1)==0
y=(t<n-0.5);
else
y=(t<n-0.5)+1*(t==n);
end
d=plot(t,y);title('Code UNIPOLAR RZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
case 4
hold off;
h =handles.bits;
n=1;
h(11)=1;
while n<=10;
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);title('Code BIPOLAR RZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
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);title('Code BIPOLAR RZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
case 5
hold off;
h =handles.bits;
n=1;
h(11)=1;
ami=-1;
while n<=10;
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
d=plot(t,y);title('Code AMI NRZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
else
ami=ami*-1;
if h(n+1)==0
if ami==1
y=(t<n);
else
y=-(t<n);
end
else
if ami==1
y=(t<n)-(t==n);
else
y=-(t<n)+(t==n);
end
end
d=plot(t,y);title('Code AMI NRZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
case 6
hold off;
h =handles.bits;
n=1;
h(11)=1;
ami=-1;
while n<=10;
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
d=plot(t,y);title('Code AMI RZ');grid on
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
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
d=plot(t,y);title('Code AMI RZ');grid on;
set(d,'LineWidth',2.5);
hold on;
axis([0 10 -1.5 1.5]);
end
n=n+1;
end
case 7
hold off;
h =handles.bits;
h=~h;
n=1;
h(11)=1;
while n<=10;
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);title('Code MANCHESTER NRZ');grid on
set(d,'LineWidth',2.5);
hold on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -