function[iloc,ival,iphase,previousiloc,previousival, ...
distminindex]=peakTrackSimple(nSines,nPeaks,N, ...
SR,pitchvalue,iftloc,iftval,iftphase,isHarm, ...
previousiloc,previousival);
% function[iloc,ival,iphase,previousiloc,previousival, ...
% distminindex]=peakTrackSimple(nSines,nPeaks,N, ...
% SR,pitchvalue,iftloc,iftval,iftphase,isHarm, ...
% previousiloc,previousival);
%
%==> simplest partial tracking
% data:
% iloc,ival,iphase: location (bin), magnitude
% and phase of peaks (current frame)
% previousiloc,previousival,previousiphase: idem for
% previous frame
% iftloc, iftval, iftphase: idem of all of the peaks in the FT
% distminindex: indexes of the minimum distance
% between iloc and iftloc
% nPeaks: number of peaks detected
% nSines: number of peaks tracked
% N: size of the FFT
% SR: sampling rate
% pitchvalue: estimated pitch value
% isHarm: indicator of harmonicity
tmpharm = pitchvalue; %--- temporary harmonic
iloc = zeros(nSines,1);
MindB = -100;
ival = zeros(nSines,1) + MindB;
iphase = zeros(nSines,1);
distminindex = zeros(nSines,1);
Delta = 0.01;
for i=1:nSines %--- for each sinus detected
if (isHarm==1) %--- for a harmonic sound
[closestpeakmag,closestpeakindex]=min(abs((iftloc-1)/N*SR-tmpharm));
tmpharm = tmpharm + pitchvalue;
else %--- for an inharmonic sound
[closestpeakmag,closestpeakindex]=min(abs(iftloc-previousiloc(i)));
end
iloc(i) = iftloc(closestpeakindex); %--- bin of the closest
ival(i) = iftval(closestpeakindex);
iphase(i) = iftphase(closestpeakindex);
dist = abs(previousiloc-iloc(i));
[distminval, distminindex(i)] = min(dist);
end