function tree=buildTree(maleClusters,femaleClusters,UBMmale,UBMfemale,GMM,mfccFolder)
%Organizes the database in a tree structure.
%Inputs:
% -(fe)maleClusters: cell array with arrays contaning speaker codes for
% each cluster;
% -UBMmale/UBMfemale is a struct with fields m(mean),v(variance) and
% w(weight). v and m are k*n matrices, where k is the number of gaussians
% used to build the UBM and n is the number of coefficients (in our case
% this is equal to 39);
% -GMM: cell array with GMM structs for each speaker. Each struct has
% fields code(number of the speaker), gender(male or female), m(mean),
% v(variance) and w(weight). Code is a number, gender is a string.
% v and m are k*n matrices, where k is the number of gaussians used to
% build the UBM and n is the number of coefficients (in our case this is
% equal to 39);
% -mfccFolder is the folder containing the MFCCs for each speaker in
% separate .mat files.
%Output:
% -tree is a struct array, where each struct is a GMM with an additional
% field named 'child', which contains another tree.
[maleGMM,femaleGMM]=adaptClusters(maleClusters,femaleClusters,UBMmale,UBMfemale,mfccFolder);
numClust = numel(maleClusters);
for i = 1:numel(numClust)
numComp = length(maleClusters{i});
for j = 1:numComp
for k = 1:numel(GMM)
if ((GMM{k}.code == maleClusters{i}(j)) && ...
strcmp(GMM{k}.gender,'male'))
child(j) = GMM{k};
end
end
end
maleGMM{i}.child = child;
maleData(i) = maleGMM{i};
end
numClust = numel(femaleClusters);
for i = 1:numel(numClust)
numComp = length(femaleClusters{i});
for j = 1:numComp
for k = 1:numel(GMM)
if ((GMM{k}.code == femaleClusters{i}(j)) && ...
strcmp(GMM{k}.gender,'female'))
child(j) = GMM{k};
end
end
end
femaleGMM{i}.child = child;
femaleData(i) = femaleGMM{i};
end
UBMmale.child = maleData;
UBMfemale.child = femaleData;
tree = [UBMmale,UBMfemale];