THIS IS MY CODE!!!
filelist = dir('*.wav');
result = zeros(size(filelist));
for index = 1 : length(filelist) fprintf('Processing %s\n', filelist(index).name); result = zeros(size(filelist)); for index = 1 : length(filelist) fprintf('Processing %s\n', filelist(index).name); [y, fs] = wavread(filelist(index).name);
[signal] =y; fs=44100; windowLength=512; frameRate = 100; step=441; signal = signal / max(abs(signal)); curPos = 1; L = length(signal); numOfFrames = floor((L-windowLength)/step) + 1; c=0.8; % threshold cen_present=1; energy_present=1; roll_Pos=1; fluxpos=1; H = hamming(windowLength); m = ((fs/(2*windowLength))*[1:windowLength])'; Centroid = zeros(1,numOfFrames); Energy=zeros(1,numOfFrames); Rolloff=zeros(1,numOfFrames); Flux=zeros(1,numOfFrames); for i=1:numOfFrames cen_window = H.*(signal(cen_present:cen_present+windowLength-1)); FFT = (abs(fft(cen_window,2*windowLength))); FFT = FFT(1:windowLength); FFT = FFT / max(FFT); Centroid(i) = sum(m.*FFT)/sum(FFT); if (sum(cen_window.^2)<0.010) Centroid(i) = 0.0; end cen_present = cen_present + step;
% short time energy of signal is calculated
energy_window = (signal(energy_present:energy_present+windowLength-1));
Energy(i) = (1/(windowLength)) * sum(abs(energy_window.^2));
energy_present = energy_present + step;
% spectral roll off calculation
roll_window = (signal(roll_Pos:roll_Pos+windowLength-1));
FFT1 = (abs(fft(roll_window,512)));
FFT1 = FFT1(1:255);
totalEnergy = sum(FFT1);
curEnergy = 0.0;
countFFT1 = 1;
while ((curEnergy<=c*totalEnergy) && (countFFT1<=255))
curEnergy = curEnergy + FFT(countFFT1);
countFFT1 = countFFT1 + 1;
end
Rolloff(i) = ((countFFT1-1))/(fs/2);
roll_Pos = roll_Pos + step;
% procedure to calculate Spectral flux begins here
flux_window = H.*(signal(fluxpos:fluxpos+windowLength-1));
FFT2 = (abs(fft(flux_window,2*windowLength)));
FFT2 = FFT2(1:windowLength);
FFT2 = FFT2 / max(FFT2);
if (i>1)
Flux(i) = sum((FFT2-FFTprev).^2);
else
Flux(i) = 0;
end
if (isnan(Flux(i)))
Flux(i)=0;
end
fluxpos = fluxpos + step;
FFTprev = FFT2;
end Centroid = Centroid / (fs/2); nam=sprintf('file%d',index); fid=fopen(nam,'w'); [r col]=size(Centroid); for ii=1:1:col %fprintf(fid,'\n%f',Centroid(ii)); fprintf(fid,'\n%f\t%f\t%f\t%f',Centroid(ii),Energy(ii),Rolloff(ii),Flux(ii)); end fclose(fid);