view dsp/tri_filterbank.m @ 42:ae596261e75f

Various fixes and development to audio handling
author samer
date Tue, 02 Dec 2014 14:51:13 +0000
parents c3b0cd708782
children
line wrap: on
line source
% 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