% function [] = trackplot(freq,amp)
%
% This function steps through a given matrix amp and finds continuous vectors of data
% along the columns (separated by zeros) and plots the corresponding values of freq
% matrix as lines vs. the row index.

function [] = trackplot(freq,amp)


born=1;
flag = 0;
freqhold=[];
count = 1;
pp = [];

[numpeaks,numtracks] = size(freq);
clg
hold on
for k = 1:numtracks  % for each column
born=1;flag=0;freqhold=[];count=1;pp=[];


	for i = 1:numpeaks   % find continuous vectors of data and plot them.
		if(flag==1 & born==1)  % found a zero and are at end of track so plot.
			plot(pp,freqhold,'b')
			flag = 0;
			freqhold = [];
			pp=[];
			count = 1;
			born = 0;
%		end
		elseif(amp(i,k)~=0 & born==1) % are still in a track get next guy.
			freqhold(count)=freq(i,k);
			pp(count) = i;
			count = count + 1;
%		end
		elseif(amp(i,k)~=0 & born==0) % just printed a track and now found a new one
			freqhold(count)=freq(i,k);
			pp(count)=i;
			count = count+1;
			born = 1;
		elseif(amp(i,k)==0 & born==1) % Have found a zero at the end of a track.
			flag = 1;
		else
		end		
	end
end
title('Frequency Tracks');
xlabel('Frame');
ylabel('Frequency (w)');