image thumbnail

Three Tube Vocal Tract

by

 

29 Jan 2014 (Updated )

This exercise computes the frequency response of a three-tube model of a human vocal tract.

Callbacks_Three_Tube_VT_GUI25(f,C)
function Callbacks_Three_Tube_VT_GUI25(f,C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=C{1,1};
y=C{1,2};
a=C{1,3};
b=C{1,4};
u=C{1,5};
v=C{1,6};
m=C{1,7};
n=C{1,8};
lengthbutton=C{1,9};
widthbutton=C{1,10};
enterType=C{1,11};
enterString=C{1,12};
enterLabel=C{1,13};
noPanels=C{1,14};
noGraphicPanels=C{1,15};
noButtons=C{1,16};
labelDist=C{1,17};%distance that the label is below the button
noTitles=C{1,18};
buttonTextSize=C{1,19};
labelTextSize=C{1,20};
textboxFont=C{1,21};
textboxString=C{1,22};
textboxWeight=C{1,23};
textboxAngle=C{1,24};
labelHeight=C{1,25};
fileName=C{1,26};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PANELS
for j=0:noPanels-1
uipanel('Parent',f,...
'Units','Normalized',...
'Position',[x(1+4*j) y(1+4*j) x(2+4*j)-x(1+4*j) y(3+4*j)-y(2+4*j)]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%GRAPHIC PANELS
for i=0:noGraphicPanels-1
switch (i+1)
case 1
graphicPanel1 = axes('parent',f,...
'Units','Normalized',...
'Position',[a(1+4*i) b(1+4*i) a(2+4*i)-a(1+4*i) b(3+4*i)-b(2+4*i)],...
'GridLineStyle','--');
case 2
graphicPanel2 = axes('parent',f,...
'Units','Normalized',...
'Position',[a(1+4*i) b(1+4*i) a(2+4*i)-a(1+4*i) b(3+4*i)-b(2+4*i)],...
'GridLineStyle','--');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%TITLE BOXES
for k=0:noTitles-1
switch (k+1)
case 1
titleBox1 = uicontrol('parent',f,...
'Units','Normalized',...
'Position',[u(1+4*k) v(1+4*k) u(2+4*k)-u(1+4*k) v(3+4*k)-v(2+4*k)],...
'Style','text',...
'FontSize',textboxFont{k+1},...
'String',textboxString(k+1),...
'FontWeight',textboxWeight{k+1},...
'FontAngle',textboxAngle{k+1});
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%BUTTONS
for i=0:(noButtons-1)
enterColor='w';
if strcmp(enterType{i+1},'pushbutton')==1 ||strcmp(enterType{i+1},'text')==1
enterColor='default';
end
if (strcmp(enterLabel{1,(i+1)},'')==0 &&...
        strcmp(enterLabel{1,(i+1)},'...')==0) %i.e. there is a label
%creating a label for some buttons
uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i)-labelDist-labelHeight(i+1) ...
(m(2+2*i)-m(1+2*i)) labelHeight(i+1)],...
'Style','text',...
'String',enterLabel{i+1},...
'FontSize', labelTextSize(i+1),...
'HorizontalAlignment','center');
end
switch (i+1)
case 1
button1=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button1Callback);
case 2
button2=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button2Callback);
case 3
button3=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button3Callback);
case 4
button4=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button4Callback);
case 5
button5=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button5Callback);
case 6
button6=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button6Callback);
case 7
button7=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button7Callback);
case 8
button8=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button8Callback);
case 9
button9=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button9Callback);
case 10
button10=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button10Callback);
case 11
button11=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button11Callback);
case 12
button12=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button12Callback);
case 13
button13=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button13Callback);
case 14
button14=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button14Callback);
case 15
button15=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button15Callback);
case 16
button16=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button16Callback);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%USER CODE FOR THE VARIABLES AND CALLBACKS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize Variables
    rG=1;
    rL=1;
    l1=8.8;
    l2=10;
    l3=2;
    A1=8;
    A2=1;
    A3=8;
    fileout='out_three_tube_4';
    sliderpos1=1;
    sliderpos2=1;
    ymin=0;
    ymax=0;
    icolor=1;
    color=['b';'g';'r';'c';'m';'y';'k';];
    ipd=100;
    v=[];

% Name the GUI
    set(f,'Name','Three_Tube_VT');

% CALLBACKS
set_slider_pos()
% Callback for button1 -- glottal reflection coefficient, rG, edit button
 function button1Callback(h,eventdata)
     set(button1,'string',num2str(sliderpos1));
     rG=sliderpos1;
 end

% Callback for button2 -- lips reflection coefficient, rL, edit button
 function button2Callback(h,eventdata)
     set(button2,'string',num2str(sliderpos2));
     rL=sliderpos2;
 end

