% notes.m sets up and plays single tones, a scale, and two chords p=2^(1/12); % frequency multiplier between notes t=0:(1/44100):1; % vector of time indices a =sin(440*2*pi*t); % define naturals and sharps %as=sin(440*(p^1)*2*pi*t); b =sin(440*(p^2)*2*pi*t); %c =sin(440*(p^3)*2*pi*t); cs=sin(440*(p^4)*2*pi*t); d =sin(440*(p^5)*2*pi*t); %ds=sin(440*(p^6)*2*pi*t); e =sin(440*(p^7)*2*pi*t); %f =sin(440*(p^8)*2*pi*t); fs=sin(440*(p^9)*2*pi*t); %g =sin(440*(p^10)*2*pi*t); gs=sin(440*(p^11)*2*pi*t); a2=sin(440*(p^12)*2*pi*t); % a one octave up a3=sin(440*(p^24)*2*pi*t); % another octave up clf; % clear the figure subplot(5,1,1) plot(t,a) axis([0 0.05 -4 4]) title('A (440 Hz)'); ylabel('Speaker location'); xlabel(' Time (seconds)'); drawnow sound([a a a a],44100) % play the a four times in a row wavwrite([a a a a],44100,16,'Pure_A_440_Hz'); %pause % press a key to continue subplot(5,1,2) plot(t,a2) axis([0 0.05 -4 4]) title('A (880 Hz)'); drawnow sound([a2 a2 a2 a2],44100) %pause wavwrite([a2 a2 a2 a2],44100,16,'Pure_A_880_Hz'); subplot(5,1,3) i=(1:length(a3))/44100; plot(t,a3.*i) axis([0 0.05 -0.1 0.1]) title('A (1760 Hz) getting louder'); drawnow i=(1:length(a3))/44100; sound([a3.*i a3.*i a3.*i a3.*i],44100) %pause wavwrite([a3.*i a3.*i a3.*i a3.*i],44100,16,'Pure_A_1760_Hz_getting_louder'); subplot(5,1,4) chord1 = a+cs+e; % superimpose the notes for a chord chord1 = chord1/max(abs(chord1)); plot(t,chord1) axis([0 0.05 -4 4]) title('A-C#-E chord (440, 554, 659 Hz)'); drawnow sound([chord1 chord1 chord1 chord1], 44100) % play the chord %pause wavwrite([chord1 chord1 chord1 chord1],44100,16,'A_Cs_E_chord'); subplot(5,1,5) chord2 = a+cs+e+3*a2; % broaden the chord chord2 = chord2/max(abs(chord2)); plot(t,chord2) axis([0 0.05 -6 6]) title('A-C#-E-A2 chord (440, 554, 659, 880 Hz)'); drawnow sound([chord2 chord2 chord2 chord2], 44100) wavwrite([chord2 chord2 chord2 chord2],44100,16,'A_Cs_E_A2_chord'); %clf; scale=[a b cs d e fs gs a2]; sound(scale,44100) % play a little scale wavwrite(scale,44100,16,'A_440_A_880_scale'); %pause z =sin(20*2*pi*t); wavwrite([z z z z],44100,16,'20_Hz'); z =sin(60*2*pi*t); wavwrite([z z z z],44100,16,'60_Hz'); z =sin(80*2*pi*t); wavwrite([z z z z],44100,16,'80_Hz'); z =sin(100*2*pi*t); wavwrite([z z z z],44100,16,'100_Hz'); z =sin(120*2*pi*t); wavwrite([z z z z],44100,16,'120_Hz'); z =sin(10000*2*pi*t); wavwrite([z z z z],44100,16,'10000_Hz'); z =sin(16000*2*pi*t); wavwrite([z z z z],44100,16,'16000_Hz'); z =sin(20000*2*pi*t); wavwrite([z z z z],44100,16,'20000_Hz');