fdiff3st.m

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

M
219
字号
disp(' ');
disp('SCRIPT: fdiff3st.m *************************************************');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 	fdiff3st.m
%
%	jmw
%	1/20/94
%	finds best association for each frame with either
%	previous M frames or prior M frames. (kind of at least...)
%
%	BASED UPON 1986 Tokyo ICASSP Paper by Glass and Zue (p2767)
%	INCLUDES post processing to remove false hits in the middle of silent
%	intervals
%
%	AND STORES RESULTS TO DISK
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

file_string = sprintf('%s.mat', name);
s=sprintf('loading ./%s from hard disk ...',file_string);
disp(s);
s=sprintf('load %s', file_string);
eval(s);
signal = eval(name);

file_string = sprintf('%s_Data.mat', name);
s=sprintf('loading ./%s from hard disk ...',file_string);
disp(s);
s=sprintf('load %s', file_string);
eval(s);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
		PLT = 1;	% flag to determine plotting
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%compute magnitudes

disp('computing magnitudes of frequency responses of LPC vectors ...');

[m,y]=size(cofa);
N = 256;
mag_array = zeros(m,N);		% big array for all mag values

for i=1:m,
	a = range(i,1);
        b = range(i,2);
        res_nrg = residue(a:b) * residue(a:b)' ;
        gain(i) =       sqrt(res_nrg); 
        
        [h,w]=freqz(gain(i),cofa(i,:),N);
	mag = abs(h);
	mag_array(i,1:N) = mag';	
end;

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

% compute distances

disp('computing distances ...');
dp = zeros(m,m);
df = zeros(m,m);
assoc = zeros(1,m);

for n=5:m-4,
	maxdpni = -1e20;
	mindfnj = 1e20;
	mindpni = 1e20;
	maxdfnj = -1e20;

	for i=(n-4):(n-2)
		dp(n,i) = sum(abs(mag_array(n,1:N)-mag_array(i,1:N)));
		if (dp(n,i) > maxdpni)
			maxdpni = dp(n,i);
		end;
		if (dp(n,i) < mindpni)
			mindpni = dp(n,i);
		end;
	end;
	
	for j=(n+2):(n+4)
		df(n,j) = sum(abs(mag_array(n,1:N)-mag_array(j,1:N)));
		if (df(n,j) < mindfnj)
			mindfnj = df(n,j);
		end;
		if (df(n,j) > maxdfnj)
			maxdfnj = df(n,j);
		end;
	end;

	% associate ?
	if (maxdpni < mindfnj)
		% associate to PAST
		assoc(n) = -1;
	elseif (mindpni > maxdfnj)
		% associate FUTURE
		assoc(n) = 1;
	end;
end;

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

% compute boundaries (boundary is whenever association changes 
% from past to future)

boundary = zeros(1,m);
flg = 0;

for i=1:m,
	if (assoc(i) == -1)
		% set flag
		flg = 1;
	elseif (assoc(i) == 1 & flg == 1)
		% boundary detected
		% reset flag
		flg = 0;
		boundary(i) = 1;
	end;
end;

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

% remove false hits in middle of silence and determine remaining
% boundary points

bpts = [];
boundary_frames = [];

for i=3:m-2,

	if ( boundary(i) == 1)
		% boundary detected - now check
		if (VUS_voicetype(i-1)=='s' & VUS_voicetype(i-2)=='s' & ...
	VUS_voicetype(i+1)=='s' & VUS_voicetype(i+2)=='s')
			boundary(i) = 0;
		end;
	end;
end;

for i=1:m,
	if ( boundary(i) == 1)
		boundary_frames = [ boundary_frames i ];
		bpts = [bpts range(i,1) ];
	end;
end;

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

% save results
s=sprintf('saving ./%s_BNDdata to disk ...', name);
disp(s);
s=sprintf('save %s_BNDdata boundary boundary_frames', name);
eval(s);

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

if (PLT)

	titles = 0;

	disp('plotting results ...');

	h=gcf;
	figure(h);
	clg;

	subplot(311);
	plot(signal);
	grid;
	a=axis;
	axis(a);
	s=sprintf('%s', name);
	if (titles)
		title(s);
	end;

	subplot(313);
	stairs(range(:,1),boundary);
	axis([a(1) a(2) -1 1.5]);
	if (titles)
		title('spectral boundary points');
	end;
	grid on;

	subplot(312);
	stairs(range(:,1),assoc);
	axis([a(1) a(2) -1.5 1.5]);
	grid on;
	if (titles)
	  title('frame association (-1 is past, +1 is future, 0 don''t know)');
	end;

end;

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

% clean up time

clear N                   file_string         mindpni             
clear PLT                 flg                 n                   
clear VUS_voicetype       gain                                
clear a                   h                   power               
clear assoc               i                   range               
clear b                   j                   res_nrg             
clear boundary            m                   residue             
clear boundary_frames     mag                 signal              
clear bpts                mag_array           voicetype           
clear cofa                maxdfnj             w                   
clear df                  maxdpni             y                   
clear dp                  mindfnj	      titles

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

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

⌨️ 快捷键说明

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