ECA = zeros(HFFTS,nbInstrument);

for ins = 1:nbInstrument
   ECA(:,ins) = filterBasis * filterCoefficients(:,ins).*(excitationSpectrums{ins,curFrame}*partialsWeights(:,ins));
end

xHat = sum(ECA.*repmat(gains(:,curFrame)',HFFTS,1),2);

maskedSpectrogram = magnitude(:,curFrame).* basicSpec(:,curFrame) > 10^-4;


%Compute distance and r
distGain = sum(sum( maskedSpectrogram .* log((maskedSpectrogram+eps) ./ (xHat+eps)) - maskedSpectrogram + xHat));
r = (magnitude(:,curFrame)+eps)./(xHat+eps);

%Update Gain Coefficients
updateGainsCoeff = sum(ECA.*repmat(r,1,nbInstrument) +eps,1)./sum(ECA +eps,1);

clear ECA;
gains(:,curFrame) = gains(:,curFrame).*updateGainsCoeff';

%     figure;plot(gains');