%doug van nort     MUMT 611    final project 
%Matlab script to extract features for HMM-based timbre recognition sytem
%feature vector is of length 21, with attack time, cepstral coefficients
%and their derivatives
%function Y = get_feats(X);
% X = input signal


function Y = doug_get_feats(X);

i=1;
while abs(X(i)) < .005
    i = i+1;
end

winlen = 2048;   %analysis window length
winlenM1 = 2047;    %analysis window length - 1
WLo2 = 1024;    %half of analysis window length

 start = i;         %find the start of the attack
 
 quart = size(X);
 quart = round(quart(2)/4);
 
 attack_end = argmax(X(1:quart));       %attack end is maximum signal value in first quarter of signal
 
 attack_time = attack_end - start;        %attack time is length of time to reach attack_end from start
 
 cep_co = rceps(X(start:start+winlen));
 cep_coeffs(1:10) = cep_co(1:10);
 cep_deriv(1:10) = zeros(1,10);
 Y(1,(1:21)) = [attack_time cep_co(1:10) cep_deriv(1:10)];
 
 for j=2:100
     
 cep_co = rceps(X(WLo2*(j-1) + start:WLo2*(j-1) + start + winlenM1));
 
 cep_coeffs(10*(j-1)+1:10*(j-1)+10) = cep_co(1:10);
 
 cep_deriv(10*(j-1)+1:10*(j-1)+10) = cep_co(1:10) - cep_coeffs(10*(j-2)+1:10*(j-2)+10);

Y(j,(1:21)) = [attack_time cep_co(1:10) cep_deriv(10*(j-1)+1:10*(j-1)+10)];
end

 
 
 
 
     
     




    