function Xcq = ecq(x, K)
% Xcq = ecq(x, K)
%
% Calculate the constant-Q transform of x, sampled at sr, using the efficient
% algorithm described in [1].
%
% K is the spectral kernel, which can be calculated using cqkern.
%
% 1. An efficient algorithm for the calculation of a constant Q transform
%    Judith C. Brown and Miller S. Puckette
%    J. Acoust. Soc. Am. 92 (5), November 1992

error(nargchk(2,2,nargin));

B = rows(K); % number of bins
N0 = columns(K); % FFT size

X = fft(vec(x), N0)';

Xcq = zeros(B,1);
for kcq = 1:B
    Xcq(kcq) = sum(X .* K(kcq,:)) / N0;
end
