Code covered by the BSD License  

Highlights from
AKUZOFT ACOUSTIC SOFTWARE

image thumbnail
from AKUZOFT ACOUSTIC SOFTWARE by Marco Araos
zip file with: Akuzoft archives Manual Akuzoft

CEXT(varargin)
function varargout = CEXT(varargin)
% CEXT M-file for CEXT.fig
%      CEXT, by itself, creates a new CEXT or raises the existing
%      singleton*.
%
%      H = CEXT returns the handle to a new CEXT or the handle to
%      the existing singleton*.
%
%      CEXT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CEXT.M with the given input arguments.
%
%      CEXT('Property','Value',...) creates a new CEXT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before CEXT_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to CEXT_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 CEXT

% Last Modified by GUIDE v2.5 30-Sep-2009 04:27:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @CEXT_OpeningFcn, ...
                   'gui_OutputFcn',  @CEXT_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 CEXT is made visible.
function CEXT_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 CEXT (see VARARGIN)

% Choose default command line output for CEXT
handles.output = hObject;

% CARGANDO DATOS DE LA VENTANA PRINCIPAL
global t RHO Q indicador;


%CENTRAR VENTANA 

scrsz = get(0,'ScreenSize');
pos_act=get(handles.CEXT,'Position');
xr=scrsz(3) - pos_act(3);
xp=round(xr/2);
yr=scrsz(4) - pos_act(4);
yp=round(yr/2);
set(handles.CEXT,'Position',[xp yp pos_act(3) pos_act(4)]);


% CARGAR FIGURA PARA INGRESO DE DATOS

axes(handles.axes1)
background = imread('CEXTcotas.jpg');
axis off;
imshow(background);

if (indicador==2 & exist('t2.mat'))

    load t2

        %diametro del conducto en metros
        set(handles.edit1,'string',DD/10^-3)
        set(handles.text2,'string',DD/10^-3)

        %diametro de la cmara en metros
        set(handles.edit4,'string',DC/10^-3)

        %Longitud del Conducto en la Entrada en m
        set(handles.edit2,'string',LI/10^-3)

        %Longitud de la Cmara en m
        set(handles.edit3,'string',LC/10^-3)
        
    handles.DD=DD;
    handles.DC=DC;
    handles.LI=LI;
    handles.LC=LC;
    
    c=331*sqrt((t+273)/273);
    
                    handles.lr=handles.LC-handles.LI;%Longitud del conducto recto entre el conducto extendido y la contraccin abrupta

                    % CAMARA

                    Sc=(pi*(handles.DC)^2)/4; % Superficie Cmara

                    % CONDUCTO
                    Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto de entrada

                    % CAVIDAD

                    Sr=abs(Sc-Sd);

                    %Impedancias

                    Zd=(RHO*c)/Sd;% Ducto 
                    Zc=(RHO*c)/Sc; % Camara

                    % Velocidades de Flujo

                    Vc=Q/Sc;% Velocidad de flujo medio en la Camara
                    Mc=Vc/c;% Nmero de Mach en la Cmara 

                    Vd=Q/Sd;% Velocidad de flujo medio en los ductos
                    Md=Vd/c;% Nmero de Mach en los ductos



                    %% Clculos TL en presencia de flujo


                    f=0:4000; % Matriz de Frecuencias 

                    for aux=1:length(f)



                    %MATRICES DE TRANSFERENCIA


                    % Conducto Extendido en la entrada

                    kc=((Sc/Sd)-1)^2;
                    zri=-j*((RHO*c)/Sr)*cot(((2*pi*f(aux))/c)*handles.LI);

                    Ti=[1 (kc*Mc*Zc);(1*Sr)/(1*Sr*zri+Sd*Md*Zd) ((1*Sr*zri)-Mc*Zc*(-1*Sc+kc*Sd))/(1*Sr*zri+Sd*Md*Zd)]; 


                    %Conducto Simple

                    k=((2*pi*f(aux))/c)/(1-Mc^2); 
                    Tii=exp(-j*Mc*k*handles.lr)*[cos(k*handles.lr) j*Zc*sin(k*handles.lr);(j/Zc)*sin(k*handles.lr) cos(k*handles.lr)];

                    % Contraccin abrupta


                    K=(1-Sd/Sc)/2;


                     Tiii=[1 K*Md*Zd;0 1];


                    % MATRIZ TOTAL

                    T=Ti*Tii*Tiii;



                    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 metros
        set(handles.edit1,'string',DD/10^-3)
        set(handles.text2,'string',DD/10^-3)

        %diametro de la cmara en metros
        set(handles.edit4,'string',DC/10^-3)

        %Longitud del Conducto en la Entrada en m
        set(handles.edit2,'string',LI/10^-3)

        %Longitud de la Cmara en m
        set(handles.edit3,'string',LC/10^-3)
        
    handles.DD=DD;
    handles.DC=DC;
    handles.LI=LI;
    handles.LC=LC;
    
                    c=331*sqrt((t+273)/273);
                    handles.lr=handles.LC-handles.LI;%Longitud del conducto recto entre el conducto extendido y la contraccin abrupta

                    % CAMARA

                    Sc=(pi*(handles.DC)^2)/4; % Superficie Cmara

                    % CONDUCTO
                    Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto de entrada

                    % CAVIDAD

                    Sr=abs(Sc-Sd);

                    %Impedancias

                    Zd=(RHO*c)/Sd;% Ducto 
                    Zc=(RHO*c)/Sc; % Camara

                    % Velocidades de Flujo

                    Vc=Q/Sc;% Velocidad de flujo medio en la Camara
                    Mc=Vc/c;% Nmero de Mach en la Cmara 

                    Vd=Q/Sd;% Velocidad de flujo medio en los ductos
                    Md=Vd/c;% Nmero de Mach en los ductos



                    %% Clculos TL en presencia de flujo


                    f=0:4000; % Matriz de Frecuencias 

                    for aux=1:length(f)



                    %MATRICES DE TRANSFERENCIA


                    % Conducto Extendido en la entrada

                    kc=((Sc/Sd)-1)^2;
                    zri=-j*((RHO*c)/Sr)*cot(((2*pi*f(aux))/c)*handles.LI);

                    Ti=[1 (kc*Mc*Zc);(1*Sr)/(1*Sr*zri+Sd*Md*Zd) ((1*Sr*zri)-Mc*Zc*(-1*Sc+kc*Sd))/(1*Sr*zri+Sd*Md*Zd)]; 


                    %Conducto Simple

                    k=((2*pi*f(aux))/c)/(1-Mc^2); 
                    Tii=exp(-j*Mc*k*handles.lr)*[cos(k*handles.lr) j*Zc*sin(k*handles.lr);(j/Zc)*sin(k*handles.lr) cos(k*handles.lr)];

                    % Contraccin abrupta


                    K=(1-Sd/Sc)/2;


                     Tiii=[1 K*Md*Zd;0 1];


                    % MATRIZ TOTAL

                    T=Ti*Tii*Tiii;



                    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=19.05;%diametro del conducto en metros
