function fletcher (bandwidth, freq, Start);
%
% measurement of the Critical Band (Thomas Koelewijn en Jasper Poort)
% bandwidth and freq in Hz  Example: fletcher(1000, 2000)
%

if nargin<3 
   Start = 60; 
end
toneA = tone(freq, Start, 1000);

noise = gengwn(50000); 
noise = [noise, noise];
lcut = (freq - (bandwidth/2))/25000;
noise = highpass (noise, lcut, 200);
Rcut = (freq + (bandwidth/2))/25000;
noise = lowpass (noise, Rcut, 200);

all = toneA + noise;
Playsound(all);
figure(3);
clf
psd(all(:,1), 256, 50000, 100);
hold on;

R = 'i'; %intialisatie
x=Start;

while R ~= 'x'
   
   R = input('do you hear the tone ? no (n) or yes (y) or exit (x) ?', 's');

if R == 'n'
   x=x+1
   %toneA = monotone(freq,x,1000);
   toneA = tone(freq,x,1000);
   all = toneA + noise;
   Playsound(all);
   
     
elseif R == 'y' 
   x=x-1
   %toneA = monotone(freq,x,1000);
	toneA = tone(freq,x,1000);
   all = toneA + noise;
   Playsound(all);


elseif R == 'x' 
    x  
    
    figure(3)
    psd(all(:,1), 256, 50000, 100);
end

end