function varargout = RES(varargin)
% RES M-file for RES.fig
% RES, by itself, creates a new RES or raises the existing
% singleton*.
%
% H = RES returns the handle to a new RES or the handle to
% the existing singleton*.
%
% RES('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RES.M with the given input arguments.
%
% RES('Property','Value',...) creates a new RES or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before RES_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to RES_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 RES
% Last Modified by GUIDE v2.5 01-Oct-2009 00:52:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RES_OpeningFcn, ...
'gui_OutputFcn', @RES_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 RES is made visible.
function RES_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 RES (see VARARGIN)
% Choose default command line output for RES
handles.output = hObject;
% CARGANDO DATOS DE LA VENTANA PRINCIPAL
global t RHO indicador;
%CENTRAR VENTANA
scrsz = get(0,'ScreenSize');
pos_act=get(handles.RES,'Position');
xr=scrsz(3) - pos_act(3);
xp=round(xr/2);
yr=scrsz(4) - pos_act(4);
yp=round(yr/2);
set(handles.RES,'Position',[xp yp pos_act(3) pos_act(4)]);
% CARGAR FIGURA PARA INGRESO DE DATOS
axes(handles.axes1)
background = imread('REScotas.jpg');
axis off;
imshow(background);
if (indicador==2 & exist('t2.mat'))
load t2
%diametro del conducto en mm
set(handles.edit1,'string',DD/10^-3)
set(handles.text2,'string',DD/10^-3)
%diametro de la cmara en mm
set(handles.edit4,'string',DC/10^-3)
set(handles.edit2,'string',LU/10^-3)
set(handles.edit3,'string',LD/10^-3)
% diametro de los hoyos en mm
set(handles.edit6,'string',DH/10^-3)
%espesor Ducto en mm
set(handles.edit7,'string',TW/10^-3)
%Nmero de Perforaciones
set(handles.edit5,'string',Nh)
handles.DD=DD;
handles.DC=DC;
handles.LU=LU;
handles.LD=LD;
handles.DH=DH;
handles.TW=TW;
handles.Nh=Nh;
c=331*sqrt((t+273)/273);
Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto
Sc=(pi*(handles.DC)^2)/4;%Superficie transversal de la cmara
Sh=(pi*handles.DH^2)/4;
leq=handles.TW+0.85*handles.DH;
So=Sc-Sd;
Zd=(RHO*c)/Sd;
%% Clculos TL sin flujo
f=0:4000; % Matriz de Frecuencias
for aux=1:length(f)
w=2*pi*f(aux);
ko=w/c;
Zr=(1/handles.Nh)*(j*w*(leq/Sh)+(w^2/(pi*c)))-j*(c/Sc)*(1/(tan(ko*handles.LU)+tan(ko*handles.LD)));
T=[1 0;1/Zr 1];
TL(aux)=20*log10((1/2)*abs(T(1,1)+((Sd/(RHO*c))*T(1,2))+(((RHO*c)/Sd)*T(2,1))+T(2,2)));
end
axes(handles.axes2)
fc=find(f==round((1.84*c)/(pi*handles.DC)));
fnew=f(1,1:fc);
plot(fnew,TL(1:length(fnew)),'r')
xlabel('Frecuencia (Hz)','FontName','Lucida Console');
ylabel('TL (dB)','FontName','Lucida Console');
grid on;
elseif (indicador==1 & exist('t1.mat'))
load t1
%diametro del conducto en mm
set(handles.edit1,'string',DD/10^-3)
set(handles.text2,'string',DD/10^-3)
%diametro de la cmara en mm
set(handles.edit4,'string',DC/10^-3)
set(handles.edit2,'string',LU/10^-3)
set(handles.edit3,'string',LD/10^-3)
% diametro de los hoyos en mm
set(handles.edit6,'string',DH/10^-3)
%espesor Ducto en mm
set(handles.edit7,'string',TW/10^-3)
%Nmero de Perforaciones
set(handles.edit5,'string',Nh)
handles.DD=DD;
handles.DC=DC;
handles.LU=LU;
handles.LD=LD;
handles.DH=DH;
handles.TW=TW;
handles.Nh=Nh;
c=331*sqrt((t+273)/273);
Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto
Sc=(pi*(handles.DC)^2)/4;%Superficie transversal de la cmara
Sh=(pi*handles.DH^2)/4;
leq=handles.TW+0.85*handles.DH;
So=Sc-Sd;
Zd=(RHO*c)/Sd;
%% Clculos TL sin flujo
f=0:4000; % Matriz de Frecuencias
for aux=1:length(f)
w=2*pi*f(aux);
ko=w/c;
Zr=(1/handles.Nh)*(j*w*(leq/Sh)+(w^2/(pi*c)))-j*(c/Sc)*(1/(tan(ko*handles.LU)+tan(ko*handles.LD)));
T=[1 0;1/Zr 1];
TL(aux)=20*log10((1/2)*abs(T(1,1)+((Sd/(RHO*c))*T(1,2))+(((RHO*c)/Sd)*T(2,1))+T(2,2)));
end
axes(handles.axes2)
fc=find(f==round((1.84*c)/(pi*handles.DC)));
fnew=f(1,1:fc);
plot(fnew,TL(1:length(fnew)),'r')
xlabel('Frecuencia (Hz)','FontName','Lucida Console');
ylabel('TL (dB)','FontName','Lucida Console');
grid on;
else
% CALCULO VELOCIDAD DEL SONIDO EN FUNCION DE LA TEMPERATURA
c=331*sqrt((t+273)/273);
% VARIABLES Y CALCULO INICIAL DEL PROGRAMA
handles.dd=38.1;%diametro del conducto en mm
set(handles.edit1,'string',handles.dd)
set(handles.text2,'string',handles.dd)
handles.dc=155;%diametro de la cmara en mm
set(handles.edit4,'string',handles.dc)
handles.lu=97.5;%
set(handles.edit2,'string',handles.lu)
handles.ld=97.5;%
set(handles.edit3,'string',handles.ld)
handles.dh=10;% diametro de los hoyos en mm
set(handles.edit6,'string',handles.dh)
handles.tw=4;%espesor Ducto en mm
set(handles.edit7,'string',handles.tw)
handles.Nh=4;%Nmero de Perforaciones
set(handles.edit5,'string',handles.Nh)
%% Clculos Bsicos
handles.DD=handles.dd*10^-3;
handles.DC=handles.dc*10^-3;
handles.LU=handles.lu*10^-3;
handles.LD=handles.ld*10^-3;
handles.DH=handles.dh*10^-3;
handles.TW=handles.tw*10^-3;
Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto
Sc=(pi*(handles.DC)^2)/4;%Superficie transversal de la cmara
Sh=(pi*handles.DH^2)/4;
leq=handles.TW+0.85*handles.DH;
So=Sc-Sd;
Zd=(RHO*c)/Sd;
%% Clculos TL sin flujo
f=0:4000; % Matriz de Frecuencias
for aux=1:length(f)
w=2*pi*f(aux);
ko=w/c;
Zr=(1/handles.Nh)*(j*w*(leq/Sh)+(w^2/(pi*c)))-j*(c/Sc)*(1/(tan(ko*handles.LU)+tan(ko*handles.LD)));
T=[1 0;1/Zr 1];
MTRES(aux)={T};
TL(aux)=20*log10((1/2)*abs(T(1,1)+((Sd/(RHO*c))*T(1,2))+(((RHO*c)/Sd)*T(2,1))+T(2,2)));
end
axes(handles.axes2)
fc=find(f==round((1.84*c)/(pi*handles.DC)));
fnew=f(1,1:fc);
plot(fnew,TL(1:length(fnew)),'r')
xlabel('Frecuencia (Hz)','FontName','Lucida Console');
ylabel('TL (dB)','FontName','Lucida Console');
grid on;
if indicador==1
handles.nombre1='CAMARA CON RESONADOR CONCENTRICO';
handles.S1RDD=handles.DD;
handles.S1RDC=handles.DC;
handles.S1RLU=handles.LU;
handles.S1RLD=handles.LD;
handles.S1RDH=handles.DH;
handles.S1RTW=handles.TW;
handles.S1RNh=handles.Nh;
save guardar1.mat -struct handles;
T1=MTRES;
S1=Sd;
save Matriz1 T1 S1
elseif indicador==2
handles.nombre2='CAMARA CON RESONADOR CONCENTRICO';
handles.S2RDD=handles.DD;
handles.S2RDC=handles.DC;
handles.S2RLU=handles.LU;
handles.S2RLD=handles.LD;
handles.S2RDH=handles.DH;
handles.S2RTW=handles.TW;
handles.S2RNh=handles.Nh;
save guardar2.mat -struct handles;
S3=Sd;
T2=MTRES;
save Matriz2 T2 S3
end
end
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes RES wait for user response (see UIRESUME)
% uiwait(handles.RES);
% --- Outputs from this function are returned to the command line.
function varargout = RES_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)
%ENTRADA DIAMETRO DEL CONDUCTO
handles=guidata(gcbo);
handles.DD=str2double(get(hObject,'String'));
set(handles.text2,'string',handles.DD);
handles.DD=handles.DD*10^-3;
if isnan(handles.DD)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.dd);
set(handles.text2,'string',handles.dd);
handles.DD=handles.dd*10^-3;
end
if handles.DD<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.dd);
set(handles.text2,'string',handles.dd);
handles.DD=handles.dd*10^-3;
end
guidata(gcbo,handles)
% --- 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)
handles=guidata(gcbo);
handles.LU=str2double(get(hObject,'String'));
handles.LU=handles.LU*10^-3;
if isnan(handles.LU)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.lu);
handles.LU=handles.lu*10^-3;
end
if handles.LU<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.lu);
handles.LU=handles.lu*10^-3;
end
guidata(gcbo,handles)
% --- 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)
handles=guidata(gcbo);
handles.LD=str2double(get(hObject,'String'));
handles.LD=handles.LD*10^-3;
if isnan(handles.LD)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.ld);
handles.LD=handles.ld*10^-3;
end
if handles.LD<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.ld);
handles.LD=handles.ld*10^-3;
end
guidata(gcbo,handles)
% --- 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
function edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit4_Callback(hObject, eventdata, handles)
%ENTRADA DIAMETRO DE LA CAMARA
handles=guidata(gcbo);
handles.DC=str2double(get(hObject,'String'));
handles.DC=handles.DC*10^-3;
if isnan(handles.DC)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.dc);
handles.DC=handles.dc*10^-3;
end
if handles.DC<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.dc);
handles.DC=handles.dc*10^-3;
end
guidata(gcbo,handles)
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit6_Callback(hObject, eventdata, handles)
handles=guidata(gcbo);
handles.DH=str2double(get(hObject,'String'));
handles.DH=handles.DH*10^-3;
if isnan(handles.DH)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.dh);
handles.DH=handles.dh*10^-3;
end
if handles.DH<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.dh);
handles.DH=handles.dh*10^-3;
end
guidata(gcbo,handles)
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)
handles=guidata(gcbo);
handles.TW=str2double(get(hObject,'String'));
handles.TW=handles.TW*10^-3;
if isnan(handles.TW)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.tw);
handles.TW=handles.tw*10^-3;
end
if handles.TW<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.tw);
handles.TW=handles.tw*10^-3;
end
guidata(gcbo,handles)
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit5_Callback(hObject, eventdata, handles)
%ENTRADA DIAMETRO DE LA CAMARA
handles=guidata(gcbo);
handles.nh=str2double(get(hObject,'String'));
if isnan(handles.nh)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.Nh);
handles.nh=handles.Nh;
end
if handles.nh<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.Nh);
handles.nh=handles.Nh;
end
guidata(gcbo,handles)
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% BOTON CALCULAR
% CARGANDO DATOS DE LA VENTANA PRINCIPAL
global t RHO indicador;
% CALCULO VELOCIDAD DEL SONIDO EN FUNCION DE LA TEMPERATURA
c=331*sqrt((t+273)/273);
if (handles.DC>handles.DD&&handles.DH<(handles.LU+handles.LD))
Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto
Sc=(pi*(handles.DC)^2)/4;%Superficie transversal de la cmara
Sh=(pi*handles.DH^2)/4;
leq=handles.TW+0.85*handles.DH;
So=Sc-Sd;
Zd=(RHO*c)/Sd;
%% Clculos TL sin flujo
f=0:4000; % Matriz de Frecuencias
for aux=1:length(f)
w=2*pi*f(aux);
ko=w/c;
Zr=(1/handles.Nh)*(j*w*(leq/Sh)+(w^2/(pi*c)))-j*(c/Sc)*(1/(tan(ko*handles.LU)+tan(ko*handles.LD)));
T=[1 0;1/Zr 1];
MTRES(aux)={T};
TL(aux)=20*log10((1/2)*abs(T(1,1)+((Sd/(RHO*c))*T(1,2))+(((RHO*c)/Sd)*T(2,1))+T(2,2)));
end
axes(handles.axes2)
fc=find(f==round((1.84*c)/(pi*handles.DC)));
fnew=f(1,1:fc);
plot(fnew,TL(1:length(fnew)),'r')
xlabel('Frecuencia (Hz)','FontName','Lucida Console');
ylabel('TL (dB)','FontName','Lucida Console');
grid on;
if indicador==1
handles.nombre1='CAMARA CON RESONADOR CONCENTRICO';
handles.S1RDD=handles.DD;
handles.S1RDC=handles.DC;
handles.S1RLU=handles.LU;
handles.S1RLD=handles.LD;
handles.S1RDH=handles.DH;
handles.S1RTW=handles.TW;
handles.S1RNh=handles.Nh;
save guardar1.mat -struct handles;
S1=Sd;
T1=MTRES;
save Matriz1 T1 S1
save t1.mat -struct handles;
elseif indicador==2
handles.nombre2='CAMARA CON RESONADOR CONCENTRICO';
handles.S2RDD=handles.DD;
handles.S2RDC=handles.DC;
handles.S2RLU=handles.LU;
handles.S2RLD=handles.LD;
handles.S2RDH=handles.DH;
handles.S2RTW=handles.TW;
handles.S2RNh=handles.Nh;
save guardar2.mat -struct handles;
S3=Sd;
T2=MTRES;
save Matriz2 T2 S3
save t2.mat -struct handles;
end
else
errordlg('El dimetro del conducto de entrada debe ser menor que el dimetro de la cmara, y el diametro del agujero debe ser menor que la longitud de la cmara','Entrada Errnea', 'modal')
return
end