unvd2dst.m

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

M
373
字号
disp(' ');
disp('SCRIPT: unvdet2dst.m ***********************************************');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 	UNVDET2DST.M
%
%	This algorithm developed by jmw (and it shows, 'eh?)
% 	jmw
%	2/9/94
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

		PLT = 1;	% flag to determine plotting

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

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

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

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

N=256;		% number of points in freqz

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

% calculate freq response

disp('calculating mean frequency w/ preemphasis...');

% get size
[m,n]=size(cofa);

meanfrq=zeros(m,1);
stddevfrq = zeros(m,1);
for i=1:m,
	if(VUS_voicetype(i) == 'u')
	[h,w]=freqz([1],cofa(i,:),N);
	mag=abs(h);

	% filter freq response with differentiator (preemphasis)
	f= ones(N,1);
	for j=1:N,
		f(j) = (j-1) * 5000/N;
	end;
	mag = mag .* f;

	total_mag = sum(mag);
		
	% measure meanfrq of freq response
	meanfrq(i)=( (mag'/total_mag) * (5000*w/pi));

	end;
end;

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

% smooth results

MFO = 3;	% median filter order
s=sprintf('smoothing mean frequency with median filter of order %d ...', MFO);
disp(s);
meanfrq=median1(meanfrq,MFO);

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

% calculate HF score

HF_thresh_HI = 3800; %3200; changed 10/04 jmw
HF_thresh_LOW = 2400;
R = HF_thresh_HI - HF_thresh_LOW;

hf_score = zeros(1,m);

for i=1:m,
	if (meanfrq(i) > HF_thresh_HI )
		hf_score(i) = 1;
	elseif (meanfrq(i) > HF_thresh_LOW )
		hf_score(i) = ( meanfrq(i) - HF_thresh_LOW ) / R;
	else
		hf_score(i) = 0;
	end;
end;

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

% compute log power for u segments ONLY

[m,n]=size(cofa);

p = zeros(1,m);

for i=1:m,
        if (VUS_voicetype(i)=='u')
                % unvoiced
                p(i)=10*log10(power(i)+ eps);
        else
                ;
        end;
end;

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

% segment unvoiced segments

seg_cnt = 0;
flg = 1;

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

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

% correlate slope of energy with stop attribute ...

seg_slope = [];
if ( seg_cnt > 0)
        for i=1:seg_cnt,
                a=seg_frames(i,1);
                b=seg_frames(i,2);
                R = b - a + 1;
                                
                %if ( R >= 8)
                %       b = a+7;
                %      R = b - a + 1;
                %end;

                if ( R >= 12)
                       b = a+11;
                       R = b - a + 1;
                end;
                
                pollie = polyfit([1:1:R],p(a:b),1);
                seg_slope(i) = pollie(1);
        end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% compute slope score 

slope_score = zeros(1,m);

%T1= 0.5; %1;
T1=  1; %1;
T2= -1; %-0.5;
yint = (1*T1)/(T1-T2);
if ( seg_cnt > 0)
        for i=1:seg_cnt,
                a=seg_frames(i,1);
                b=seg_frames(i,2);
                R = b - a + 1;
		if (seg_slope(i) > T1)
			slope_score(a:b) = zeros(1,R);
		elseif (seg_slope(i) > T2)
		    slope_score(a:b) = yint-(seg_slope(i)/(T1-T2)*ones(1,R));
		else
			slope_score(a:b) = ones(1,R);
		end;
        end;
end;

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

% compute final unv fric & unv stop scores

ufr_score = zeros(1,m);
ust_score = zeros(1,m);
k1 = 0.75;
%k2 = 0.5;
k2 = 0;

if ( seg_cnt > 0)
        for i=1:seg_cnt,
                a=seg_frames(i,1);
                b=seg_frames(i,2);
		R = b - a + 1;
           	ust_score(a:b) = k1*slope_score(a:b)+(k2*(1-hf_score(a:b)));
		ust_score(a:b) = ust_score(a:b) / (k1+k2);
        end;
end;

if ( seg_cnt > 0)
        for i=1:seg_cnt,
                a=seg_frames(i,1);
                b=seg_frames(i,2);
		ufr_score(a:b) = hf_score(a:b);
        end;
end;

for i=1:m,
	if (ust_score(i) < 0)
		ust_score(i) = 0;
	elseif (ust_score(i) > 1)
		ust_score(i) = 1;
	end;

	if (ufr_score(i) < 0)
		ufr_score(i) = 0;
	elseif (ufr_score(i) > 1)
		ufr_score(i) = 1;
	end;
end;

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

% scale stop score for segments less than a certain duration (stop_thresh)

stop_thresh = 500;
stop_gain = 8.0;

if ( seg_cnt > 0)
        for i=1:seg_cnt,
                a=seg_frames(i,1);
                b=seg_frames(i,2);
                R = b - a + 1;
		R = R * 50;

		if ( R < stop_thresh)
		        scale_factor = ((stop_thresh - R)/stop_thresh);
			scale_factor = 1 + scale_factor;

		   	scale_factor = stop_gain * scale_factor;
			
			ust_score(a:b) = ust_score(a:b) * scale_factor;
			
			s1=sprintf('segment %d is %4.0f ms.  ',i,R/10);
		      s2=sprintf('stop score increased by %4.2fx',scale_factor);
			disp([s1 s2]);
		end;
        end;
end;

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

% scale stop score for segments more than a certain duration (fric_thresh)

fric_thresh = 800;
fric_gain = 1.0;

if ( seg_cnt > 0)
        for i=1:seg_cnt,
                a=seg_frames(i,1);
                b=seg_frames(i,2);
                R = b - a + 1;
		R = R * 50;

		if ( R > fric_thresh)
		   	scale_factor = 1 + ((R - fric_thresh )/fric_thresh);
		   	scale_factor = fric_gain * scale_factor;
			ust_score(a:b) = ust_score(a:b) / scale_factor;
			s1=sprintf('segment %d is %4.0f ms.  ',i,R/10);
		      s2=sprintf('stop score decreased by %4.2fx',scale_factor);
			disp([s1 s2]);

		end;
        end;
end;

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

% limit stop score to [0,1]

for i=1:m,
	if (ust_score(i) > 1.0 )
		ust_score(i) = 1.0;
	end;
end;

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

% save results

s=sprintf('saving ./%s_USTscore', name);
disp(s);
s=sprintf('save temp/%s_USTscore ust_score', name);
eval(s);

s=sprintf('saving ./%s_UFRscore', name);
disp(s);
s=sprintf('save temp/%s_UFRscore ufr_score', name);
eval(s);

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

% plot results

if (PLT)

	titles = 1;	% turn off for diss figs

	disp('plotting results ...');
	h=gcf;
	figure(h);
	clf;

	subplot(311);
	s=sprintf('x=%s;', name);
	eval(s);
	plot(x);
	s=sprintf('%s',name);
	if (titles)
		title(s);
	end;
	grid on;
	a1=axis;

	subplot(312);
	stairs(range(:,1),ust_score);
	%stairs(range(:,1),slope_score); 
	grid on;
	axis([a1(1) a1(2) -0.5 1.5]);
	if (titles)
		title('Unvoiced Stop score');
	end;
	
	subplot(313);
	stairs(range(:,1),ufr_score);
	grid on;
	axis([a1(1) a1(2) -0.5 1.5]);
	if (titles)
		title('Unvoiced Fricative score');
	end;

	drawnow;
end;

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

% clean up

clear HF_thresh_HI        flg                 seg_cnt             
clear HF_thresh_LOW       h                   seg_frames          
clear MFO                 hf_score            seg_slope           
clear N                   i                   slope_score         
clear PLT                 j                   stddevfrq           
clear R                   m                   total_mag           
clear T1                  mag                 ufr_score           
clear T2                  meanfrq             ust_score           
clear VUS_voicetype       n                   voicetype           
clear a                                       w                   
clear a1                  p                   x                   
clear b                   pollie              yint                
clear cofa                power               k1 k2
clear f                   range               s2 s1 
clear filename            residue
clear fric_gain fric_thresh scale_factor stop_gain stop_thresh
              
s=sprintf('clear %s',name);
eval(s);
clear s
    

⌨️ 快捷键说明

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