function edges=as_cqedges(fs,range,res,F0)

% as_cqedges - Audio Spectrum linear to log frequency map (no checking)
% 
% Converts a constant-Q filterbank specification into a list of band
% edges, and optionally the sparse mapping matrix
% which can be multiplied by a STFT power spectrogram to get a 
% constant-Q spectrogram. 
%
% as_cqmap0 ::
%    real     ~ 'sampling rate',
%    [[2]]    ~ 'requested lower and upper cut-off frequencies',
%    real     ~ 'resolution in octaves',
%    real     ~ 'origin of frequency grid in Hz (defaut=1kHz)'
% ->
%    [[L-1]]  ~ 'frequency bin edges',
%    [[L,M]]  ~ 'L by M sparse array'.

% origin of frequnecy grid defaults to 1kHz
if nargin<4, F0=1000; end

% quantise requested edges and represent them in
% in units of res on a log frequency scale.
limits = round(log2(range/F0)/res);

% convert to normalised frequencies (fs=1)
edges = (F0/fs)*2.^(res*(limits(1):limits(2)));

% remove any edges above Nyquist rate
if edges(end)>=0.5, edges = edges(edges<0.5); end