set(handles.edit1,'string',handles.dd)
set(handles.text2,'string',handles.dd)

handles.dc=155.7;%diametro de la cmara en metros
set(handles.edit4,'string',handles.dc)

handles.li=97.5;%Longitud del Conducto en la Entrada en m
set(handles.edit2,'string',handles.li)

handles.lc=195;%Longitud de la Cmara en m
set(handles.edit3,'string',handles.lc)


%% Clculos Bsicos 

handles.DD=handles.dd*10^-3;
handles.DC=handles.dc*10^-3;
handles.LI=handles.li*10^-3;
handles.LC=handles.lc*10^-3;

handles.lr=handles.LC-handles.LI;%Longitud del conducto recto entre el conducto extendido y la contraccin abrupta

% CAMARA

Sc=(pi*(handles.DC)^2)/4; % Superficie Cmara

% CONDUCTO
Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto de entrada

% CAVIDAD

Sr=abs(Sc-Sd);

%Impedancias

Zd=(RHO*c)/Sd;% Ducto 
Zc=(RHO*c)/Sc; % Camara

% Velocidades de Flujo

Vc=Q/Sc;% Velocidad de flujo medio en la Camara
Mc=Vc/c;% Nmero de Mach en la Cmara 

Vd=Q/Sd;% Velocidad de flujo medio en los ductos
Md=Vd/c;% Nmero de Mach en los ductos



%% Clculos TL en presencia de flujo


f=0:4000; % Matriz de Frecuencias 

for aux=1:length(f)



%MATRICES DE TRANSFERENCIA


% Conducto Extendido en la entrada

kc=((Sc/Sd)-1)^2;
zri=-j*((RHO*c)/Sr)*cot(((2*pi*f(aux))/c)*handles.LI);

Ti=[1 (kc*Mc*Zc);(1*Sr)/(1*Sr*zri+Sd*Md*Zd) ((1*Sr*zri)-Mc*Zc*(-1*Sc+kc*Sd))/(1*Sr*zri+Sd*Md*Zd)]; 


%Conducto Simple

k=((2*pi*f(aux))/c)/(1-Mc^2); 
Tii=exp(-j*Mc*k*handles.lr)*[cos(k*handles.lr) j*Zc*sin(k*handles.lr);(j/Zc)*sin(k*handles.lr) cos(k*handles.lr)];

% Contraccin abrupta


K=(1-Sd/Sc)/2;


 Tiii=[1 K*Md*Zd;0 1];

 
% MATRIZ TOTAL

T=Ti*Tii*Tiii;

