Upload
gabriel-salazar
View
220
Download
0
Embed Size (px)
Citation preview
8/12/2019 Lab3 Zavala Salazar Victor
1/13
CURSO : TALLER DE ELECTRNICAAVANZADA
TEMA :PROGRAMACION EN GUIDE SIMUL INK DE
MATLAB
DOCENTE: ING. SANCHEZ MARQUEZ, C.
CICLO : X
ALUMNO: ZAVALA SALAZAR, VICTOR G.
2012
8/12/2019 Lab3 Zavala Salazar Victor
2/13
PROGRAMACION EN GUIDE SIMULINK DE MATLAB
PROGRAMA 1:
functionvarargout = Sumar_sim(varargin)% SUMAR_SIM M-file for Sumar_sim.fig
% SUMAR_SIM, by itself, creates a new SUMAR_SIM or raises theexisting% singleton*.%% H = SUMAR_SIM returns the handle to a new SUMAR_SIM or thehandle to% the existing singleton*.%% SUMAR_SIM('CALLBACK',hObject,eventData,handles,...) calls thelocal% function named CALLBACK in SUMAR_SIM.M with the given inputarguments.%% SUMAR_SIM('Property','Value',...) creates a new SUMAR_SIM orraises the% existing singleton*. Starting from the left, property valuepairs are% applied to the GUI before Sumar_sim_OpeningFcn gets called. An% unrecognized property name or invalid value makes propertyapplication% stop. All inputs are passed to Sumar_sim_OpeningFcn viavarargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allowsonly one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Sumar_sim
% Last Modified by GUIDE v2.5 13-May-2013 18:41:38
% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @Sumar_sim_OpeningFcn, ...
'gui_OutputFcn', @Sumar_sim_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);
ifnargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
end
ifnargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end% End initialization code - DO NOT EDIT
8/12/2019 Lab3 Zavala Salazar Victor
3/13
% --- Executes just before Sumar_sim is made visible.functionSumar_sim_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 Sumar_sim (see VARARGIN)
% Choose default command line output for Sumar_simhandles.output = hObject;
% Update handles structureguidata(hObject, handles);
% UIWAIT makes Sumar_sim wait for user response (see UIRESUME)% uiwait(handles.figure1);find_system('Name','suma');open_system('suma');set_param(gcs,'SimulationCommand','Start');
% --- Outputs from this function are returned to the command line.functionvarargout = Sumar_sim_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 structurevarargout{1} = handles.output;
functionedit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (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 edit1 as text% str2double(get(hObject,'String')) returns contents of edit1as a double
% --- Executes during object creation, after setting all properties.functionedit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcnscalled
% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor' ))
set(hObject,'BackgroundColor','white');end
8/12/2019 Lab3 Zavala Salazar Victor
4/13
functionedit2_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 edit2as a double
% --- Executes during object creation, after setting all properties.functionedit2_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 CreateFcnscalled
% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor' ))
set(hObject,'BackgroundColor','white');end
% --- Executes on button press in pushbutton1.functionpushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
val_a=get(handles.edit1,'String');val_b=get(handles.edit2,'String');set_param('suma/Constant','Value',val_a);set_param('suma/Constant1','Value',val_b);
8/12/2019 Lab3 Zavala Salazar Victor
5/13
PROGRAMA 2:
functionvarargout = generador(varargin)% GENERADOR M-file for generador.fig
% GENERADOR, by itself, creates a new GENERADOR or raises theexisting% singleton*.%% H = GENERADOR returns the handle to a new GENERADOR or thehandle to% the existing singleton*.%% GENERADOR('CALLBACK',hObject,eventData,handles,...) calls thelocal% function named CALLBACK in GENERADOR.M with the given inputarguments.%% GENERADOR('Property','Value',...) creates a new GENERADOR orraises the% existing singleton*. Starting from the left, property valuepairs are% applied to the GUI before generador_OpeningFcn gets called. An% unrecognized property name or invalid value makes propertyapplication% stop. All inputs are passed to generador_OpeningFcn viavarargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allowsonly one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help generador
% Last Modified by GUIDE v2.5 13-May-2013 19:17:37
% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @generador_OpeningFcn, ...
'gui_OutputFcn', @generador_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);
ifnargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
end
ifnargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end% End initialization code - DO NOT EDIT
8/12/2019 Lab3 Zavala Salazar Victor
6/13
% --- Executes just before generador is made visible.functiongenerador_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 generador (see VARARGIN)
% Choose default command line output for generadorhandles.output = hObject;
% Update handles structureguidata(hObject, handles);
% UIWAIT makes generador wait for user response (see UIRESUME)% uiwait(handles.figure1);find_system('Name','simu');open_system('simu');set_param(gcs,'SimulationCommand','Start');
% --- Outputs from this function are returned to the command line.functionvarargout = generador_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 structurevarargout{1} = handles.output;
% --- Executes on selection change in Wave.functionWave_Callback(hObject, eventdata, handles)% hObject handle to Wave (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Wavecontents as cell array% contents{get(hObject,'Value')} returns selected item fromWaveonda = get(hObject,'Value');ifonda==1
set_param('simu/Signal Generator','Wave','sine');set_param(gcs,'SimulationCommand','Start');
elseifonda==2set_param('simu/Signal Generator','Wave','square');set_param(gcs,'SimulationCommand','Start');
elseifonda==3set_param('simu/Signal Generator','Wave','sawtooth');set_param(gcs,'SimulationCommand','Start');
else
set_param('simu/Signal Generator','Wave','random');set_param(gcs,'SimulationCommand','Start');end
8/12/2019 Lab3 Zavala Salazar Victor
7/13
% --- Executes during object creation, after setting all properties.functionWave_CreateFcn(hObject, eventdata, handles)% hObject handle to Wave (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcnscalled
% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.ifispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor' ))
set(hObject,'BackgroundColor','white');end
8/12/2019 Lab3 Zavala Salazar Victor
8/13
PROGRAMA 3: SISTEMA DE RECONOCIMIENTO DE VOZ MEDIANTEMATLAB UTILIZANDO PUERTO SERIAL CON PROTEUS
CODIGO EN C:#include #fusesXTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN,NOPBADE
N#use delay(clock=48000000)//#include #include //configura descriptores para trabajo en CDCvoid main(void) {char incominByte;int x;usb_init(); //INICIALIZA LAS TRANSACCIONES ENTRE LA PC Y LA TARJETAwhile (TRUE){ //BUCLE INFINITO
if (usb_enumerated())
{ //REVISA SI EL PIC HA SIDO ENUMERADOif (usb_cdc_kbhit()){ //REVISA SI HA LLEGADO ALGUN CARACTER AL BUFFER DE RECEPCION
incomingByte = usb_cdc_getc(); //LEE EL CARACTER DEL BUFFER DE RECEPCINswitch(incomingByte)
{case 'A':output_high(PIN_B1);
break;
case 'B':
output_low(PIN_B1);break;
case 'C':output_high(PIN_B2);
break;
case 'D':output_low(PIN_B2);
break;
case 'E':output_high(PIN_B3);
break;
case 'F':output_low(PIN_B3);
break;
case 'G':output_high(PIN_B4);
break;
case 'H':output_low(PIN_B4);
break;
case 'I':
8/12/2019 Lab3 Zavala Salazar Victor
9/13
output_high(PIN_B5);break;
case 'J':output_low(PIN_B5);
break;
default:break;
}}
}}}
CODIGO EN MATLAB
functionvarargout = DOMOTICA(varargin)gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @DOMOTICA_OpeningFcn, ...'gui_OutputFcn', @DOMOTICA_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);
ifnargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
end
ifnargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});
end
functionDOMOTICA_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject;guidata(hObject, handles);%Incluir imagen%Importamos imagen *.jpg,junto con su mapa de colores[x,map]=imread('imagen.jpg','jpg');%Representamos imagen en figura, con su mapa de coloresimage(x),colormap(map),axis off,hold on
%Ttulos sobre imagen%Ttulotext(80,0,'DOMOTICA','Fontname','Arial','Fontsize',25,'Fontangle','Italic', ...
'Fontweight','Bold','color',[0.7 0.3 0.2]);set (handles.text7,'string',...
['AUTORES: ', ...'-ZAVALA SALAZAR, V. ', ...'-VILLAVICENCIO ROJAS ', ...'-PONCE ROJAS, A. ', ...'-BENAVENTE ESPINOZA, M.']);
functionvarargout = DOMOTICA_OutputFcn(hObject, eventdata, handles)
8/12/2019 Lab3 Zavala Salazar Victor
10/13
varargout{1} = handles.output;
functionPUERTA_Callback(hObject, eventdata, handles)fs=44100;y=wavrecord(80000,fs);sound(y,fs);wavwrite(y,fs,'PUERTA');
functionPORTON_Callback(hObject, eventdata, handles)fs=44100;y=wavrecord(80000,fs);sound(y,fs);wavwrite(y,fs,'PORTON');
functionTV_Callback(hObject, eventdata, handles)fs=44100;
y=wavrecord(80000,fs);sound(y,fs);wavwrite(y,fs,'TV');
functionLUZ_SALA_Callback(hObject, eventdata, handles)fs=44100; % FRECUENCIA DE MUESTREOy=wavrecord(80000,fs); % ADQUIRIR SONIDOsound(y,fs); % REPRODUCIR SONIDO GRABADOwavwrite(y,fs,'LUZ_SALA'); % ETIQUETAR SONIDO GUARDADO
functionALARMA_Callback(hObject, eventdata, handles)fs=44100;y=wavrecord(80000,fs);
sound(y,fs);wavwrite(y,fs,'ALARMA');
functionGRABANDO_Callback(hObject, eventdata, handles)set (handles.text1,'string',' ');set (handles.text2,'string',' ');set (handles.text3,'string',' ');set (handles.text4,'string',' ');set (handles.text6,'string',' ');clear all;grabar;
functionCOMPARANDO_Callback(hObject, eventdata, handles)COMPARADOR;voz_usuario=wavread('SONIDO.wav');usuario=normalizar(voz_usuario);transusuario=abs((fft(usuario)));
error(1)=mean(abs(FFTPUERTA-transusuario)); error(2)=mean(abs(FFTPORTON-transusuario)); error(3)=mean(abs(FFTTV-transusuario)); error(4)=mean(abs(FFTLUZSALA-transusuario)); error(5)=mean(abs(FFTALARMA-transusuario)); clc;disp('BEGIN')SerPic = serial ('COM3');set(SerPic,'BaudRate',9600);set(SerPic,'DataBits',8);set(SerPic,'Parity','none');
8/12/2019 Lab3 Zavala Salazar Victor
11/13
set(SerPic,'StopBits',1);set(SerPic,'FlowControl','none');fopen(SerPic);min_error=min(error);display(error);disp(min_error);
if(min_error == error(1))set (handles.text1,'string','ENCENDIDO');fprintf(SerPic,'%s','A');pause(0.2)
elseset (handles.text1,'string','APAGADO');fprintf(SerPic,'%s','B');pause(0.2)
endif(min_error == error(2))
set (handles.text2,'string','ENCENDIDO');fprintf(SerPic,'%s','C');pause(0.2)
elseset (handles.text2,'string','APAGADO');fprintf(SerPic,'%s','D');pause(0.2)
endif(min_error == error(3))set (handles.text3,'string','ENCENDIDO');fprintf(SerPic,'%s','E');pause(0.2)
elseset (handles.text3,'string','APAGADO');fprintf(SerPic,'%s','F');pause(0.2)
endif(min_error == error(4))
set (handles.text4,'string','ENCENDIDO');fprintf(SerPic,'%s','G');pause(0.2)
elseset (handles.text4,'string','APAGADO');fprintf(SerPic,'%s','H');pause(0.2)
endif(min_error == error(5))
set (handles.text6,'string','ENCENDIDO');fprintf(SerPic,'%s','I');pause(0.2)
elseset (handles.text6,'string','APAGADO');fprintf(SerPic,'%s','J');pause(0.2)
endfclose(SerPic);delete(SerPic)clear SerPicdisp ('STOP')
functionSALIR_Callback(hObject, eventdata, handles)opcion = questdlg(' Desea salir del software?','Domotica','Si','No','Cancelar','Cancelar')switchopcion,
case'No',%
case'Si',close all
case'Cancelar',end
functionINSTRUCCIONES_Callback(hObject, eventdata, handles)
8/12/2019 Lab3 Zavala Salazar Victor
12/13
8/12/2019 Lab3 Zavala Salazar Victor
13/13