
% logft.m  7/99  from logft.c
%    uses kernels calc from genlgftkern.m
% View with:
%  waterfall(cq)  
%   view(0, 40)
% 
%  Must run genlgftkern  FIRST to have the kernels
% Example:    cq = logft(vsc32, 512,  kerncos, kernsin,  windsizmax, nfreqs);
% NB: kernels + windsizmax and nfreqs have been returned by running genlgftkern
%  returns rows of length nfreqs

        function  [cq, time]  = logft(infile,hopsiz, kerncos, kernsin,  windsizmax, nfreqs, SR, ccx);

% infile = vsc11;
% hopsiz = 256;
% 
% infile has to be a column array
[nrows ncols] = size(infile);

if ncols ~= 1 & nrows ~= 1

   error('infile not a row or col array');

elseif ncols ~= 1

   infile = infile';

end


% fprintf('logft: windsizmax= %.0f= %.1f ms  ;     nfreqs = %.0f \n', windsizmax,1000*windsizmax/SR,   nfreqs);
[nr nc] = size(kerncos);
if nc < windsizmax
	windsizmax = nc;
	fprintf('logft: NOTE: winsizmax longer than need for this minfreq; changing to %.0f = %.1f ms(freq=%.0f)\n', nc, 1000*nc/SR, SR/nc);
end
nhops = 1 + floor((length(infile)-windsizmax)/hopsiz) ;
cq = zeros(nfreqs, nhops);

    for jj = 0:nhops-1
	 	ninit = jj*hopsiz+1;
 		nfnl  =  jj*hopsiz +1 + windsizmax - 1;
		%	fprintf('%.0f\t %.0f\n',ninit, nfnl);
		infile2 = infile(ninit:nfnl);
	 	reOinfil = kerncos * infile2;
	 	imOinfil = kernsin * infile2;
        if ccx == 1,
            cq(:,jj+1) = reOinfil  +  i * imOinfil;
        else
 		    cq(:,jj+1) = ((reOinfil .^ 2) + (imOinfil .^ 2)) .^(.5);
        end
    end
    cq = cq';
    [rowcq collcq] = size(cq);
    time = (hopsiz / SR )  * [1 : rowcq] ;
        
    % semilogx(freqs, cq)
    % waterfall(freqs, time, cq);
