You are on page 1of 5

TIEMPO: % --- Outputs from this function are returned to the command line.

function varargout = Practica9_Tiempo_OutputFcn(hObject, eventdata,


function varargout = Practica9_Tiempo(varargin) handles)
% PRACTICA9_TIEMPO MATLAB code for Practica9_Tiempo.fig % varargout cell array for returning output args (see VARARGOUT);
% PRACTICA9_TIEMPO, by itself, creates a new PRACTICA9_TIEMPO or % hObject handle to figure
raises the existing % eventdata reserved - to be defined in a future version of MATLAB
% singleton*. % handles structure with handles and user data (see GUIDATA)
%
% H = PRACTICA9_TIEMPO returns the handle to a new % Get default command line output from handles structure
PRACTICA9_TIEMPO or the handle to varargout{1} = handles.output;
% the existing singleton*.
%
% PRACTICA9_TIEMPO('CALLBACK',hObject,eventData,handles,...) calls % --- Executes on selection change in popupmenu1.
the local function popupmenu1_Callback(hObject, eventdata, handles)
% function named CALLBACK in PRACTICA9_TIEMPO.M with the given % hObject handle to popupmenu1 (see GCBO)
input arguments. % eventdata reserved - to be defined in a future version of MATLAB
% % handles structure with handles and user data (see GUIDATA)
% PRACTICA9_TIEMPO('Property','Value',...) creates a new
PRACTICA9_TIEMPO or raises the % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1
% existing singleton*. Starting from the left, property value pairs are contents as cell array
% applied to the GUI before Practica9_Tiempo_OpeningFcn gets called. % contents{get(hObject,'Value')} returns selected item from
An popupmenu1
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to Practica9_Tiempo_OpeningFcn via % --- Executes during object creation, after setting all properties.
varargin. function popupmenu1_CreateFcn(hObject, eventdata, handles)
% % hObject handle to popupmenu1 (see GCBO)
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only % eventdata reserved - to be defined in a future version of MATLAB
one % handles empty - handles not created until after all CreateFcns called
% instance to run (singleton)".
% % Hint: popupmenu controls usually have a white background on
% See also: GUIDE, GUIDATA, GUIHANDLES Windows.
% See ISPC and COMPUTER.
% Edit the above text to modify the response to help Practica9_Tiempo if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
% Last Modified by GUIDE v2.5 09-Jun-2019 18:20:45 set(hObject,'BackgroundColor','white');
end
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ... % --- Executes on button press in pushbutton1.
'gui_Singleton', gui_Singleton, ... function pushbutton1_Callback(hObject, eventdata, handles)
'gui_OpeningFcn', @Practica9_Tiempo_OpeningFcn, ... % hObject handle to pushbutton1 (see GCBO)
'gui_OutputFcn', @Practica9_Tiempo_OutputFcn, ... % eventdata reserved - to be defined in a future version of MATLAB
'gui_LayoutFcn', [] , ... % handles structure with handles and user data (see GUIDATA)
'gui_Callback', []); str = get(handles.popupmenu1, 'String');
if nargin && ischar(varargin{1}) val = get(handles.popupmenu1, 'Value');
gui_State.gui_Callback = str2func(varargin{1});
end caracter = get(handles.edit1, 'String');
Tb = str2num(get(handles.edit2, 'String'));
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); % Señal de reloj
else clkSignal = 0:Tb/2:7*length(caracter)*Tb;
gui_mainfcn(gui_State, varargin{:}); for c=1:2*7*length(caracter)+1
end if mod (c,2) == 0
% End initialization code - DO NOT EDIT clkSignal(c) = 0;
else
clkSignal(c) = 1;
% --- Executes just before Practica9_Tiempo is made visible. end
function Practica9_Tiempo_OpeningFcn(hObject, eventdata, handles, end
varargin) t1 = 0:Tb/2:2*7*length(caracter)*Tb/2;
% This function has no output args, see OutputFcn.
% hObject handle to figure axes(handles.axes1)
% eventdata reserved - to be defined in a future version of MATLAB stairs(t1,clkSignal)
% handles structure with handles and user data (see GUIDATA) title('Señal de reloj')
% varargin command line arguments to Practica9_Tiempo (see
VARARGIN) ylabel('Amplitud [V]')
ylim([-2 2]) %límites de y
% Choose default command line output for Practica9_Tiempo yticks(-2:2) %espaciado de y
handles.output = hObject;
xlabel('Tiempo [ms]')
% Update handles structure xlim([0 7*length(caracter)*Tb]) %límites de x
guidata(hObject, handles); xticks(0:Tb/2:2*7*length(caracter)*Tb) %espaciado de x
grid on
% UIWAIT makes Practica9_Tiempo wait for user response (see
UIRESUME) % Lectura y conversion de caracter
% uiwait(handles.figure1); carTemp = dec2bin(caracter); %conversion de caracter a binario
carBin = reshape(carTemp',[7*length(caracter),1]); %reordenamiento de
vector de caracter en 7*(longitud de caracter)x1
binNum = str2num(carBin)'; %conversion de vector de caracteres en hdb3Signal(c-3) = hdb3Signal(c);
vector de numeros de 1x7*(longitud de caracter) contViolate = hdb3Signal(c);
set(handles.text4, 'String', num2str(binNum)); sig = contViolate;
binNum = [binNum,0]; %se añade un 0 para que el gráfico no quede end
incompleto al final contZeros = 0; %reset de contador de zeros
t2 = 0:Tb:7*length(caracter)*Tb; else
hdb3Signal(c) = 0;
axes(handles.axes2) end
stairs(t2,binNum) end
title('Señal de caracter') end
t3 = 0:Tb:7*length(caracter)*Tb;
ylabel('Amplitud [V]')
ylim([-2 2]) axes(handles.axes3)
yticks(-2:2) stairs(t3,hdb3Signal)
title('Señal codificada con HDB3')
xlabel('Tiempo [ms]')
xlim([0 7*length(caracter)*Tb]) ylabel('Amplitud [V]')
xticks(0:Tb:7*length(caracter)*Tb) ylim([-2 2]) %límites de y
grid on yticks(-2:2) %espaciado de y

switch str{val} xlabel('Tiempo [ms]')


case 'AMI' xlim([0 7*length(caracter)*Tb])
set(handles.text13, 'String', 1/Tb); %Ancho de banda xticks(0:Tb:7*length(caracter)*Tb)
set(handles.text14, 'String', 1/Tb); %Velocidad de transmisión grid on
set(handles.text15, 'String', 1/Tb); %Velocidad de codificación
end
% Caracter codificado con AMI
amiSignal = 0:Tb:7*length(caracter)*Tb;
sig = -1; %signo inicial function edit1_Callback(hObject, eventdata, handles)
for c = 1:7*length(caracter) % hObject handle to edit1 (see GCBO)
if binNum(c) == 1 && sig == -1; % eventdata reserved - to be defined in a future version of MATLAB
amiSignal(c) = 1; % handles structure with handles and user data (see GUIDATA)
sig = 1; %se asigna positivo
elseif binNum(c) == 1 && sig == 1; % Hints: get(hObject,'String') returns contents of edit1 as text
amiSignal(c) = -1; % str2double(get(hObject,'String')) returns contents of edit1 as a
sig = -1; %se asigna negativo double
else
amiSignal(c) = 0; %se mantiene el nivel % --- Executes during object creation, after setting all properties.
end function edit1_CreateFcn(hObject, eventdata, handles)
end % hObject handle to edit1 (see GCBO)
t3 = 0:Tb:7*length(caracter)*Tb; % eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
axes(handles.axes3)
stairs(t3,amiSignal) % Hint: edit controls usually have a white background on Windows.
title('Señal codificada con AMI') % See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
ylabel('Amplitud [V]') get(0,'defaultUicontrolBackgroundColor'))
ylim([-2 2]) %límites de y set(hObject,'BackgroundColor','white');
yticks(-2:2) %espaciado de y end

