mgif.m

来自「这是一个用于语音信号处理的工具箱」· M 代码 · 共 330 行

M
330
字号
%
% Manual glottal inverse filtering algorithm
% The inverse filter can be adjusted by hand using formant frequency 
% and bandwidths.
% Author : Minkyu Lee
% Date 10-Oct-1994
% Modified by D. G. Childers
%

% If a window for the mgif button is already open, just return

%if exist('mgif_con_win_h') == 1
%	return;
%end

% If the end points of analysis frame is not defined, return
if exist('xsmax') ~=1 | exist('xsmin') ~= 1
	disp('Please select the analysis frame first');
	return;
end

ext_left=200;	% Extra points for manual GIF
ext_right=200;	% Extra points for manual GIF
%ext=0;
if xsmin-ext_left <= 0
	ext_left=xsmin-1;
end
if xsmax+ext_right >= len
	ext_right=len-xsmax;
end
ydata_m=speech(xsmin-ext_left:xsmax+ext_right);
		
S=sprintf('./output/%s_GCI.mat',name);
if exist(S) == 0
	disp('Glottal closure detection')
	B1;
else
	disp('Glottal closure detection is completed');
end
disp(' ');
disp('Loading glottal closure instant (GCI) data')
S=sprintf('load ./output/%s_GCI.mat',name);
eval(S);
temp_gci=gci; clear gci;
num_gci=length(temp_gci);
for i=1:num_gci
	if temp_gci(i) > round(xsmin)
		break;
	end
end

for j=i:num_gci
	if temp_gci(j) > round(xsmax);
		break;	
	end
	gci(j-i+1)=temp_gci(j)-round(xsmin);
end
clear temp_gci;
num_gci=length(gci);

% Crude estimation of gain and formant frequencies and bandwidths.
% Here, the gain, ff1, ff2, ff3, ff4, fb1, fb2, fb3 and fb4 will be 
% estimated roughly in this script.

mgif_es;

% Define some character strings for future use

S_g  =sprintf('Filter Gain. [dB] :');
S_ff1=sprintf('1st fmt freq.[Hz] :');
S_fb1=sprintf('        bwd. [Hz] :');
S_ff2=sprintf('2nd fmt freq.[Hz] :');
S_fb2=sprintf('        bwd. [Hz] :');
S_ff3=sprintf('3rd fmt freq.[Hz] :');
S_fb3=sprintf('        bwd. [Hz] :');
S_ff4=sprintf('4th fmt freq.[Hz] :');
S_fb4=sprintf('        bwd. [Hz] :');
S_ff5=sprintf('5th fmt freq.[Hz] :');
S_fb5=sprintf('        bwd. [Hz] :');

