function bc = beatchroma(chromag, beats, frame_t)

% assigning beats to frames
nBeat = length(beats);
nFrame = size(chromag, 2);
beatassign = zeros(1,nFrame);
iBeat = 1;

for iFrame = 1:nFrame
    if frame_t(iFrame) > beats(iBeat) && frame_t(iFrame) < beats(end)
        iBeat = iBeat + 1;
    end
    beatassign(iFrame) = iBeat;
end
% averaging over frames belonging to one beat
fprintf(1,'__ preprocessing chromagram... ___________________________________________\n');
bc = zeros(nBeat,12);
chromag(:,isnan(sum(chromag))) = 1;

for iBeat = 1:nBeat
    bc(iBeat,:) = median(chromag(:,beatassign == iBeat),2);
    if ~any(isnan(bc(iBeat,:)))
        bc(iBeat,:) = bc(iBeat,:)/max(bc(iBeat,:));
    end
end