xlabel('Tiempo [ms]') function edit2_Callback(hObject, eventdata, handles)


xlim([0 7*length(caracter)*Tb]) % hObject handle to edit2 (see GCBO)
xticks(0:Tb:7*length(caracter)*Tb) % eventdata reserved - to be defined in a future version of MATLAB
grid on % handles structure with handles and user data (see GUIDATA)

case 'HDB3' % Hints: get(hObject,'String') returns contents of edit2 as text


% Caracter codificado con HDB3 % str2double(get(hObject,'String')) returns contents of edit2 as a
hdb3Signal = 0:Tb:7*length(caracter)*Tb; double
sig = -1; %signo inicial
contZeros = 0;
contViolate = 0; % --- Executes during object creation, after setting all properties.
for c = 1:7*length(caracter) function edit2_CreateFcn(hObject, eventdata, handles)
if binNum(c) == 1 && sig == -1; % hObject handle to edit2 (see GCBO)
contZeros = 0; %reset de contador de zeros % eventdata reserved - to be defined in a future version of MATLAB
hdb3Signal(c) = 1; % handles empty - handles not created until after all CreateFcns called
sig = 1; %se asigna positivo
elseif binNum(c) == 1 && sig == 1; % Hint: edit controls usually have a white background on Windows.
contZeros = 0; %reset de contador de zeros % See ISPC and COMPUTER.
hdb3Signal(c) = -1; if ispc && isequal(get(hObject,'BackgroundColor'),
sig = -1; %se asigna negativo get(0,'defaultUicontrolBackgroundColor'))
else set(hObject,'BackgroundColor','white');
contZeros = contZeros + 1; %Cuenta ceros consecutivos end
if contZeros == 4
if contViolate == 0 || contViolate ~= sig
hdb3Signal(c) = sig;
contViolate = sig;
elseif contViolate == sig TIEMPO
hdb3Signal(c) = -contViolate;
AMI
% Last Modified by GUIDE v2.5 09-Jun-2019 18:24:23

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Practica9_Frecuencia_OpeningFcn, ...
'gui_OutputFcn', @Practica9_Frecuencia_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
HDB3

