disp('Please say "A" for 2 seconds.');

annoy = 1;


[orig short fft]=recprep(16,8000,2,1);

if(max(short) > 32760)		%  If it hits the max, then try again.
   	disp('Too loud!  Clipping present.');
   	sound(clip);
	
else				%  Not too noisy--go ahead with life
	[peaks maxval]=peak(fft(1:4000));
	if(length(peaks) ~= 0)	%  As long as you have peaks, make a peak picture
 		maxval=maxval/max(maxval);
  		figure(3);
		stem(maxval);
	end

	if(length(peaks) == 0)	%  If you don't have any peaks, tell them, and exit 
		sound(tryagain);
		disp('No signal');
	elseif (length(peaks) > 15)	%  If there were too many peaks, tell them, and exit 
		sound(tryagain);
		disp ('Noise');
	elseif ((length(peaks) > 5) & (length(peaks) < 11))	% If the numpeaks > 5 & < 11--boys.
		  
%%%%%%%%%%%%%%%% boys--tracy = 1, herman = 0, no id = 2  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		disp ('Boys');
		tracy = 2;

% test 3:
  		if(maxval(2) > .90)   % If the second peak is large, then tracy
			disp('test3');
			tracy = 1;
		end


% test 6:
  		if(maxval(3) > .95)	%  If the third peak is large, then tracy
			disp('test6');
			tracy  = 1;
  		end;


% test 1:
  		if( (maxval(2) > maxval(3)) & (maxval(3) < maxval(4)) & ((maxval(2) - maxval(4)) < .15))
		%  If the second and fourth peak are similar, and the third peak is smaller than second:
			if(maxval(2)+maxval(3)+maxval(4) > 1.3)  %if the sum of the three is big--tracy
	     			disp('test1');
				tracy = 1;
	 	       	end
		elseif( (maxval(2) > maxval(3)) & (maxval(3) < maxval(4)) & ((maxval(2) - maxval(4)) > .25))
		%  If the second peak is much bigger than the fourth, and the third peak is smaller than both:	
			if((maxval(4)-maxval(3) < .2) & (maxval(3)+maxval(4) < .9))
			%  and the difference between 3 & 4 isn't much, but their sum has a lot of energy--herm
		 	   disp('test1b');
			   tracy = 0;
		        else
			%  otherwise--no clue
			   disp('test1c');
			   tracy=2;
        		end
		end

% test 7:
		if((maxval(4)-maxval(3) > .21) & (maxval(5) < .4))
		%  If the fourth peak is bigger than the third, and the fifth is not that big--tracy
			disp('test7');
			tracy=1;
		end

% test 8:
  		
		if((maxval(2)-maxval(3) > .3) & (maxval(5) < .5) & (maxval(3) > maxval(2)))
		%  If the 2nd is bigger than the 3rd, and the 5th is small, and the 3rd is bigger than the 2nd--tracy
			disp('test8');
			tracy=1;
		end
  
% test 2:

		if((maxval(2) - maxval(3) > .02) & (maxval(3) - maxval(4) > .02) & (maxval(2) < .8))
		%  If the 2nd is bigger than the 3rd, and the 3rd is bigger than 4th, and the 2nd is big:
	        	if(maxval(2)+maxval(3)+maxval(4) <  1)
			%  and the 2nd+3rd+4th has a good deal of energy--herman
		    		disp('test2');
			    	tracy = 0;
		        end

	  	end

  		
% test 4:
		if(maxval(4) > .90)   %  If 4th peak is big
			disp('test4');
	     		tracy = 1;
	  	end

  		if(maxval(3)-maxval(2) > .1)	%  If 3rd is a good bit above 2nd--herm
			disp('test5');
			tracy=0;
	  	end


		%%%%%%  Make the sounds based on the decision  %%%%%%
  		if(tracy == 1)
	     		disp('Tracy');
		     	if(annoy)
        			sound([thankYou;t;haveANiceDay]*10000);	
   			else
       				sound(t);      
     			end
	  	elseif(tracy==0)
     			disp('Herm');
			if(annoy)
     				sound([thankYou;hreal;haveANiceDay]);
			else     
				sound(hreal);
			end
  		elseif(tracy==2)
     			disp('No positive id');
     			sound(noid);
	  	end
	


	elseif ((length(peaks) > 2) & (length(peaks) < 5))   %  Girls have numpeaks > 2 and < 5 
%%%%%%%%%%%%%%%%%% girls--court = 1, shermay = 0,  no positive id = 2  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  		court = 0;

  		disp('Girls');
		%  if ((maxval(2) - maxval(3)) > .08) | ((maxval(2)+maxval(3)) < .6) 
		%     court = 1;
		%  end


  		tmpval = maxval(2)-maxval(3);

		%  if((tmpval > .08) & ((maxval(2)+maxval(3)) < .65))
		%	disp('test1');
		%      court = 1;
		%  end

% test 2:
  		if((tmpval > .08) & ((maxval(2)+maxval(3)) > .65))   %  If difference is big, and energy is too--smy
			disp('test2');
			court = 0;
  		end

% test 3:
  		if( abs(tmpval) < .08)	% if difference is small--smy
		  	disp('test3');
			court = 0;
		end

% test 4:

  		if((maxval(2)+maxval(3) > .55) & (maxval(2)+maxval(3)) < .65)   %  if energy is medium--don't know
			disp('test4');
			court = 2;
		end


% test 1:

  		if(maxval(2)+maxval(3) < .55) % if energy is small--court
			disp('test1');
			court = 1;
		end

% test 5:
  
  		if((maxval(3) > maxval(2)) & ~court)  % if upsloping and energy is low--smy
			disp('test5');
			court = 0;
  		end


% test 6:
  		if(court & (maxval(3) < .08))	% if low energy and almost no last peak--female imposter
     			disp('test6');
			court=3
  		end

% test 7:
  		if(maxval(3) > .95)	% if big third peak--court
			disp('test7')
			court = 1;
  		end




		%%%%%  Make the sounds based on the decision  %%%%
  		if(court == 1)
    			%% Courtney
    			disp ('Courtney');
    			if(annoy)
       				sound([thankYou;c;haveANiceDay]);
    			else
       				sound(c);
    			end
  		elseif(court==0)
    			disp ('Shermay');
    			if(annoy)
       				sound([thankYou;s;haveANiceDay]);
    			else
       				sound(s);
    			end
  		elseif(court==2)
    			disp('No positive ID.');
    			sound(noid);
  		else
    			disp('Female imposter!');
    			sound(femimp);
	 	end

 	else  % Number of peaks is not right-- < 2 or ( > 11 and < 15)
		disp('No positive ID');
 		sound(noid);
	end

end
figure(1);
