Está en la página 1de 9

function varargout = vocal(varargin) % VOCAL MATLAB code for vocal.

fig % VOCAL, by itself, creates a new VOCAL or raises the existing % singleton*. % % H = VOCAL returns the handle to a new VOCAL or the handle to % the existing singleton*. % % VOCAL('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in VOCAL.M with the given input arguments. % % VOCAL('Property','Value',...) creates a new VOCAL or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before vocal_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to vocal_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 inf to modify the response to help vocal % Last Modified by GUIDE v2.5 11-Jul-2013 16:43:38 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @vocal_OpeningFcn, ... 'gui_OutputFcn', @vocal_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 vocal is made visible. function vocal_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 vocal (see VARARGIN)

% Choose default command line output for vocal handles.output = hObject; % Update handles structure guidata(hObject, handles);

axes(handles.axes1) handles.imagen=imread('imagen.bmp'); imagesc(handles.imagen) axis off % UIWAIT makes vocal wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = vocal_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 grabar. function grabar_Callback(hObject, eventdata, handles) % hObject handle to grabar (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; fs=44100; %frecuencia de muestreo y=wavrecord(40000,fs); %tiempo el cual vamos a grabar sound(y,fs); %reproducimos wavwrite(y,fs,'voz'); %gurdamos en un archivo wav llamado VOZ

% --- Executes on button press in reproducir. function reproducir_Callback(hObject, eventdata, handles) [s,fs] = wavread ('voz.wav'); wavplay (s,fs);

% --- Executes on button press in reconocer. function reconocer_Callback(hObject, eventdata, handles) % ecerando variables a enviar num1=0; num2=0; num3=0; num4=0; enviar=0; z=0;

%terminado variables

%RECONOCIMIENTO DE VOZ v1=wavread('open'); v2=wavread('close'); v3=wavread('prender'); v4=wavread('apagar'); %normalizamos %PARA open maximo1=max(abs(v1)); n1=length(v1); sonido1=zeros(1,n1); for i=1:1:n1 sonido1(i)=v1(i)/maximo1; end %PARA close maximo2=max(abs(v2)); n2=length(v2); sonido2=zeros(1,n2); for i=1:1:n2 sonido2(i)=v2(i)/maximo2; end %PARA prender maximo3=max(abs(v3)); n3=length(v3); sonido3=zeros(1,n3); for i=1:1:n3 sonido3(i)=v3(i)/maximo3; end %PARA apagar maximo4=max(abs(v4)); n4=length(v4); sonido4=zeros(1,n4); for i=1:1:n4 sonido4(i)=v4(i)/maximo4; end

%Calculando transformadas transvocala=abs((fft(sonido1))); transvocale=abs((fft(sonido2))); transvocali=abs((fft(sonido3))); transvocalo=abs((fft(sonido4))); voz_usuario=wavread('voz'),

maximo5=max(abs(voz_usuario)); n5=length(voz_usuario); usuario=zeros(1,n5); for i=1:1:n5 usuario(i)=voz_usuario(i)/maximo5; end transusuario=abs((fft(usuario))); %diferencia d furier %calculo de error error(1)=mean(abs(transvocala-transusuario)); error(2)=mean(abs(transvocale-transusuario)); error(3)=mean(abs(transvocali-transusuario)); error(4)=mean(abs(transvocalo-transusuario)); min_error=min(error); display(error); display(min_error); if (min_error==error(1)) set(handles.text1,'String','Encendiendo Focos'); clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','A'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial disp('Transmitiendo') end if (min_error==error(2)) set(handles.text1,'String','Apagando Focos'); clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','B'); pause(0.2) %cerrar puerto y limpiar variables

fclose(pserial); clear pserial disp('Transmitiendo') end if (min_error==error(3)) set(handles.text1,'String','Ejecutando Secuencia 1'); clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','C'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial disp('Transmitiendo') end if (min_error==error(4)) set(handles.text1,'String','Ejecutando Secuencia 2'); clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','D'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial disp('Transmitiendo') end

%% enviando comandos

function inf_Callback(hObject, eventdata, handles) % hObject handle to inf (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 inf as inf % str2double(get(hObject,'String')) returns contents of inf as a double

% --- Executes during object creation, after setting all properties. function inf_CreateFcn(hObject, eventdata, handles) % hObject handle to inf (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 graba. function graba_Callback(hObject, eventdata, handles) % hObject handle to graba (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; fs=44100; %frecuencia de muestreo y1=wavrecord(40000,fs); %tiempo el cual vamos a grabar sound(y1,fs); %reproducimos wavwrite(y1,fs,'open'); %gurdamos en un archivo wav llamado VOZ % --- Executes on button press in grabe. function grabe_Callback(hObject, eventdata, handles) % hObject handle to grabe (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; fs=44100; %frecuencia de muestreo y2=wavrecord(40000,fs); %tiempo el cual vamos a grabar sound(y2,fs); %reproducimos wavwrite(y2,fs,'close'); %gurdamos en un archivo wav llamado VOZ % --- Executes on button press in grabi. function grabi_Callback(hObject, eventdata, handles) % hObject handle to grabi (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; fs=44100; %frecuencia de muestreo y3=wavrecord(40000,fs); %tiempo el cual vamos a grabar sound(y3,fs); %reproducimos wavwrite(y3,fs,'prender'); %gurdamos en un archivo wav llamado VOZ % --- Executes on button press in grabo.

function grabo_Callback(hObject, eventdata, handles) % hObject handle to grabo (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clear all; fs=44100; %frecuencia de muestreo y4=wavrecord(40000,fs); %tiempo el cual vamos a grabar sound(y4,fs); %reproducimos wavwrite(y4,fs,'apagar'); %gurdamos en un archivo wav llamado VOZ

function text1_Callback(hObject, eventdata, handles) % hObject handle to text1 (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 text1 as text % str2double(get(hObject,'String')) returns contents of text1 as a double

% --- Executes during object creation, after setting all properties. function text1_CreateFcn(hObject, eventdata, handles) % hObject handle to text1 (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 pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton11. function pushbutton11_Callback(hObject, eventdata, handles) close

% --- Executes on button press in pushbutton12.

function pushbutton12_Callback(hObject, eventdata, handles) clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','1'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial disp('Transmitiendo')

% --- Executes on button press in pushbutton13. function pushbutton13_Callback(hObject, eventdata, handles) clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','2'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial disp('Transmitiendo')

% --- Executes on button press in pushbutton14. function pushbutton14_Callback(hObject, eventdata, handles) close vocal caratula

% --- Executes on button press in pushbutton15. function pushbutton15_Callback(hObject, eventdata, handles) clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos

fopen(pserial); fprintf(pserial,'%s','3'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial

% --- Executes on button press in pushbutton16. function pushbutton16_Callback(hObject, eventdata, handles) clc; pserial=serial('COM12'); set(pserial,'Baudrate',9600); set(pserial,'DataBits',8); set(pserial,'Parity','none'); set(pserial,'StopBits',1); set(pserial,'FlowControl','none'); disp('transmitiendo a (65)') %envio de datos fopen(pserial); fprintf(pserial,'%s','4'); pause(0.2) %cerrar puerto y limpiar variables fclose(pserial); clear pserial disp('Transmitiendo')

También podría gustarte