% --- Executes just before Practica9_Frecuencia is made visible.


function Practica9_Frecuencia_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 Practica9_Frecuencia (see
VARARGIN)

% Choose default command line output for Practica9_Frecuencia


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Practica9_Frecuencia wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

FRECUENCIA % --- Outputs from this function are returned to the command line.
function varargout = Practica9_Frecuencia_OutputFcn(hObject, eventdata,
function varargout = Practica9_Frecuencia(varargin) handles)
% PRACTICA9_FRECUENCIA MATLAB code for Practica9_Frecuencia.fig % varargout cell array for returning output args (see VARARGOUT);
% PRACTICA9_FRECUENCIA, by itself, creates a new % hObject handle to figure
PRACTICA9_FRECUENCIA or raises the existing % eventdata reserved - to be defined in a future version of MATLAB
% singleton*. % handles structure with handles and user data (see GUIDATA)
%
% H = PRACTICA9_FRECUENCIA returns the handle to a new % Get default command line output from handles structure
PRACTICA9_FRECUENCIA or the handle to varargout{1} = handles.output;
% the existing singleton*.
%
% PRACTICA9_FRECUENCIA('CALLBACK',hObject,eventData,handles,...) % --- Executes on selection change in popupmenu1.
calls the local function popupmenu1_Callback(hObject, eventdata, handles)
% function named CALLBACK in PRACTICA9_FRECUENCIA.M with the % hObject handle to popupmenu1 (see GCBO)
given input arguments. % eventdata reserved - to be defined in a future version of MATLAB
% % handles structure with handles and user data (see GUIDATA)
% PRACTICA9_FRECUENCIA('Property','Value',...) creates a new
PRACTICA9_FRECUENCIA or raises the % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1
% existing singleton*. Starting from the left, property value pairs are contents as cell array
% applied to the GUI before Practica9_Frecuencia_OpeningFcn gets % contents{get(hObject,'Value')} returns selected item from
called. An popupmenu1
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to Practica9_Frecuencia_OpeningFcn via % --- Executes during object creation, after setting all properties.
varargin. function popupmenu1_CreateFcn(hObject, eventdata, handles)
% % hObject handle to popupmenu1 (see GCBO)
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only % eventdata reserved - to be defined in a future version of MATLAB
one % handles empty - handles not created until after all CreateFcns called
% instance to run (singleton)".
% % Hint: popupmenu controls usually have a white background on
% See also: GUIDE, GUIDATA, GUIHANDLES Windows.
% See ISPC and COMPUTER.
% Edit the above text to modify the response to help Practica9_Frecuencia if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white'); hold on
end plot(f2,abs(spectrum2))
hold off

% --- Executes on button press in pushbutton1. case 'HDB3'


