www.pudn.com > asr.rar > FEA_EXT.M, change:2004-11-06,size:16783b
%%%%%%%%%%%%%%%%
%% 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');
set(cmthndl,'string','Waiting......');
pause(1);
%% 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);
%% 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+energy. number of frame * (18+1)
%% all the coefficient are normalizated.
%% save at normlization\global_mfccp18&energy_old
%% There are error in Mel bank
% mfcc=melcepNorm2(sgg,fs,'pe',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&energy
% mfcc=melcepNormCMS(sgg,fs,'pe',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_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
[mfcc,dStd]=melcepNormEltsi(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 16 coefficients( 4 scales(8 coeffients), 8 scales(4 coeffients),
%% 16 scales(2 coeffients),32 scales(1 coeffients),normalizated energy)
% mfcc=melcepdwtnorm(sgg,fs,'pe',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);
% imagesc(mfcc);
% colormap(hsv(255));
im=mat2gray(mfcc);
imshow(im,255);
axis('xy');
pause(2);
% pause;
% plot mfcc(0-order & 1-order)
% figure;
% hold on;
% grid on;
% i=size(mfcc,2);
% mfcc0=abs(fft(mfcc(2,:),128));
% mfcc1=abs(fft(mfcc(3,:),128));
% f=fs*(0:63)/128;
% plot(f,mfcc0(1:64),'b');
% plot(f,mfcc1(1:64),'r');
% title('blue--the FFT of MFCC(1-oder); red--the FFT of MFCC(2-order)');
% xlabel('frequency');
% ylabel('Magnitude');
% hold off;
% plot mfcc(0-order & 1-order)
% figure;
% hold on;
% grid on;
% i=size(mfcc2,2);
% mfcc0=abs(fft(mfcc2(2,:),128));
% mfcc1=abs(fft(mfcc2(3,:),128));
% f=fs*(0:63)/128;
% plot(f,mfcc0(1:64),'b');
% plot(f,mfcc1(1:64),'r');
% title('blue--the FFT of MFCC(0-oder); red--the FFT of MFCC(1-order)');
% xlabel('frequency');
% ylabel('Magnitude');
% hold off;
%% 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
end
if val == 5
%% Determine if file type is matched%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if( isempty(Files) | ...
isempty(findstr(lower(CrntFile),'.fea')) )
msg=str2mat('Error Message: ',...
' ',...
'Selected files are',...
'not in fea 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;
%% load data %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
filename=[Pathname Files(i,:)];
filename=deblank(filename);
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;
eval(['load ' filename ';']);
dot_pos=find(name=='.');
mfccfiles(1:length(name(1:dot_pos-1)))...
= name(1:dot_pos-1);
eval(['mfcc = ' mfccfiles ';']);
% eval(['tmplt = ' tmpltfiles(i,:) ';']);
% 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,:)=[];
% c=[c vx];
diffmfcc=vx';
%% plot results %%
%%%%%%%%%%%%%%%%%%
set(FigNumber,'CurrentAxes',fig22);
imagesc(diffmfcc);
colormap(hsv(255));
%im=mat2gray(mfcc);
%imshow(im);
axis('xy');
pause(3);
%% 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=name(5:(length(name)));
outfilename=strcat('diff',outfile);
outfilename=[Pathname outfilename];
eval(['save ' outfilename ' diffmfcc -ascii;']);
% end
end
end
end