www.pudn.com > asr.rar > FEA_EXTCont.M, change:2004-11-06,size:17769b
%%%%%%%%%%%%%%%%
%% fea_ext.m %%
%%%%%%%%%%%%%%%%
%% Reset the other function selections %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(fcn1hndl,'value',1);
set(fcn3hndl,'value',1);
set(fcn4hndl,'value',1);
set(fcn5hndl,'value',1);
%% Get Input Data %%
%%%%%%%%%%%%%%%%%%%%%
ip1=get(ip1hndl,'string');
ip2=get(ip2hndl,'string');
ip3=get(ip3hndl,'string');
ip4=get(ip4hndl,'string');
%% Possible Selections %%
%% 1 - About Feature Extraction %%
%% 2 - Spectral Features %%
%% 3 - Cepstral Features %%
%% 4 - MFCC Features %%
%% Determine Selection Item %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
val=get(fcn2hndl,'value');
if val ==1
abfeatur;
end
if val == 2
%% Determine if file type is matched%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if( isempty(Files) | ...
isempty(findstr(lower(CrntFile),'.wav')) )
msg=str2mat('Error Message: ',...
' ',...
'Selected files are',...
'not in wav format.');
set(cmthndl,'string',msg);
return;
end
%% clear plot area %%
%%%%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig);
set(fig,'visible','off');
cla
%% Set parameters %%
%%%%%%%%%%%%%%%%%%%%
fmrate=str2num(ip1);
if(fmrate==0 | isempty(fmrate))
fmrate=100;
set(ip1hndl,'string',num2str(100));
end
winsize=str2num(ip2);
if(winsize==0 | isempty(winsize))
winsize=150;
set(ip2hndl,'string',num2str(150));
end
coeffsize=str2num(ip3);
if(coeffsize==0 | isempty(coeffsize))
coeffsize=16;
set(ip3hndl,'string',num2str(16));
end
set(ip4hndl,'String','xxxx');
%% start processing all files in sequence %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
no_file=size(Files,1);
for i=1:no_file
%% clear previous figures %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig21);
cla;
set(FigNumber,'CurrentAxes',fig22);
cla;
%% Read in and plot wave file(s) %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filename=[Pathname Files(i,:)];
filename=deblank(filename);
CrntFile=filename;
[sg,fs] = wavread(filename);
set(FigNumber,'CurrentAxes',fig21);
plot(sg);
%% Show message %%
%%%%%%%%%%%%%%%%%%
msg=str2mat('Input Parameters: ', ...
' <fmrate > <coeffsize>', ...
' <winsize > <not used >',...
' ',...
[' File Name: ',Files(i,:)]);
set(cmthndl,'string',msg);
crntmsg = msg;
%% computer spectral features %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sc = features(sg,fmrate,winsize,coeffsize,fs);
%% plot results %%
%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig22);
imagesc(sc);
colormap(hsv(255));
axis('xy');
pause(3);
% zzz=[];
%% Save result if Saveflag = 1 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(Saveflag==1)
[outfile,outpath]=uiputfile('*.fea',...
'Save power spectrum To A File');
if(outfile ~= 0)
outfile=strcat(outfile,'.fea');
outfilename=[outpath outfile];
eval(['save ' outfilename ' sc -ascii;']);
end
end
end
end
if val == 3
%% Determine if file type is matched%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if( isempty(Files) | ...
isempty(findstr(lower(CrntFile),'.wav')) )
msg=str2mat('Error Message: ',...
' ',...
'Selected files are',...
'not in wav format.');
set(cmthndl,'string',msg);
return;
end
%% clear plot area %%
%%%%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig);
set(fig,'visible','off');
cla
%% Set parameters %%
%%%%%%%%%%%%%%%%%%%%
fmrate=str2num(ip1);
if(fmrate==0 | isempty(fmrate))
fmrate=128;
set(ip1hndl,'string',num2str(128));
end
winsize=str2num(ip2);
if(winsize==0 | isempty(winsize))
winsize=256;
set(ip2hndl,'string',num2str(256));
end
coeffsize=str2num(ip3);
if(coeffsize==0 | isempty(coeffsize))
coeffsize=12;
set(ip3hndl,'string',num2str(12));
end
set(ip4hndl,'String','xxxx');
%% start processing all files in sequence %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
no_file=size(Files,1);
for i=1:no_file
%% clear previous figures %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig21);
cla;
set(FigNumber,'CurrentAxes',fig22);
cla;
%% Read in and plot wave file(s) %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filename=[Pathname Files(i,:)];
filename=deblank(filename);
CrntFile=filename;
[sg,fs] = wavread(filename);
set(FigNumber,'CurrentAxes',fig21);
plot(sg);
%% Show message %%
%%%%%%%%%%%%%%%%%%
msg=str2mat('Input Parameters: ', ...
' <fmrate > <coeffsize>', ...
' <winsize > <not used >',...
' ',...
[' File Name: ',Files(i,:)]);
set(cmthndl,'string',msg);
crntmsg = msg;
%% computer Cepstrum features %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[cc,dcc] = cepfea(sg,fmrate,winsize,coeffsize);
cep=[cc;dcc];
%% plot results %%
%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig22);
imagesc(cep);
colormap(hsv(255));
axis('xy');
pause(3);
% plot cep(0)
% figure;
% hold on;
% i=size(cep,2);
% cep0=abs(fft(cep(1,:),128));
% cep1=abs(fft(cep(2,:),128));
% f=fs*(0:63)/128;
% plot(f,cep0(1:64),'b');
% plot(f,cep1(1:64),'r');
% title('blue--the FFT of LPCC(0-order); the FFT of red--LPCC(1-order)');
% xlabel('frequency');
% ylabel('Magnitude');
% hold off;
%% Save result if Saveflag = 1 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(Saveflag==1)
% [outfile,outpath]=uiputfile('*.fea',...
% 'Save ceptrum(LPCC) To A File');
% if(outfile ~= 0)
% outfile=strcat(outfile,'.fea');
% outfilename=[outpath outfile];
outfile=CrntFile(1:(length(CrntFile)-3));
outfilename=strcat(outfile,'fea');
eval(['save ' outfilename ' cep -ascii;']);
% end
end
end
end
if val == 4
%% Determine if file type is matched%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if( isempty(Files) | ...
isempty(findstr(lower(CrntFile),'.wav')) )
msg=str2mat('Error Message: ',...
' ',...
'Selected files are',...
'not in wav format.');
set(cmthndl,'string',msg);
return;
end
%% clear plot area %%
%%%%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig);
set(fig,'visible','off');
cla
%% Set parameters %%
%%%%%%%%%%%%%%%%%%%%
fmrate=str2num(ip1);
if(fmrate==0 | isempty(fmrate))
fmrate=128;
set(ip1hndl,'string',num2str(128));
end
winsize=str2num(ip2);
if(winsize==0 | isempty(winsize))
winsize=256;
set(ip2hndl,'string',num2str(256));
end
coeffsize=str2num(ip3);
if(coeffsize==0 | isempty(coeffsize))
coeffsize=12;
set(ip3hndl,'string',num2str(12));
end
set(ip4hndl,'String','xxxx');
if Mfflag ==1
set(cmthndl,'string','Waiting......');
pause(1);
end
%% start processing all files in sequence %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
no_file=size(Files,1);
for i=1:no_file
%% clear previous figures %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set(FigNumber,'CurrentAxes',fig21);
% cla;
% set(FigNumber,'CurrentAxes',fig22);
% cla;
%% Read in and plot wave file(s) %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filename=[Pathname Files(i,:)];
filename=deblank(filename);
[sg,fs] = wavread(filename);
% set(FigNumber,'CurrentAxes',fig21);
% plot(sg);
%% Show message %%
%%%%%%%%%%%%%%%%%%
CrntFile=filename;
slashpos=findstr(filename,'\');
name=filename(slashpos(length(slashpos))+1:...
length(filename));
msg=str2mat('Input Parameters: ', ...
' <fmrate > <coeffsize>', ...
' <winsize > <not used >',...
[' File Name: ',name]);
set(cmthndl,'string',msg);
crntmsg = msg;
%% Normalization w.r.t. signal power
%sg=sg-mean(sg);
%sg=sg/std(sg);
% normalize to a peak value of 1.0
% sg=sg./max(abs(sg));
%% preemphasis y(n)=x(n)-0.97x(n-1);
len=length(sg);
sgg=[];
for i=1:len-1
sgg(i)=sg(i+1)-0.97*sg(i);
end
%% computer MFCC features (number of frame * 42=(1+1+12)*3) %%
%% MFCC include log-energy,0-order coefficient,1-order differnce,2-order difference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% mfcc2=melcepst(sg,fs,'e0dD',12);
%
%% MFCC donot include 0-order coefficient. number of frame * 39=(1+12)*3
%% save at pe_mfcc&energy&2difference39
% mfcc=melcepst(sgg,fs,'edD',12);
%
%% MFCC donot include 0-order coefficient. number of frame * 69=(1+22)*3
%% save at pe_mfcc&energy&2difference39
% mfcc=melcepst(sgg,fs,'edD',22);
%
%% MFCC only include 12-order coefficient and 1-order difference. number of frame * 24=12*2
%% save at pe_mfcc&1difference24
% mfcc=melcepst(sgg,fs,'d',12);
%
%% MFCC include 18-order coefficient+energy. number of frame * (18+1)
%% all the coefficient are normalizated.
%% save at normlization\global_mfcc18&energy
% mfcc=melcepNorm1(sgg,fs,'e',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated. -,/.
%% save at normlization\global_mfccp18 2 >
% mfcc=melcepNorm2(sgg,fs,'p',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated. lowpass,-,/.
%% save at normlization\global_mfccplp18
% [mfcc,dStd]=melcepNorm3(sgg,fs,'p',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated. in cepstrum,first RASTA then /.
%% save at normlization\global_mfccpRASTA18 4 >
% [mfcc,dStd]=melcepNormRASTA(sgg,fs,'p',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated. in log power domain, RASTA,then in cepstrum, /.
%% save at normlization\global_mfccpRASTAFreq18 3 >
% [mfcc,dStd]=melcepNormRASTAFreq(sgg,fs,'p',18);
%% MFCC include 18-order coefficient+energy. number of frame * (18+1)
%% all the coefficient are normalizated. -/
%% save at normlization\global_mfccp18&energy
% [mfcc,dStd]=melcepNorm2(sgg,fs,'pe',18,20);
%% MFCC include 18-order coefficient+energy. number of frame * (18+1)
%% all the coefficient are normalizated. only(-) CMS
%% save at normlization\cms_mfccp18 1 >
% mfcc=melcepNormCMS(sgg,fs,'p',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated in frequency. only(-), no energy coefficience
%% save at normlization\freq_mflec18
% [mfcc,dStd]=melcepNormFreq(sgg,fs,'p',18,20);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated in frequency. only(-), no energy coefficience
%% save at normlization\freq_mflecNonlin18
% [mfcc,dStd]=melcepNormFreqNonlin(sgg,fs,'p',18,40);
%% MFCC include 18-order coefficient. number of frame * (18)
%% all the coefficient are normalizated in ceptrum. In frequency long time spectrum is emphasis.
%% save at normlization\norm_mfccEltsi18, the best >
[mfcc,dStd]=melcepNormEltsi(sgg,fs,'p',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% log calculate before the mel filter
%% all the coefficient are normalizated in ceptrum. In frequency long time spectrum is emphasis.
%% save at normlization\norm_mfccEltsibl18, very bad
% [mfcc,dStd]=melcepNormEltsibl(sgg,fs,'p',18);
%% MFCC include 18-order coefficient. number of frame * (18)
%% In frequency long time spectrum is emphasis. and mean substract.
%% all the coefficient are normalizated in ceptrum. save at normlization\norm_mfccLtsiFreq18
% [mfcc,dStd]=melcepNormEltsiFreq(sgg,fs,'p',18);
%% MFCC include 18-order coefficient+energy. number of frame * (18+1)
%% all the coefficient are non linear normalizated.
%% save at normlization\nonlinear_mfcc18&energy
% mfcc=melcepNormSegNonlin(sgg,fs,'pe',18);
%%MFCCDWT include 16 coefficients( 4 scales(8 coeffients), 8 scales(4 coeffients),
%% 16 scales(2 coeffients),32 scales(1 coeffients),normalizated energy)
% mfcc=melcepdwt(sgg,fs,'pe',15,32);
%%MFCCDWT include 15 coefficients( 4 scales(8 coeffients), 8 scales(4 coeffients),
%% 16 scales(2 coeffients),32 scales(1 coeffients)), DWT-db1
%% save in \norm_mfccdwt
% mfcc=melcepdwtnorm(sgg,fs,'p',15,32);
%%MFCCDWT include 16 coefficients( 4 scales(8 coeffients), 8 scales(4 coeffients),
%% 16 scales(2 coeffients),32 scales(1 coeffients),energy)
%% non-linear normalizated DID NOT succeed !!
% mfcc=melcepdwtnormseg(sgg,fs,'pe',15,32);
mfcc=mfcc';
%% plot results %%
%%%%%%%%%%%%%%%%%%
% set(FigNumber,'CurrentAxes',fig21);
% plot(dStd);
% set(FigNumber,'CurrentAxes',fig22);
% im=mat2gray(mfcc);
% imshow(im,255);
% axis('xy');
%% Save result if Saveflag = 1 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(Saveflag==1)
% [outfile,outpath]=uiputfile('*.fea',...
% 'Save Mel-ceptrum(MFCC) To A File');
% if(outfile ~= 0)
% outfile=strcat(outfile,'.fea');
% outfilename=[outpath outfile];
outfile=CrntFile(1:(length(CrntFile)-3));
outfilename=strcat(outfile,'fea');
eval(['save ' outfilename ' mfcc -ascii;']);
% end
end
end
msg='OK';
set(cmthndl,'string',msg);
crntmsg=msg;
% calculate difference MFCC
% eval(['load ' filename ';']);
% dot_pos=find(name=='.');
% mfccfiles(1:length(name(1:dot_pos-1)))...
% = name(1:dot_pos-1);
% eval(['mfcc = ' mfccfiles ';']);
% % calculate different mfcc
% c=mfcc';
% vf=(4:-1:-4)/60;
% [nf,ncc]=size(c);
% ww=ones(4,1);
% cx=[c(ww,:); c; c(nf*ww,:)];
% vx=reshape(filter(vf,1,cx(:)),nf+8,ncc);
% vx(1:8,:)=[];
% diffmfcc=vx';
end
if val == 5
%% Determine if file type is matched%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if( isempty(Files) | ...
isempty(findstr(lower(CrntFile),'.wav')) )
msg=str2mat('Error Message: ',...
' ',...
'Selected files are',...
'not in wav format.');
set(cmthndl,'string',msg);
return;
end
%% clear plot area %%
%%%%%%%%%%%%%%%%%%%%%
% set(FigNumber,'CurrentAxes',fig);
% set(fig,'visible','off');
% cla
if Mfflag ==1
set(cmthndl,'string','Waiting......');
pause(1);
end
%% start processing all files in sequence %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
no_file=size(Files,1);
for i=1:no_file
%% Read in and plot wave file(s) %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filename=[Pathname Files(i,:)];
filename=deblank(filename);
[sg,fs] = wavread(filename);
%% Show message %%
%%%%%%%%%%%%%%%%%%
CrntFile=filename;
slashpos=findstr(filename,'\');
name=filename(slashpos(length(slashpos))+1:...
length(filename));
msg=str2mat('Input Parameters: ', ...
' <fmrate > <coeffsize>', ...
' <winsize > <not used >',...
[' File Name: ',name]);
set(cmthndl,'string',msg);
crntmsg = msg;
%% Normalization w.r.t. signal power
%sg=sg-mean(sg);
%sg=sg/std(sg);
% normalize to a peak value of 1.0
sg=sg./max(abs(sg));
%% preemphasis y(n)=x(n)-0.97x(n-1);
len=length(sg);
sgg=[];
for i=1:len-1
sgg(i)=sg(i+1)-0.97*sg(i);
end
sgg=sgg';
%% wpsubegy calculate subband energy use wp, then log, cos
% wpegycoeff=wpsubegy(sgg);
% wpegycoeff=wpegycoeff';
%% wpcoeff calculate wp coefficients, then sum the abs amplitude
[ams2,ams3,ams4,ams5,ams6]=wpamscoeff(sgg);
wpc=[ams2,ams3,ams4,ams5,ams6];
wpc=wpc';
%% plot results %%
%%%%%%%%%%%%%%%%%%
% set(FigNumber,'CurrentAxes',fig21);
% cla;
% plot(wpc);
% im=mat2gray(wpegycoeff');
% imshow(im,255);
% axis('xy');
% pause;
%% Save result if Saveflag = 1 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(Saveflag==1)
% [outfile,outpath]=uiputfile('*.fea',...
% 'Save Mel-WP(wpegycoeff) To A File');
% if(outfile ~= 0)
% outfile=strcat(outfile,'.fea');
% outfilename=[outpath outfile];
outfile=CrntFile(1:(length(CrntFile)-3));
outfilename=strcat(outfile,'fea');
eval(['save ' outfilename ' wpc -ascii;']);
% end
end
end
msg='OK';
set(cmthndl,'string',msg);
crntmsg=msg;
end