naratios.m

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

M
269
字号
disp(' ');
disp('SCRIPT: naratio4st.m **************************************************');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 	
%	naratio4st.m
%
%	nasal amplitude ratio 
%	
%	jmw
%	1/13/94
%	1/4/94
%	12/21/93
%
%	THIS METHOD scores the nasal attribute from zero to one.
%	zero is confident that it is NOT nasal
%	one is confident that it IS nasal.
%
%	Algorithm is based upon formant amplitudes.
%
%	AND IT STORES THE RESULTING NASAL SCORE !
% 	IT ALSO LOADS THE BAR SCORE AND ZEROS NASAL SCORE FOR ANY FRAME
% 	THAT HAS A BAR SCORE GREATER THAN A CERTAIN THRESHOLD
%
%	AND LOADS RESULTS FROM r1_ratio3st (sonorant score) to
%	eliminate non-sonorant segments being classified as nasals ...
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

		PLT = 1;		% flag to determine plotting

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

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

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

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

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

file_string = sprintf('temp/%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);

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

% calculate nasal ratio based on FORMANT AMPLITUDES

[m,n]= size(cofa);

nratio = zeros(1,m);
for i=1:m,
	if (a1(i) ~= 0 )
		nratio(i) = a2(i) / a1(i);
	else
		nratio(i) = 0;
	end;
end;

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

% smooth nratio with median filter

MFO = 5; % changed 2/21/94 from 7; % median filter order
s=sprintf('smoothing nratio with median filter of order %d ...', MFO);
disp(s);
nratio = median1(nratio,MFO);

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

% set threshold for nasals and calculate nasal score

disp('calculating nasal score ...');
N_thresh_LOW = 0.05; 			% empirically determined
N_thresh_HI  = 0.20; % changed 2/23/94 from 0.20;
R = N_thresh_HI - N_thresh_LOW;		% R = "range"
N_score = zeros(1,m);

for i=1:m,
	if (nratio(i) >= N_thresh_HI)
		N_score(i) = 0;
	elseif (nratio(i) >= N_thresh_LOW) 
		N_score(i) = (N_thresh_HI - nratio(i)) / R;
	elseif (nratio(i) > 0)
		N_score(i) = 1;
	end;
end;

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

% compare nasal score with bar score ...
% i.e. eliminate frames that are also scored as bar

disp('eliminating nasal frames that are also scored as bar ...');

BAR_REJECT_THRESH = 0.75; %changed from 0.7 2/21/94 % empirically determined	

for i=1:m,
	if ( bar_score(i) > BAR_REJECT_THRESH & N_score(i) > 0)
		N_score(i) = 0;
	end;
end;

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

% eliminate non-sonorant frames classified as nasals

disp('removing non-sonorant frames classified as nasals ...');

NS_thresh = 0.5;	% empirically determined (halfway point)

for i=1:m,
	if (son_score(i) < NS_thresh)
		N_score(i) = 0;
	end;
end;
		
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% segment
 
seg_cnt = 0;
flg = 1;

for i = 1:m,
        if ( N_score(i) > 0 & flg == 1)
                % start new segment
                seg_cnt = seg_cnt + 1;
                seg_frames(seg_cnt,1) = i;
                flg = 0;
        elseif ( N_score(i) > 0 & flg==0)
                % continue in current segment
                seg_frames(seg_cnt,2) = i;
        elseif ( N_score(i) == 0 & flg==0 )
                % segment just ended on previous frame - reset flag
		seg_frames(seg_cnt,2) = i-1;
                flg = 1;
        end;
end;

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

% and discard segments that are tooooo short

events = 0;
NASAL_thresh = 250; % changed from 300 2/21/94

if ( seg_cnt >0)
	% segments do exist
	for i=1:seg_cnt,
		a=range(seg_frames(i,1),1);
		b=range(seg_frames(i,2),2);
		if ( (b-a) < NASAL_thresh)
			% discard - too short
			events = events + 1; % counter of segments eliminated
			a=seg_frames(i,1);
			b=seg_frames(i,2);
			N_score(a:b) = zeros(1,b-a+1);
		end;
	end;
end;
s=sprintf('eliminating nasal segments less than');
s1 = sprintf(' %d samples: ... %d events',NASAL_thresh,events);
s=[s s1];
disp(s);

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

if (PLT)

	titles = 1;	% turn off for diss figs

	h=gcf;
	figure(h);
	clf;

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

	subplot(312);
	stairs(range(:,1),nratio);
	axis([a(1) a(2) 0 1]);
	hold on;
	if (0)	% for dissertation threshold plotting use 0, else use 1
		plot(range(:,1),N_thresh_LOW * ones(1,m),':');
		plot(range(:,1),N_thresh_HI * ones(1,m),':');
	else
		plot(N_thresh_LOW * ones(1,a(2)),'--');
		plot(N_thresh_HI * ones(1,a(2)),'--');
	end;
	hold off;
	grid on;
	if (titles)
		title('smoothed a2/a1');
	end;

	subplot(313);
	stairs(range(:,1),N_score);
	axis([a(1) a(2) -0.5 1.5]);
	grid on;
	if (titles)
		title('Nasal Score');
	end;

	drawnow;
end;

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

% save to disk

nas_score = N_score;
s=sprintf('saving ./%s_NASscore to disk ...', name);
disp(s);
s=sprintf('save temp/%s_NASscore nas_score', name);
eval(s);

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

% clean up time...

clear BAR_REJECT_THRESH   a3                                  
clear              	  b                   nas_score           
clear 	                  bar_score           nratio              
clear MFO                 cofa                power               
clear NASAL_thresh        events              range               
clear NS_thresh           f1                  residue             
clear N_score             f2                  s                   
clear N_thresh_HI         f3                  s1                  
clear N_thresh_LOW        f4                  seg_cnt             
clear PLT                 file_string         seg_frames          
clear R                   flg                 son_score           
clear VUS_voicetype       h                   voicetype           
clear a                   i                   
clear a1                  m                   
clear a2                  n 		titles signal

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


⌨️ 快捷键说明

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