% mk_mfcc - Function factory, makes MFCC functions
%
% mk_mfcc :: 
%    I:[[M]->[N]]  ~'selects which rows of DCT to compute',
%    N:natural     ~'size of input', 
%    nonneg        ~'sampling rate'
% -> ([[N]]->[[M]]).

function f = mk_mfcc(M,N,fs)
	Nfft = 2^nextpow2(N+1);
	Nspec= dftbins(Nfft);

	wndw = spdiag(hamming(N,'periodic'));
	melW = tri_filterbank(melspace(400/3,min(7000,fs/2),42),fs*(0:Nspec-1)/Nfft);
	dctW = row(dct(eye(size(melW,1))),M);
	f=@mfcc;

	function y=mfcc(x)
		ft = fft(wndw*x,Nfft);
		y  = dctW*log(melW*abs(ft(1:Nspec,:)).^2);
	end
end
