annotate dsp/specbasis.m @ 32:c3b0cd708782

Imported core dsp tools.
author samer
date Sun, 20 Jan 2013 13:48:47 +0000
parents
children 5b7d90b6393a
rev   line source
samer@32 1 function map=specbasis(edges,M)
samer@32 2 % specbasis - Create frequency mapping matrix
samer@32 3 %
samer@32 4 % Converts a filterbank specification into a sparse matrix for
samer@32 5 % mutliplying with a linear-frequency spectrogram.
samer@32 6 %
samer@32 7 % as_fmap ::
samer@32 8 % [[L-1]] ~ 'array of L-1 bin edge frequencies, in FT bins',
samer@32 9 % M:natural ~ 'number of bins in linear-freq spectrum'
samer@32 10 % ->
samer@32 11 % [[L,M]] ~ 'L-by-M sparse array'.
samer@32 12 %
samer@32 13 % Note, frequencies must measured in bins of the target spectrum,
samer@32 14 % Also, the first and last of the L bands are catch-alls which
samer@32 15 % get all energy below the bottom edge and above the top edge
samer@32 16 % respectively. If, eg, the bottom edge is 0, then the bottom
samer@32 17 % band will be empty.
samer@32 18
samer@32 19 % 2005-01-15 Written - Samer Abdallah: to reproduce behaviour of
samer@32 20 % a the function as_fmap_orig.m. It runs at about half
samer@32 21 % the speed, but this version is only 8 lines of code!
samer@32 22 % Also, this version doesn't barf if more than one band
samer@32 23 % edge falls in a frequency bin.
samer@32 24 %
samer@32 25 % 2005-01-29 SA: switched to measuring frequency in bins and specifying
samer@32 26 % the size of the spectrum to be remapped. This makes the
samer@32 27 % function more general in that it doesn't assume that
samer@32 28 % 1+N/2 bins are retained from an N-point FFT. In fact, the
samer@32 29 % function is now independent of the FFT size.
samer@32 30
samer@32 31 E=repmat([0; edges(:); M-1],1,M);
samer@32 32 I=repmat(0:M-1,length(edges)+1,1);
samer@32 33 map=sparse(phi(E(2:end,:)-I)-phi(E(1:end-1,:)-I));
samer@32 34 map=map.*(map>8e-15); % squeeze out more small values
samer@32 35 map(:,2:end-1)=map(:,2:end-1)/2; % make up for top and bottom bins
samer@32 36
samer@32 37 % ____
samer@32 38 % this is piecewise linear ramp : ___/
samer@32 39 % It models the response of an FFT bin to a band edge as the edge
samer@32 40 % moves across the frequency range. The response of a bin to a
samer@32 41 % band is computed as the sum of responses due to the left and
samer@32 42 % right edges, ie, for the ith FT bin,
samer@32 43 % response=phi(e1-i)-phi(e2-i)
samer@32 44 % where e1 and e2 are the lower and upper edges of the band
samer@32 45 function y=phi(x), y=abs(x+0.5)-abs(x-0.5);
samer@32 46