%Adrian Delancy clear all %Finding Frequencies (v) of notes: for n=0:11; v(1+n)= 220*2.^(n/12); end A=v(1); Bb=v(2); B=v(3); C=v(4);%Middle C Db=v(5); D=v(6); Eb=v(7); E=v(8); F=v(9); Gb=v(10);%(F#) G=v(11); Ab=v(12);%(G#) bpm =30; %Specify beats per minute bps=bpm/60; delta = 0.0005; d=1/delta;%Sampling rate %Defining note values eg. quaver (q),half-note etc... cr =0:delta:bps;%crotchet or quater note - 1 beat dotcr=0:delta:bps*(3/2);%dotted quater note or crotchet - 3/2 beats h=0:delta:bps*2;%Half note or minim - 2 beats wh=0:delta:bpm*4;%Whole note - 4 beats doth = 0:delta:bps*3;%dotted minim - 3 beats q=0:delta:bps/2;%quaver or eighth note - 1/2 beat dotq=0:delta:bps*0.75;% - dotted quaver - 3/4 beat k=2*pi; %Playing the first part of chours in the key of A flat (Ab) in 2/4 time: y = [sin(k*Eb*h) sin(k*F*cr) sin(k*G*cr) sin(k*Ab*dotcr) sin(k*Bb*2*q) sin(k*2*C*cr) sin(k*C*2*cr) sin(k*Db*2*cr) sin(k*Db*2*q) sin(k*Db*2*q) sin(k*Ab*cr) sin(k*Bb*2*q) sin(k*B*2*q) sin(k*C*2*doth)]; sound(y,d); %Playing the tune twice as a fast: bpm =15; bps=bpm/60; delta = 0.0005; d=1/delta; %Defining note values eg. quaver (q),half-note etc... cr1 =0:delta:bps; dotcr1=0:delta:bps*(3/2); h1=0:delta:bps*2; wh1=0:delta:bpm*4; doth1 = 0:delta:bps*3; q1=0:delta:bps/2; dotq1=0:delta:bps*0.75; k=2*pi; %Playing in the key of A flat (Ab): y1 = [sin(k*Eb*h1) sin(k*F*cr1) sin(k*G*cr1) sin(k*Ab*dotcr1) sin(k*Bb*2*q1) sin(k*2*C*cr1) sin(k*C*2*cr1) sin(k*Db*2*cr1) sin(k*Db*2*q1) sin(k*Db*2*q1) sin(k*Ab*cr1) sin(k*Bb*2*q1) sin(k*B*2*q1) sin(k*C*2*doth1)]; sound(y1,d); %Rescaling the original tune: y = [sin(k*Eb*(2*h)) sin(k*F*cr*2) sin(k*G*cr*2) sin(k*Ab*dotcr*2) sin(k*Bb*4*q) sin(k*4*C*cr) sin(k*C*4*cr) sin(k*Db*4*cr) sin(k*Db*4*q) sin(k*Db*4*q) sin(k*Ab*2*cr) sin(k*Bb*4*q) sin(k*B*4*q) sin(k*C*4*doth)]; sound(y,d);