% Program song1a.m % Prepared by S. Scott Moor, IPFW August 2004 % Based on suggestions from Shreekanth Mandayam, % Department of Electrical and Computer Engineering, Rowan University, % see http://users.rowan.edu/~shreek/networks1/music.html % % To play song simply type “song1a” at the command line % this file must be in the current directory or on the MATLAB path % % This program creates sine waves for a series of standard % notes. Each note is set up to be 0.5 seconds long at a % sample rate of 8000 Hz. The notes are assembled into a % song that is then played by the computer speaker. % variables used: % sf = sampling frequency (samples/sec) % x = time vector (sec.) % a, b, cs, d, e, & fs = the amplitude series for the notes used in the song % line1, line2, line3 = the amplitude series for each line of the song % song = the amplitude series for the entire song. % set up time series sf = 8000; x = 0:1/sf:0.5; % define each note a=sin(2*pi*440*x); b=sin(2*pi*493.88*x); cs=sin(2*pi*554.37*x); d=sin(2*pi*587.33*x); e=sin(2*pi*659.26*x); fs=sin(2*pi*739.99*x); % assembling the notes into a song line1 = [a,a,e,e,fs,fs,e,e]; line2 = [d,d,cs,cs,b,b,a,a]; line3 = [e,e,d,d,cs,cs,b,b]; song = [line1,line2,line3,line3,line1,line2]; % now we play the song sound(song, sf)