% Open control box for manual inverse filtering
%for i=1:num_gci-1,
%	cont_flag=0;
%	ydata_m=speech(gci(i)+xsmin:gci(i+1)+xsmin);
%	mgif_estim;
	if exist('mgif_con_win_h') ~= 1
		if exist('mgif_con_win_pos') == 1
			PV=mgif_con_win_pos;
		else
			PV=[100 20 300 380];
		end
	
		mgif_con_win_h=figure('Position',PV,...
			'Resize','on',...
			'Numbertitle','off',...
			'color',BACK_COLOR,...
			'Name','Pitch Async MGIF control box');
	
		%
		% Design the control box 
		%

		% for gain slide bar
		mgif_txt_gain_h=uicontrol('Style','Pushbutton',...
				'Position',[10 350 120 20],...
				'String',S_g);

		mgif_ed_gain_h=uicontrol('Style','edit',...
				'Position',[140 350 40 20],...
				'String',gain);
	
		S1=sprintf('gain=mgif_ok(mgif_ed_gain_h, mgif_sl_gain_h);'); 
		mgif_sl_gain_h=uicontrol('Style','slider',...
				'Position',[190 350 100 20],...
				'Callback',S1,...
				'Max',200,...
				'Min',1,...
				'Value',gain);
	
		% for ff1 slide bar
		mgif_txt_ff1_h=uicontrol('Style','Pushbutton',...
				'Position',[10 320 120 20],...
				'String',S_ff1);
	
		mgif_ed_ff1_h=uicontrol('Style','edit',...
				'Position',[140 320 40 20],...
				'String',ff(1));
	
		S1=sprintf('ff(1)=mgif_ok(mgif_ed_ff1_h, mgif_sl_ff1_h);'); 
		mgif_sl_ff1_h=uicontrol('Style','slider',...
				'Position',[190 320 100 20],...
				'Callback',S1,...
				'Max',900,...
				'Min',150,...
				'Value',ff(1));
		% for fb1 slide bar
		mgif_txt_fb1_h=uicontrol('Style','Pushbutton',...
				'Position',[10 290 120 20],...
				'String',S_fb1);
	
		mgif_ed_fb1_h=uicontrol('Style','edit',...
				'Position',[140 290 40 20],...
				'String',fb(1));
	
		S1=sprintf('fb(1)=mgif_ok(mgif_ed_fb1_h, mgif_sl_fb1_h);'); 
		mgif_sl_fb1_h=uicontrol('Style','slider',...
				'Position',[190 290 100 20],...
				'Callback',S1,...
				'Max',200,...
				'Min',30,...
				'Value',fb(1));
		% for ff2 slide bar
		mgif_txt_ff2_h=uicontrol('Style','Pushbutton',...
				'Position',[10 260 120 20],...
				'String',S_ff2);
	
		mgif_ed_ff2_h=uicontrol('Style','edit',...
				'Position',[140 260 40 20],...
				'String',ff(2));
	
		S1=sprintf('ff(2)=mgif_ok(mgif_ed_ff2_h, mgif_sl_ff2_h);'); 
		mgif_sl_ff2_h=uicontrol('Style','slider',...
				'Position',[190 260 100 20],...
				'Callback',S1,...
				'Max',2500,...
				'Min',500,...
				'Value',ff(2));
	
		% for fb2 slide bar
		mgif_txt_fb2_h=uicontrol('Style','Pushbutton',...
				'Position',[10 230 120 20],...
				'String',S_fb2);
	
		mgif_ed_fb2_h=uicontrol('Style','edit',...
				'Position',[140 230 40 20],...
				'String',fb(2));
	
		S1=sprintf('fb(2)=mgif_ok(mgif_ed_fb2_h, mgif_sl_fb2_h);'); 
		mgif_sl_fb2_h=uicontrol('Style','slider',...
				'Position',[190 230 100 20],...
				'Callback',S1,...
				'Max',350,...
				'Min',30,...
				'Value',fb(2));
	
		% for ff3 slide bar
		mgif_txt_ff3_h=uicontrol('Style','Pushbutton',...
				'Position',[10 200 120 20],...
				'String',S_ff3);
	
		mgif_ed_ff3_h=uicontrol('Style','edit',...
				'Position',[140 200 40 20],...
				'String',ff(3));
	
		S1=sprintf('ff(3)=mgif_ok(mgif_ed_ff3_h, mgif_sl_ff3_h);'); 
		mgif_sl_ff3_h=uicontrol('Style','slider',...
				'Position',[190 200 100 20],...
				'Callback',S1,...
				'Max',3500,...
				'Min',1300,...
				'Value',ff(3));
	
		% for fb3 slide bar
		mgif_txt_fb3_h=uicontrol('Style','Pushbutton',...
				'Position',[10 170 120 20],...
				'String',S_fb3);
	
		S=sprintf('%d',fb(3));
		mgif_ed_fb3_h=uicontrol('Style','edit',...
				'Position',[140 170 40 20],...
				'String',S);
	
		S1=sprintf('fb(3)=mgif_ok(mgif_ed_fb3_h, mgif_sl_fb3_h);'); 
		mgif_sl_fb3_h=uicontrol('Style','slider',...
				'Position',[190 170 100 20],...
				'Callback',S1,...
				'Max',500,...
				'Min',40,...
				'Value',fb(3));
	
		% for ff4 slide bar
		mgif_txt_ff4_h=uicontrol('Style','Pushbutton',...
				'Position',[10 140 120 20],...
				'String',S_ff4);
	
		mgif_ed_ff4_h=uicontrol('Style','edit',...
				'Position',[140 140 40 20],...
				'String',ff(4));
	
		S1=sprintf('ff(4)=mgif_ok(mgif_ed_ff4_h, mgif_sl_ff4_h);'); 
		mgif_sl_ff4_h=uicontrol('Style','slider',...
				'Position',[190 140 100 20],...
				'Callback',S1,...
				'Max',4500,...
				'Min',2500,...
				'Value',ff(4));
	
		% for fb4 slide bar
		mgif_txt_fb4_h=uicontrol('Style','Pushbutton',...
				'Position',[10 110 120 20],...
				'String',S_fb4);
	
		mgif_ed_fb4_h=uicontrol('Style','edit',...
				'Position',[140 110 40 20],...
				'String',fb(4));
	
		S1=sprintf('fb(4)=mgif_ok(mgif_ed_fb4_h, mgif_sl_fb4_h);'); 
		mgif_sl_fb4_h=uicontrol('Style','slider',...
				'Position',[190 110 100 20],...
				'Callback',S1,...
				'Max',500,...
				'Min',40,...
				'Value',fb(4));
	
		% for ff5 slide bar
		mgif_txt_ff5_h=uicontrol('Style','Pushbutton',...
				'Position',[10 80 120 20],...
				'String',S_ff5);
	
		mgif_ed_ff5_h=uicontrol('Style','edit',...
				'Position',[140 80 40 20],...
				'String',ff(5));
	
		S1=sprintf('ff(5)=mgif_ok(mgif_ed_ff5_h, mgif_sl_ff5_h);'); 
		mgif_sl_ff5_h=uicontrol('Style','slider',...
				'Position',[190 80 100 20],...
				'Callback',S1,...
				'Max',4500,...
				'Min',2500,...
				'Value',ff(5));
	
		% for fb5 slide bar
		mgif_txt_fb5_h=uicontrol('Style','Pushbutton',...
				'Position',[10 50 120 20],...
				'String',S_fb5);
	
		mgif_ed_fb5_h=uicontrol('Style','edit',...
				'Position',[140 50 40 20],...
				'String',fb(5));
	
		S1=sprintf('fb(5)=mgif_ok(mgif_ed_fb5_h, mgif_sl_fb5_h);'); 
		mgif_sl_fb5_h=uicontrol('Style','slider',...
				'Position',[190 50 100 20],...
				'Callback',S1,...
				'Max',500,...
				'Min',40,...
				'Value',fb(5));
	
		mgif_pb_go_h=uicontrol('Style','pushbutton',...
				'Position',[10 10 80 30],...
				'Callback','mgif_plot',...
				'String','Redraw');
	
	
		mgif_pb_can_h=uicontrol('Style','pushbutton',...
				'Position',[100 10 80 30],...
				'Callback','mgif_go',...
				'String','Go');
	
	
		mgif_pb_re_h=uicontrol('Style','pushbutton',...
				'Position',[190 10 80 30],...
				'Callback','mgif_cancel',...
				'String','Cancel');
	else
		set(mgif_sl_gain_h,'Value',gain);
		set(mgif_sl_ff1_h,'Value',ff(1));
		set(mgif_sl_fb1_h,'Value',fb(1));
		set(mgif_sl_ff2_h,'Value',ff(2));
		set(mgif_sl_fb2_h,'Value',fb(2));
		set(mgif_sl_ff3_h,'Value',ff(3));
		set(mgif_sl_fb3_h,'Value',fb(3));
		set(mgif_sl_ff4_h,'Value',ff(4));
		set(mgif_sl_fb4_h,'Value',fb(4));
		set(mgif_sl_ff5_h,'Value',ff(5));
		set(mgif_sl_fb5_h,'Value',fb(5));
		set(mgif_ed_gain_h,'String',gain);
		set(mgif_ed_ff1_h,'String',ff(1));			
		set(mgif_ed_fb1_h,'String',fb(1));
		set(mgif_ed_ff2_h,'String',ff(2));	
		set(mgif_ed_fb2_h,'String',fb(2));
		set(mgif_ed_ff3_h,'String',ff(3));	
		set(mgif_ed_fb3_h,'String',fb(3));
		set(mgif_ed_ff4_h,'String',ff(4));	
		set(mgif_ed_fb4_h,'String',fb(4));
		set(mgif_ed_ff5_h,'String',ff(5));
		set(mgif_ed_fb5_h,'String',fb(5));
	end	
	
	% Open the plotting

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?