MTCEXT(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
  
   T1=MTCEXT;
   S1=Sd;
   handles.S1DD=handles.DD;
   handles.S1DC=handles.DC;
   handles.S1LI=handles.LI;
   handles.S1LC=handles.LC;
   handles.nombre1='CAMARA CON CONDUCTO EXTENDIDO EN LA ENTRADA';
   save guardar1.mat -struct handles; 
   save Matriz1 T1 S1
   
   elseif indicador==2
    
   handles.nombre2='CAMARA CON CONDUCTO EXTENDIDO EN LA ENTRADA';
   handles.S2DD=handles.DD;
   handles.S2DC=handles.DC;
   handles.S2LI=handles.LI;
   handles.S2LC=handles.LC; 
   save guardar2.mat -struct handles; 
   
    S3=Sd;
    T2=MTCEXT;
    save Matriz2 T2 S3
     
end



end


% Update handles structure
guidata(hObject, handles);

% UIWAIT makes CEXT wait for user response (see UIRESUME)
% uiwait(handles.CEXT);


% --- Outputs from this function are returned to the command line.
function varargout = CEXT_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 CONDUCTO ENTRADA EN MM
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)

%ENTRADA PORCIN CONDUCTO EXTENDIDO ENTRADA  EN MM
handles=guidata(gcbo);

handles.LI=str2double(get(hObject,'String'));
handles.LI=handles.LI*10^-3;

if isnan(handles.LI)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.li);
set(handles.text2,'string',handles.li);
handles.LI=handles.li*10^-3;


end
if handles.LI<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.li);
handles.LI=handles.li*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)
%ENTRADA LONGITUD DE LA CAMARA  EN MM
handles=guidata(gcbo);

handles.LC=str2double(get(hObject,'String'));
handles.LC=handles.LC*10^-3;

if isnan(handles.LC)
errordlg('Debes ingresar un valor nmerico', 'Mala Entrada', 'modal')
set(hObject,'string',handles.lc);
set(handles.text2,'string',handles.lc);
handles.LC=handles.lc*10^-3;


end
if handles.LC<=0
errordlg('Debes ingresar un valor positivo', 'Mala entrada', 'modal')
set(hObject,'string',handles.lc);
handles.LC=handles.lc*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 edit4_Callback(hObject, eventdata, handles)
%ENTRADA LONGITUD DE LA CAMARA  EN MM
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);
set(handles.text2,'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 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





% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)

handles=guidata(gcbo);

global t RHO Q indicador;

%BOTON CALCULAR

c=331*sqrt((t+273)/273);

if (handles.DC>handles.DD && handles.LI<handles.LC)

handles.lr=handles.LC-handles.LI;%Longitud del conducto recto entre el conducto extendido y la contraccin abrupta

% CAMARA

Sc=(pi*(handles.DC)^2)/4; % Superficie Cmara

% CONDUCTO
Sd=(pi*(handles.DD)^2)/4;%Superficie transversal del conducto de entrada

% CAVIDAD

Sr=abs(Sc-Sd);

%Impedancias

Zd=(RHO*c)/Sd;% Ducto 
Zc=(RHO*c)/Sc; % Camara

% Velocidades de Flujo

Vc=Q/Sc;% Velocidad de flujo medio en la Camara
Mc=Vc/c;% Nmero de Mach en la Cmara 

Vd=Q/Sd;% Velocidad de flujo medio en los ductos
Md=Vd/c;% Nmero de Mach en los ductos



%% Clculos TL en presencia de flujo


f=0:4000; % Matriz de Frecuencias 

for aux=1:length(f)



%MATRICES DE TRANSFERENCIA


% Conducto Extendido en la entrada

kc=((Sc/Sd)-1)^2;
zri=-j*((RHO*c)/Sr)*cot(((2*pi*f(aux))/c)*handles.LI);

Ti=[1 (kc*Mc*Zc);(1*Sr)/(1*Sr*zri+Sd*Md*Zd) ((1*Sr*zri)-Mc*Zc*(-1*Sc+kc*Sd))/(1*Sr*zri+Sd*Md*Zd)]; 


%Conducto Simple

k=((2*pi*f(aux))/c)/(1-Mc^2); 
Tii=exp(-j*Mc*k*handles.lr)*[cos(k*handles.lr) j*Zc*sin(k*handles.lr);(j/Zc)*sin(k*handles.lr) cos(k*handles.lr)];

% Contraccin abrupta


K=(1-Sd/Sc)/2;


 Tiii=[1 K*Md*Zd;0 1];

 
% MATRIZ TOTAL

T=Ti*Tii*Tiii;
MTCEXT(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
   S1=Sd;
  
   handles.nombre1='CAMARA CON CONDUCTO EXTENDIDO EN LA ENTRADA';
   handles.S1DD=handles.DD;
   handles.S1DC=handles.DC;
   handles.S1LI=handles.LI;
   handles.S1LC=handles.LC; 
   save guardar1.mat -struct handles; 
   
   
   
   T1=MTCEXT;
   save Matriz1 T1 S1 
   save t1.mat -struct handles;
   
elseif indicador==2
    
   handles.nombre2='CAMARA CON CONDUCTO EXTENDIDO EN LA ENTRADA';
   handles.S2DD=handles.DD;
   handles.S2DC=handles.DC;
   handles.S2LI=handles.LI;
   handles.S2LC=handles.LC; 
   save guardar2.mat -struct handles; 
    
    S3=Sd;
    T2=MTCEXT;
    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 la longitud de la extensin de entrada debe ser menor que la longitud de la cmara','Entrada Errnea', 'modal')
    
    return
end






Contact us at files@mathworks.com