function bc = synchronisechroma(chromag, beats, frame_t)

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

bc = ones(nBeat,size(chromag,1));
chromag(:,isnan(sum(chromag))) = 1;

if size(beats,2) < 2
    for iBeat = 1:nBeat-1
        currind = find(frame_t >= beats(iBeat) & frame_t < beats(iBeat+1));
        bc(iBeat,:) = median(chromag(:,currind),2);
        if ~any(isnan(bc(iBeat,:)))
            bc(iBeat,:) = bc(iBeat,:)/max(bc(iBeat,:));
        end
    end
else
    for iBeat = 1:nBeat
        currind = (frame_t >= beats(iBeat,1) & frame_t < beats(iBeat,2));
        bc(iBeat,:) = median(chromag(:,currind),2);
        if ~any(isnan(bc(iBeat,:)))
            bc(iBeat,:) = bc(iBeat,:)/max(bc(iBeat,:));
        end
    end
end