% Callback for button3 -- rG slider (range of -1 to +1) edit button
 function button3Callback(h,eventdata)
     sliderpos1=get(button3,'val')*2-1;
     button1Callback(h,eventdata);
 end

% Callback for button4 -- rL slider (range of -1 to +1) edit button
 function button4Callback(h,eventdata)
     sliderpos2=get(button4,'val')*2-1;
     button2Callback(h,eventdata);
 end

% Callback for button5 -- length of first tube (cm),l1, edit button
 function button5Callback(h,eventdata)
     l1=str2num(get(button5,'string'));
 end

% Callback for button6 -- length of second tube (cm),l2, edit button
 function button6Callback(h,eventdata)
      l2=str2num(get(button6,'string'));
 end

% Callback for button7 -- length of third tube (cm),l3, edit button
 function button7Callback(h,eventdata)
     l3=str2num(get(button7,'string'));
 end

% Callback for button8 == area of first tube (sq-cm), A1, edit button
 function button8Callback(h,eventdata)
     A1=str2num(get(button8,'string'));
 end

% Callback for button9 -- area of second tube (sq-cm), A2, edit button
 function button9Callback(h,eventdata)
      A2=str2num(get(button9,'string'));
 end

% Callback for button10 -- area of third tube (sq-cm), A3, edit button
 function button10Callback(h,eventdata)
      A3=str2num(get(button10,'string'));
 end

% Callback for button11 -- name of output text file, fileout, in which 
% to store resonance information of 3-tube model, 
 function button11Callback(h,eventdata)
    fileout=get(button11,'string');
 end

% Callback for button15 -- ipd: excitation period in samples at fs=10000
    function button15Callback(h,eventdata);
        ipd=str2num(get(button15,'string'));
    end

% Callback for button12 -- run three tube processing with current data
% compute vocal tract shape and frequency response; first retrieve values
% for current 3-tube model
 function button12Callback(h,eventdata)
    button1Callback(h,eventdata);
    button2Callback(h,eventdata);
    button5Callback(h,eventdata);
    button6Callback(h,eventdata);
    button7Callback(h,eventdata);
    button8Callback(h,eventdata);
    button9Callback(h,eventdata);
    button10Callback(h,eventdata);
    button11Callback(h,eventdata);
    
     if (l1 <= 0)
       waitfor(errordlg('l1 must be positive.'));
       return;
    end
     
    if (l2 <= 0)
      waitfor(errordlg('l2 must be positive.'));
      return;
    end
    
    if (l3 <= 0)
      waitfor(errordlg('l3 must be positive.'));
      return;
    end
    
    if (A1 <= 0)
      waitfor(errordlg('A1 must be positive.'));
      return;
    end
    
    if (A2 <= 0)
      waitfor(errordlg('A2 must be positive.'));
      return;
    end
    
    if (A3 <= 0)
      waitfor(errordlg('A3 must be positive.'));
      return;
    end
    
% create vocal tract shape for plotting for 3-tube vocal tract model
     [x,y1,y2,x1,y3,l]=three_tube_model_pt1(rG,rL,l1,l2,l3,A1,A2,A3);
     
% plot vocal tract shape of 3-tube model in graphics Panel 1
    grid off;
    reset(graphicPanel1);axes(graphicPanel1);cla;
	plot(x,y1,color(1),'LineWidth',2); hold on;
    plot(x,y2,color(1),'LineWidth',2);
	xlabel('Distance From Glottis in cm'); ylabel('Area in Square cm');
    hold on; plot(x1,y3,'r--','LineWidth',2);
    axis([0 l, min(y2)-1 max(y1)+1]);legend('3-tube VT model');
    
% display 3-tube model parameters in titleBox1
	s1=sprintf('3-tube VT model -- l1, A1: %4.1f %4.1f',l1,A1);
	s2=sprintf(' l2, A2: %4.1f %4.1f, l3, A3: %4.1f %4.1f,',l2,A2,l3,A3);
	s3=sprintf(' rL,rG: %4.1f %4.1f',rL,rG);
	stitle=strcat(s1,s2,s3);
    set(titleBox1,'String',stitle);
    set(titleBox1,'FontSize',20);
 
% calculate frequency response of 3-tube vocal tract model
 [fr,vm,vmins,vmaxs,v]=three_tube_model_pt2(rG,rL,l1,l2,l3,A1,A2,A3);
size(v)
 
% plot log magnitude response in graphics Panel 2
    icolor=1;
    reset(graphicPanel2);axes(graphicPanel2);cla;
	plot(fr,vm,color(icolor),'LineWidth',2),
    icolor=icolor+1; if (icolor > 7) icolor=icolor-7;end
	xlabel('Frequency in Hz'),ylabel('Log Magnitude (dB)');
	axis([0 5000 vmins-10 vmaxs+10]); hold on;
        
