analy_2b.m

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

M
203
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	analy_2b.m
%
%	jmw and Dr. Hu
%
%	a lot of different times ...
%
%	this program performs pitch asynchronous LP analysis on unvoiced
%	and silent
%
%	and performs pitch synchronous analysis on voiced
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp(' ');
disp('SCRIPT: analy_2b.m ***********************************');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

file_string=sprintf('./temp/%s_GCI.mat',name);
s=sprintf('loading %s', file_string);
disp(s);
s=sprintf('load %s', file_string);
eval(s);

%load GCI;

file_string=sprintf('./temp/%s.mat',name);
s=sprintf('loading %s',file_string);
disp(s);
s=sprintf('load %s',file_string);
eval(s);

signal=eval(name);

s=sprintf('clear %s',name);
eval(s);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% hard-coded flag to use edited gci instead of original gci

USE_ED = 1;
if USE_ED == 1
	gci=gci_ed;
	disp('Using Edited Version of GCI Track ...');
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp('Segmentation is underway ...')

gcitemp=gci;

k=1;

% Segmentation for beginning of speech (pitch synchronous)
startp=14;
endp=2*gci(1)-gci(2);
nsframe=floor((endp-startp+1)/50)-1;
for m=1:nsframe
	voicetype(k)='u';
	range(k,:)=[startp startp+49]+50*(m-1);
	k=k+1;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Segmentation for unvoiced speech (fixed-frame : 50 samples or less)
mid=round((startp+50*nsframe+endp)/2);
voicetype(k)='u';
range(k,:)=[startp+50*nsframe mid];

k=k+1;

voicetype(k)='u';
%range(k,:)=[mid endp];
range(k,:)=[mid+1 endp]; % fixed by jmw 4-13-93 

k=k+1;

voicetype(k)='T';
range(k,:)=[2*gci(1)-gci(2)+1 gci(1)-1]; % mod by jw to increase start by +1

k=k+1;

voicetype(k)='v';
range(k,:)=[gci(1) gci(2)-1];

k=k+1;

for n=2:length(gci)-1
	if (gci(n+1)-gci(n))/(gci(n)-gci(n-1)) > 3
		voicetype(k)='T';
		range(k,:)=[gci(n) 2*gci(n)-gci(n-1)-1];
		k=k+1;
		startp=2*gci(n)-gci(n-1);
		endp=2*gci(n+1)-gci(n+2)-1;
		nsframe=floor((endp-startp+1)/50)-1;
		for m=1:nsframe
			voicetype(k)='u';
			range(k,:)=[startp startp+49]+50*(m-1);
			k=k+1;
		end;
		mid=round((startp+50*nsframe+endp)/2);
		voicetype(k)='u';
		range(k,:)=[startp+50*nsframe mid];
		k=k+1;
		voicetype(k)='u';
		range(k,:)=[mid+1 endp];
		k=k+1;
		voicetype(k)='T';
		range(k,:)=[2*gci(n+1)-gci(n+2) gci(n+1)-1];
		k=k+1;
	else
		voicetype(k)='v';
		range(k,:)=[gci(n) gci(n+1)-1];
		k=k+1;
	end;
end;

voicetype(k)='T';
n=length(gci);
range(k,:)=[gci(n) 2*gci(n)-gci(n-1)-1];

k=k+1;

startp=2*gci(n)-gci(n-1);
endp=length(signal);
nsframe=floor((endp-startp+1)/50)-1;
for m=1:nsframe
	voicetype(k)='u';
	range(k,:)=[startp startp+49]+50*(m-1);
	k=k+1;
end;

mid=round((startp+50*nsframe+endp)/2);
voicetype(k)='u';
range(k,:)=[startp+50*nsframe mid];

k=k+1;

voicetype(k)='u';
range(k,:)=[mid+1 endp];

k=k+1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp('Redo the LP analysis:')
disp('   => Pitch synchronous analysis for voice speech,');
disp('   => frame-based (<=50 samples) analysis for unvoiced speech.');
disp('');
disp('Please wait. This will take a while ...');

% start timer
t_start = clock;

for k=1:length(voicetype)
	ss=signal(range(k,1)-13:range(k,2));
	[cofa(k,:),emp(k),energy,residue1]=lpc_1a(ss);
	residue(range(k,1):range(k,2))=residue1;
	power(k)=energy/(range(k,2)-range(k,1)+1);
end;

% following line added by jmw 4/7/94
range(1,1)= 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp(sprintf('time required: %f sec', etime(clock,t_start)));
disp('');

file_string=sprintf('./%s_Data', name);
s=sprintf('saving %s.mat to disk ...',file_string);
disp(s);
s=sprintf('save temp/%s.mat range power cofa residue voicetype', file_string);
eval(s); 

disp('');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%             *****    Variables    *****
%
% range == the range of the underlying speech segment	
% power == the corresponding power
% cofa == AR coefficients
% residue == the resultant residue
% voicetype == self-explanatory
%		'v' ---> voiced
%		'u' ---> unvoiced
%		'T' ---> transition between voiced and unvoiced

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% clean up time

clear cofa emp endp energy gci gci_ed gcitemp k m mid n nsframe power
clear range reply residue residue1 signal ss startp t_start voicetype
clear s signal_name file_string USE_ED

⌨️ 快捷键说明

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