image thumbnail

Single Pole Cepstrum

by

 

29 Jan 2014 (Updated )

This exercise compares and contrasts three methods for computing the complex cepstrum of a signall.

Callbacks_single_pole_cepstrum_GUI25(f,C)
function Callbacks_single_pole_cepstrum_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','--');
case 3
graphicPanel3 = 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);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%USER CODE FOR THE VARIABLES AND CALLBACKS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize Variables
    a=0.9;

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

% CALLBACKS
% Callback for button1 -- a: single pole location
 function button1Callback(h,eventdata)
     a=str2num(get(button1,'string'));
 end

% Callback for button2 -- run single pole cepstrum
 function button2Callback(h,eventdata)

 % retrieve value of parameter a
     a=str2num(get(button1,'string'));
          if ~((a >= 0.01 && a <=0.99))
        waitfor(errordlg('a must be between 0.01 and 0.99.'));
        return
     end
     
 % GUI Title in titleBox1
    stitle=strcat('single pole cepstrum -- 3 methods: a=',num2str(a));
	set(titleBox1,'String',stitle);
    set(titleBox1,'FontSize',25);
    
% call single pole cepstrum routine
    [nseq,nplot,x,xhat1,xhat2,xhat3]=compute_single_pole_cepstrum(a);
    
% plot results - graphics Panel 3 shows the time sequence of the input signal; 
% graphics Panel 2 shows the trio of complex cepstrums computed 
% using three compuational methods;
% graphics Panel 1 shows differences between analytical and computed cepstrums
% for the recursion and data sequence methods

% clear graphics Panel 3
    reset(graphicPanel3);
    axes(graphicPanel3);
    cla; 
    
% plot input signal in graphics Panel 3
    n1=0:nseq-1;
    plot(n1(1:nplot),x(1:nplot),'r','LineWidth',2);
	xlabel('n in samples'),ylabel('value');grid on;axis tight;
    
% clear graphics Panel 2
    reset(graphicPanel2);
    axes(graphicPanel2);
    cla;
    
% plot complex cepstrums of three analysis methods in graphics Panel 2
    stem(n1(1:nplot),xhat1(1:nplot),'k-','LineWidth',2),...
        xlabel('n in quefrency'),ylabel('value');grid on; axis tight;
    hold on;
    stem(n1(1:nplot),xhat2(1:nplot),'b:','LineWidth',2);
    stem(n1(1:nplot),xhat3(1:nplot),'r--','LineWidth',2);
    legend('xhat1-analytical formula','xhat2-recursion relation',...
        'xhat3-data sequence');
    
% clear graphics Panel 1
    reset(graphicPanel1);
    axes(graphicPanel1);
    cla;
    
% plot differences between analytical computation of complex cepstrum and
% the recursion method, as well as the data method in graphics Panel 1
    stem(n1(1:nplot),xhat2(1:nplot)-xhat1(1:nplot),'b:');
    hold on; stem(n1(1:nplot),(xhat3(1:nplot)'-xhat1(1:nplot)),'r--');
    xlabel('n in quefrency'),ylabel('value');grid on;axis tight;
    legend('error xhat2-xhat1','error xhat3-xhat1');
 end

% Callback for button3 -- close GUI
 function button3Callback(h,eventdata)
     close(gcf);
 end
end

Contact us