% read in name of Output Text File, from button 11, in which to store 
% values of resonances and bandwidths
	button11Callback(h,eventdata);
    
% flush all text from output text file for new runs
    fname=strcat(fileout,'.txt');
    fid=fopen(fname,'w');
    fclose(fid);
    
% numerically determine locations and frequencies of 2-tube vocal 
% tract model resonances
    [nfmt,fmt]=three_tube_model_pt3(vm,fileout,rL,rG,l1,l2,l3,A1,A2,A3);
        
 % print resonance locations on plot
	for nf=1:nfmt
        frfmt=[fmt(nf) fmt(nf)];
        vrfmt=[vmins vmaxs];
        plot(frfmt,vrfmt,'k','LineWidth',1);
        string=strcat('fmt', int2str(nf), ':', int2str(fmt(nf)));
        if (mod(nf,2) == 0)
            text(fmt(nf)-200,vmaxs,string);
        else
            text(fmt(nf)-200,vmins,string);
        end
    end
    hold on;
 end

% Callback for button13 -- Append spectral plot
 function button13Callback(h,eventdata)
   
 % read in new values for 3-tube vocal tract model
    button1Callback(h,eventdata);
    button2Callback(h,eventdata);
    button5Callback(h,eventdata);
    button6Callback(h,eventdata);
    button7Callback(h,eventdata);
    button8Callback(h,eventdata);
    button9Callback(h,eventdata);
    button10Callback(h,eventdata);
    button11Callback(h,eventdata);
    
     if (l1 <0)
       waitfor(errordlg('Enter l1 value greater than zero.'));
       return;
    end
     
    if (l2 <0)
      waitfor(errordlg('Enter l2 value greater than zero.'));
      return;
    end
    
    if (l3 <0)
      waitfor(errordlg('Enter l3 value greater than zero.'));
      return;
    end
    
    if (A1 <0)
      waitfor(errordlg('Enter A1 value greater than zero.'));
      return;
    end
    
    if (A2 <0)
      waitfor(errordlg('Enter A2 value greater than zero.'));
      return;
    end
    
    if (A3 <0)
      waitfor(errordlg('Enter A3 value greater than zero.'));
      return;
    end
    
% create vocal tract shape for plotting for 3-tube vocal tract model
     [x,y1,y2,x1,y3,l]=three_tube_model_pt1(rG,rL,l1,l2,l3,A1,A2,A3);
     
% plot vocal tract shape of 3-tube model in graphics Panel 1
    grid off;
    reset(graphicPanel1);axes(graphicPanel1);cla;
	plot(x,y1,color(1),'LineWidth',2); hold on;
    plot(x,y2,color(1),'LineWidth',2);
	xlabel('Distance From Glottis in cm'); ylabel('Area in Square cm');
    hold on; plot(x1,y3,'r--','LineWidth',2);
    axis([0 l, min(y2)-1 max(y1)+1]);legend('3-tube VT model');
     
% calculate frequency response of 3-tube vocal tract model
	[fr,vm,vmins,vmaxs,v]=three_tube_model_pt2(rG,rL,l1,l2,l3,A1,A2,A3);
size(v)    
% plot log magnitude response on graphics Panel 2
    axes(graphicPanel2);
    
	plot(fr,vm,color(icolor),'LineWidth',2);
    icolor=icolor+1; if (icolor > 7) icolor=icolor-7; end
    if (vmaxs > vmins+100) vmaxs=vmins+100;
    end
    ymin=min(ymin,vmins-10);
    ymax=max(ymax,vmaxs);
	axis([0 5000 ymin ymax]);
	hold on;
    
% determine name of file to hold information about resonances
	button11Callback(h,eventdata);
    
% numerically determine locations and frequencies of 3-tube vocal 
% tract model resonances
    [nfmt,fmt]=three_tube_model_pt3(vm,fileout,rL,rG,l1,l2,l3,A1,A2,A3);
 end

% Callback for button16 -- Play Vocal Tract Excited by Pulse Train of
% Period ipd samples at fs=10000 samples/second
    function button16Callback(h,eventdata);
% convert sampled frequency response to DTFT of impulse response of system
% and excite by impulse train; listen to output
    V=[v(1:5001), conj(v(5000:-1:2))];
    vimp=real(ifft(V,10000));
    xin=zeros(1,10000);
    button15Callback(h,eventdata);
    if (ipd <0)
        waitfor(errordlg('IPD must be positive'));
    end
    xin(1:ipd:10000)=1;
    fs=10000;
    xout=conv(xin,vimp);
    soundsc(xout(1:10000),fs);
    end

% Callback for button14 -- close GUI
 function button14Callback(h,eventdata)
     fclose('all');
     close(gcf);
 end
function set_slider_pos()
    set(button3,'val',rG);
    set(button4,'val',rL);
end
end

Contact us