% tri_filterbank - Bank of triangular filters 
%
% tri_filterbank ::
%    E:[[M+2]->nonneg] ~'array of filter edge frequencies',
%    F:[[N]]           ~'array of bin frequencies for input spectra'
% -> [[M,N]]           ~'matrix to multiply by input spectra'.
%
% Modelled on Malcom Slaney's code in Auditory toolbox.

function W=tri_filterbank(edges,f)
	M = length(edges)-2; % total number of filters to prepare

	lower  = edges(1:M);
	center = edges(2:M+1);
	upper  = edges(3:M+2);

	W = zeros(M,length(f));
	for i=1:M
		W(i,:) = (f>lower(i) & f<=center(i)).*(f-lower(i))/(center(i)-lower(i)) ...
			 	 + (f>center(i) & f<upper(i)).*(upper(i)-f)/(upper(i)-center(i));
	end
	W=sparse(W);
end
