function [precision,recall,f_measure] = evaluateChordAnnotation(X,F,T,filename,parameter)


if parameter.ChordRec && parameter.visualize
    parameter.visualize = 1;
else
    parameter.visualize = 0;
end


[f_chroma] = TFR_to_chroma(X,F,parameter);
% if parameter.visualize
%     visualize_chroma(f_chroma,parameter);
%     title('CHROMA');
% end




templateChords = chordTemplates(parameter);


select = [1:24];
templateChordsSelected = templateChords;
nonSelected = setdiff([1:24],select);
for n=1:size(nonSelected,2)
    templateChordsSelected(:,nonSelected(n)) = ones(12,1)*NaN;
end

f_distance = 1 - templateChordsSelected' * f_chroma';

numSamples = size(f_chroma,1);
numChords =  size(templateChordsSelected,2);


if 1
    [f_min,f_chordIndex] = min(f_distance,[],1);
    chord_matrix = zeros(numChords,numSamples);
    for n=1:numSamples
        chord_matrix(f_chordIndex(n),n)=1;
    end
else
    chord_matrix = f_distance;
    chord_matrix = (chord_matrix  < thresholdDistance);

end

% figure; imagesc(chord_matrix)


labfile = strcat(parameter.directoryLab,filename(1:end-3),'lab');
segmentation = readSegmentationAnnotation(labfile);



labels = {segmentation.label}';
parameter.chordClass = 0;
labels_out = discard_chord_annotations(labels,parameter);
discard = strcmp(labels_out,'N');
segmentation = segmentation(~discard);

labels = {segmentation.label}';
labels_simplified = simplify_chord_annotations(labels);

[labels_indices,chordLabelsVis] = chordLabel_to_chordIndex(labels_simplified);

numLabels = size(labels,1);
for k=1: numLabels
    segmentation(k).label = labels_indices(k);
end



parameter.numSamples = size(chord_matrix,2);
parameter.numChords = 24;

chordMatrix_groundTruth = segmentation_to_matrix(segmentation,parameter);


[precision,recall,f_measure] = evaluate_matrix1_matrix2(chord_matrix,chordMatrix_groundTruth,parameter);

fprintf('%i %-50s P:%1.3f R:%1.3f F:%1.3f\n',parameter.featureType, filename(1:min(length(filename),50)),precision, recall,f_measure);
