% Project, Spectral analysis 532
% Ethnecity '98
% DATA of length 4800, samplingfreq 8000 Hz

function Model = power_model();

% --- Training DATA ---
load Msounds
load Dsounds
load Psounds

% Three pers: 1, One pers: 0.5 
scale = 1;

global wsize wlag window powlen words

wsize=50; wlag=10; powlen=(4800-wsize)/wlag;
window=hamming(wsize)';

Q(1,:,:,:)=D;
Q(2,:,:,:)=P;
Q(3,:,:,:)=M;

figure(1)
for wordnr=1:5
  for pers=1:3
    for realiz=1:10;
      xx=reshape(Q(pers,wordnr,realiz,:),1,4800);
      xx=filter([1 -15/16],1,xx); xx=xx/max(xx);

      subplot(5,2,wordnr*2-1); plot(xx); axis([0 4800 -1 1]);
      ylabel('Level'); title(['Realization of ', words(wordnr,:)]);
 
      for k=0:powlen
        yy=window.*xx(wlag*k+1:wlag*k+wsize);
        power(k+1) = sqrt(sum(yy.^2));
      end;  
    power_tot(realiz,:) = power;
    end;
    power_pers(pers,:)=sqrt(sum(power_tot.^2, 1))/10;
  end;
  power_avg = sqrt(sum(power_pers.^2, 1))/scale;

% --- Power calculation ---
  subplot(5,2,wordnr*2); plot(power_avg); axis([0 powlen 0 1]);
  title(['Power, Model for ', words(wordnr,:)]);
  ylabel('Power');

  POW(wordnr,:) = power_avg;
end;

Model = POW;