function pushbutton1_Callback(hObject, eventdata, handles) % Caracter codificado con HDB3
% hObject handle to pushbutton1 (see GCBO) hdb3Signal = 0:Tb:7*length(caracter)*Tb;
% eventdata reserved - to be defined in a future version of MATLAB sig = -1; %signo inicial
% handles structure with handles and user data (see GUIDATA) contZeros = 0;
str = get(handles.popupmenu1, 'String'); contViolate = 0;
val = get(handles.popupmenu1, 'Value'); for c = 1:7*length(caracter)
if binNum(c) == 1 && sig == -1;
caracter = get(handles.edit1, 'String'); contZeros = 0; %reset de contador de zeros
Tb = str2num(get(handles.edit2, 'String')); hdb3Signal(c) = 1;
sig = 1; %se asigna positivo
elseif binNum(c) == 1 && sig == 1;
% Lectura y conversion de caracter contZeros = 0; %reset de contador de zeros
carTemp = dec2bin(caracter); %conversion de caracter a binario hdb3Signal(c) = -1;
carBin = reshape(carTemp',[7*length(caracter),1]); %reordenamiento de sig = -1; %se asigna negativo
vector de caracter en 7*(longitud de caracter)x1 else
binNum = str2num(carBin)'; %conversion de vector de caracteres en vector contZeros = contZeros + 1; %Cuenta ceros consecutivos
de numeros de 1x7*(longitud de caracter) if contZeros == 4
set(handles.text4, 'String', num2str(binNum)); if contViolate == 0 || contViolate ~= sig
binNum = [binNum,0]; %se añade un 0 para que el gráfico no quede hdb3Signal(c) = sig;
incompleto al final contViolate = sig;
elseif contViolate == sig
axes(handles.axes2) hdb3Signal(c) = -contViolate;
spectrum1 = fft(binNum); hdb3Signal(c-3) = hdb3Signal(c);
f1 = 0:1/(length(binNum)*Tb):1/Tb-1/(length(binNum)*Tb); contViolate = hdb3Signal(c);
stem(f1,abs(spectrum1), '^') sig = contViolate;
title('Espectro de señal original') end
contZeros = 0; %reset de contador de zeros
ylabel('Amplitud') else
hdb3Signal(c) = 0;
xlabel('Frecuencia [KHz]') end
xlim([0 (str2num(get(handles.edit3, 'String'))-1)*1/(length(binNum)*Tb)]) end
xticks(0:1/(length(binNum)*Tb):1/Tb-1/(length(binNum)*Tb)) end
grid on
axes(handles.axes3)
hold on spectrum2 = fft(hdb3Signal);
plot(f1,abs(spectrum1)) f2 = 0:1/(length(hdb3Signal)*Tb):1/Tb-1/(length(hdb3Signal)*Tb);
hold off stem(f2,abs(spectrum2), '^')
title('Espectro de señal codificada')
switch str{val}
case 'AMI' ylabel('Amplitud')
set(handles.text13, 'String', 1/Tb); %Ancho de banda
set(handles.text14, 'String', 1/Tb); %Velocidad de transmisión xlabel('Frecuencia [KHz]')
set(handles.text15, 'String', 1/Tb); %Velocidad de codificación xlim([0 (str2num(get(handles.edit3, 'String'))-
1)*1/(length(hdb3Signal)*Tb)])
% Caracter codificado con AMI xticks(0:1/(length(hdb3Signal)*Tb):1/Tb-1/(length(hdb3Signal)*Tb))
amiSignal = 0:Tb:7*length(caracter)*Tb; grid on
sig = -1; %signo inicial
for c = 1:7*length(caracter) hold on
if binNum(c) == 1 && sig == -1; plot(f2,abs(spectrum2))
amiSignal(c) = 1; hold off
sig = 1; %se asigna positivo
elseif binNum(c) == 1 && sig == 1; end
amiSignal(c) = -1;
sig = -1; %se asigna negativo
else function edit1_Callback(hObject, eventdata, handles)
amiSignal(c) = 0; %se mantiene el nivel % hObject handle to edit1 (see GCBO)
end % eventdata reserved - to be defined in a future version of MATLAB
end % handles structure with handles and user data (see GUIDATA)

axes(handles.axes3) % Hints: get(hObject,'String') returns contents of edit1 as text


spectrum2 = fft(amiSignal); % str2double(get(hObject,'String')) returns contents of edit1 as a
f2 = 0:1/(length(amiSignal)*Tb):1/Tb-1/(length(amiSignal)*Tb); double
stem(f2,abs(spectrum2), '^')
title('Espectro de señal codificada')
% --- Executes during object creation, after setting all properties.
ylabel('Amplitud') function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
xlabel('Frecuencia [KHz]') % eventdata reserved - to be defined in a future version of MATLAB
xlim([0 (str2num(get(handles.edit3, 'String'))- % handles empty - handles not created until after all CreateFcns called
1)*1/(length(amiSignal)*Tb)])
xticks(0:1/(length(amiSignal)*Tb):1/Tb-1/(length(amiSignal)*Tb)) % Hint: edit controls usually have a white background on Windows.
grid on % See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), HDB3
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a
double

% --- Executes during object creation, after setting all properties.


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a
double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

FRECUENCIA

AMI