% EE 6820 project
% Segmentation of soccer field audio
% March 31, 2001
% <xlx@ctr.columbia.edu>

% read data
sounddir = '../wav/soccer/';
wavname1 = 'soccer_cg_02.wav';
wavname2 = 'soccer_agt_40.wav';
wavname3 = 'soccer_news2_goal_02.wav';
wavname4 = 'foot1_p24_join.wav';

[d,fs1,nbits]= wavread([sounddir,wavname3]);
% sampling rate normalization
fs = 16000;	%standard sampling rate
d = resample(d,fs, fs1);
d = d(:,1);

% spectrogram 
[b, f, t] = specgram(d,128,fs);
figure(1); subplot(211);
imgdb(t,f,20*log10(abs(b))); colormap(gray(256));
% thanks for imgdb, the spectrogram looks much better!

% energy 
energy = abs(b).^2;
energy = energy - min(energy(:));
% devide into 8 bands
for i=1:8
   k = (i-1)*floor(size(b,1)/8)+1;
   e(i,:)= sum(energy(k:k+8,:));
end

figure(1); subplot(212);
plot(t, e(1,:)/max(e(1,:)), t, e(8,:)/max(e(8,:))); axis tight;

clear all

