Sie sind auf Seite 1von 13

CURSO :

TALLER DE ELECTRNICA AVANZADA

TEMA : PROGRAMACION EN GUIDE SIMULINK DE MATLAB

DOCENTE: ING. SANCHEZ MARQUEZ, C.

CICLO : X

ALUMNO: ZAVALA SALAZAR, VICTOR G.

2012

PROGRAMACION EN GUIDE SIMULINK DE MATLAB PROGRAMA 1:


function varargout = Sumar_sim(varargin) % SUMAR_SIM M-file for Sumar_sim.fig % SUMAR_SIM, by itself, creates a new SUMAR_SIM or raises the existing % singleton*. % % H = SUMAR_SIM returns the handle to a new SUMAR_SIM or the handle to % the existing singleton*. % % SUMAR_SIM('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SUMAR_SIM.M with the given input arguments. % % SUMAR_SIM('Property','Value',...) creates a new SUMAR_SIM or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Sumar_sim_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Sumar_sim_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only 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 EDIT gui_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', []); 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 Sumar_sim is made visible. function Sumar_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_sim handles.output = hObject; % Update handles structure guidata(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. function varargout = 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 structure varargout{1} = handles.output;

function edit1_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 edit1 as a double

% --- Executes during object creation, after setting all properties. function edit1_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 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 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

% --- Executes on button press in pushbutton1. function pushbutton1_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);

PROGRAMA 2:
function varargout = generador(varargin) % GENERADOR M-file for generador.fig % GENERADOR, by itself, creates a new GENERADOR or raises the existing % singleton*. % % H = GENERADOR returns the handle to a new GENERADOR or the handle to % the existing singleton*. % % GENERADOR('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GENERADOR.M with the given input arguments. % % GENERADOR('Property','Value',...) creates a new GENERADOR or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before generador_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to generador_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only 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 EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @generador_OpeningFcn, ... 'gui_OutputFcn', @generador_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 generador is made visible. function generador_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 generador handles.output = hObject; % Update handles structure guidata(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. function varargout = 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 structure varargout{1} = handles.output;

% --- Executes on selection change in Wave. function Wave_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 Wave contents as cell array % contents{get(hObject,'Value')} returns selected item from Wave onda = get(hObject,'Value'); if onda==1 set_param('simu/Signal Generator','Wave','sine'); set_param(gcs,'SimulationCommand','Start'); elseif onda==2 set_param('simu/Signal Generator','Wave','square'); set_param(gcs,'SimulationCommand','Start'); elseif onda==3 set_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

% --- Executes during object creation, after setting all properties. function Wave_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 CreateFcns called % Hint: popupmenu 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

PROGRAMA 3: SISTEMA DE RECONOCIMIENTO DE VOZ MEDIANTE MATLAB UTILIZANDO PUERTO SERIAL CON PROTEUS CODIGO EN C:
#include <18F4550.h> #fuses XTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN,NOPBADE N #use delay(clock=48000000) //#include <usb_bootloader.h> #include <usb_cdc.h> //configura descriptores para trabajo en CDC void main(void) { char incominByte; int x; usb_init(); //INICIALIZA LAS TRANSACCIONES ENTRE LA PC Y LA TARJETA while (TRUE) { //BUCLE INFINITO if (usb_enumerated()) { //REVISA SI EL PIC HA SIDO ENUMERADO if (usb_cdc_kbhit()) { //REVISA SI HA LLEGADO ALGUN CARACTER AL BUFFER DE RECEPCION incomingByte = usb_cdc_getc(); switch(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; //LEE EL CARACTER DEL BUFFER DE RECEPCIN

case 'I':

output_high(PIN_B5); break; case 'J': output_low(PIN_B5); break; default: break; } } } } }

CODIGO EN MATLAB
function varargout = 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', []); 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 function DOMOTICA_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 colores image(x),colormap(map),axis off,hold on %Ttulos sobre imagen %Ttulo text(80,0,'DOMOTICA','Fontname','Arial','Fontsize',25,'Fontangle','Ita lic', ... '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.' ]);

function varargout = DOMOTICA_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function PUERTA_Callback(hObject, eventdata, handles) fs=44100; y=wavrecord(80000,fs); sound(y,fs); wavwrite(y,fs,'PUERTA'); function PORTON_Callback(hObject, eventdata, handles) fs=44100; y=wavrecord(80000,fs); sound(y,fs); wavwrite(y,fs,'PORTON'); function TV_Callback(hObject, eventdata, handles) fs=44100; y=wavrecord(80000,fs); sound(y,fs); wavwrite(y,fs,'TV'); function LUZ_SALA_Callback(hObject, eventdata, handles) fs=44100; % FRECUENCIA DE MUESTREO y=wavrecord(80000,fs); % ADQUIRIR SONIDO sound(y,fs); % REPRODUCIR SONIDO GRABADO wavwrite(y,fs,'LUZ_SALA'); % ETIQUETAR SONIDO GUARDADO function ALARMA_Callback(hObject, eventdata, handles) fs=44100; y=wavrecord(80000,fs); sound(y,fs); wavwrite(y,fs,'ALARMA'); function GRABANDO_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; function COMPARANDO_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');

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) else set (handles.text1,'string','APAGADO'); fprintf(SerPic,'%s','B');pause(0.2) end if (min_error == error(2)) set (handles.text2,'string','ENCENDIDO'); fprintf(SerPic,'%s','C');pause(0.2) else set (handles.text2,'string','APAGADO'); fprintf(SerPic,'%s','D');pause(0.2) end if (min_error == error(3)) set (handles.text3,'string','ENCENDIDO'); fprintf(SerPic,'%s','E');pause(0.2) else set (handles.text3,'string','APAGADO'); fprintf(SerPic,'%s','F');pause(0.2) end if (min_error == error(4)) set (handles.text4,'string','ENCENDIDO'); fprintf(SerPic,'%s','G');pause(0.2) else set (handles.text4,'string','APAGADO'); fprintf(SerPic,'%s','H');pause(0.2) end if (min_error == error(5)) set (handles.text6,'string','ENCENDIDO'); fprintf(SerPic,'%s','I');pause(0.2) else set (handles.text6,'string','APAGADO'); fprintf(SerPic,'%s','J');pause(0.2) end fclose(SerPic); delete(SerPic) clear SerPic disp ('STOP')

function SALIR_Callback(hObject, eventdata, handles) opcion = questdlg(' Desea salir del software?','Domotica','Si','No', 'Cancelar','Cancelar') switch opcion, case 'No', % case 'Si', close all case 'Cancelar', end function INSTRUCCIONES_Callback(hObject, eventdata, handles)

opcion = questdlg(' ','Domotica','EDITAR','GRABAR', 'COMPARAR','COMPARAR') switch opcion, case 'EDITAR', set (handles.text7,'string',... ['EN ESTA OPCION SE ', ... 'EDITAN LAS VOCES QUE SE ', ... 'REQUIEREN PARA ', ... 'RECONOCER A LAS PERSONA QUE ESTA HABLANDO ' ]); case 'GRABAR', set (handles.text7,'string',... ['EN ESTA OPCION SE ', ... 'DEFINE QUE INSTRUCCION ', ... 'QUIERE ENCENDER EL ', ... 'USUARIO ' ]); case 'COMPARAR', set (handles.text7,'string',... ['EN ESTA OPCION SE ', ... 'COMPARAR LAS VOCES ', ... 'Y SE ENCIENDE LA INSTRUCCION ', ... 'QUE PIDE EL USUARIO' ]); end

SIMULACION POR USB EN PROTEUS:

Das könnte Ihnen auch gefallen