MATLAB for Bonus
MATLAB for Bonus
%%
display('Critical Band Finder');
fc= input('Enter the center frequency in Hz: ');
fs= 44100;
t= 0: 1/fs: 2;
noise= 0;
for i= 0: 0.1: 10/0.1
noise= noise + (randn(1,1).*sin(2*pi*(fc - 5 + i).* t));
end
noise= noise ./ 3000;
display('This is the noise to listen for.');
pause(1);
sound(noise, fs);
display('Test Beginning)');
pause(1);
heard= 0;
in= 0;
i= 0;
while true
bw= 10 + i;
f1= fc - (bw/2);
f2= fc + (bw/2);
t1= sin(2*pi *f1 .* t) ./ 50;
t2= sin(2*pi *f2 .* t) ./ 50;
x= noise + t1 + t2;
sound(x, fs)
in= input('Could you hear the noise? (Enter 0 for no, 1 for yes, and 2 for repeat sound): ');
if in == 2
pause(0.5);
in= 0;
elseif in == 1 && heard == 0
heard= 1;
i= i - 20;
elseif heard == 1 && in == 0
i= i + 1;
elseif heard == 1 && in == 1
display(['Your critical bandwidth for ' int2str(fc) ' Hz is ' int2str(bw) ‘Hz’]);
break
elseif in ~= 0
in= 0;
i= i + 20;
else
i= i + 20;
end
end