% %% Problem #2 - Homework 1 %%
% 
% % octave calculations
% fc = 1000;
% fl = fc/sqrt(2);
% fu = 2*fl;
% disp('Octave bands - upwards');
% while fu <= 23000
%     oct_band = [num2str(fl), ',', num2str(fc), ',', num2str(fu)];
%     disp(oct_band);
%     
%     fl = fu;
%     fu = 2*fl;
%     fc = sqrt(2)*fl;  
% end
% 
% fc = 1000;
% fl = fc/sqrt(2);
% fu = 2*fl;
% disp('Octave bands - downwards');
% while fl >= 15
%     oct_band = [num2str(fl), ',', num2str(fc), ',', num2str(fu)];
%     disp(oct_band);
%     
%     fu = fl;
%     fl = fu/2;
%     fc = sqrt(2)*fl;  
% end
% 
% disp('THIRD OCTAVE BANDS');
% fd = 2^(1/6);
% fc = 1000;
% fu = fc * fd;
% fl = fc / fd;
% while fu <= 23000 
%     third_oct_band1 = [num2str(fl), ',', num2str(fc), ',', num2str(fu)];
%     disp(third_oct_band1);
%     
%     fl = fu;
%     fc = fl * fd;
%     fu = fc * fd;
% end
% 
% fc = 1000;
% fu = fc * fd;
% fl = fc / fd;
% while fl >= 15
%     third_oct_band2 = [num2str(fl), ',', num2str(fc), ',', num2str(fu)];
%     disp(third_oct_band2);
%     
%     fu = fl;
%     fc = fu / fd;
%     fl = fc / fd;
% end

%% Problem #3 - Homework 1 %%

% low sweep frequency range
fl1 = 5;
fl2 = 40;

% sample rate
Fs = 44100;

% length of each sweep
endTime = 10;
t = 0:1/Fs:endTime;

flow = linspace(fl1, fl2, length(t));
lowsweep = square(2*pi.*flow.*t);
audiowrite('lowsweep.wav', lowsweep, Fs);

% high sweep frequency range
fh1 = 16000;
fh2 = 21000;

fhigh = linspace(fh2, fh1, length(t));
highsweep = sin(2*pi.*fhigh.*t);
audiowrite('highsweep.wav', highsweep, Fs);