HW1, ECE301, Prof. Boutin
In this homework assignment, we were asked to write a Matlab code to play the "Hail Purdue" song with different speeds and pitch. Here are my results:
Sound File
M-File
% Jun Hyeong Park % ECE 301 HW #1_ Playing music for a=0:18 f(a+1)=220*2^(a/12); end A=f(1); % la Bb=f(2); % ti flat B=f(3); % ti C=f(4); % do Db=f(5); % re flat D=f(6); % re Eb=f(7); % mi flat E=f(8); % mi F=f(9); % fa Gb=f(10); % so flat G=f(11); % so A2b=f(12); % upper la flat A2=f(13); % upper la B2b=f(14); % upper ti falt B2=f(15); % upper ti C2=f(16); % upper do D2b=f(17); % upper re flat D2=f(18); % upper re E2b=f(19); % upper mi flat M=0; % Mute % when I saw a music score of Hail Purdue, bpm was 140. 140bpm means % 140 quarter notes per a minute. It means that 1 quarter note per 0.43 seconds. P=0.43; % 1 quarter note TP=P*2; % 2 - quarter FP=P*4; % 1 THP=P*3; % 3 - quarter QP=P*1.5; % 3 - 8 H=P/2; % half time notes=[Eb,F,G,A2b,G,A2b,G,A2b,G,A2b,B2b,A2b,Eb,F,G,M, ... G,A2b,A2,B2b,A2,B2b,A2,B2b,A2,B2b,C2,B2b,Eb,D2b,C2,M, ... Eb,F,G,A2b,G,A2b,G,A2b,G,A2b,E2b,C2,B2b,A2b,D2b,A2b,A2b ... B2b,B2b,B2,B2,C2,D2b,E2b,C2,B2b,A2b,C2,B2b, ... B2b, ... Eb,F,G,A2b,B2b,C2,C2,D2b,D2b,D2b,A2b,B2b,B2,C2, ... C2,C2,B2b,A2b,B2b,C2,C2,B2b,F,G,A2b,G,F,B2b, ... Eb,Eb,F,G,A2b,B2b,C2,C2,C2, ... D2b,D2b,A2b,B2b,C2,M,F,G, ... A2b,F,Eb,A2b,C2,Eb,C2,B2b,A2b,A2b]; duration=[P,P,P,P,P,P,H,H,H,H,P,P,P,P,THP,P, ... P,P,P,P,P,P,H,H,H,H,P,P,P,P,THP,P, ... P,P,P,P,P,P,H,H,H,H,P,P,P,P,THP,H,H ... QP,H,QP,H,QP,H,H,H,H,H,TP,TP, ... FP, ... TP,P,P,QP,H,P,P,P,H,H,P,H,H,FP, ... TP,P,P,QP,H,P,P,P,H,H,P,H,H,FP, ... QP,H,P,P,QP,H,P,H,H, ... P,P,P,P,THP,P,QP,H, ... P,P,P,P,TP,QP,H,QP,H,THP]; delta = 0.00005; % Question #1.a for n= 1:117 % number of notes = 117 t=0:delta:duration(n); % normal speed x=sin(2*pi*t*notes(n)); % sine wave sound(x,1/delta); % play a song end pause(1) % Question #1.b for n= 1:117 t=0:delta:duration(n)*0.5; % becomes faster twice. x=sin(2*pi*t*notes(n)); % sine wave sound(x,1/delta); % I can hear a song that is played at double speed. end pause(1) % Question #1.c for n= 1:117 t=0:delta:duration(n); % normal speed y=sin(2*pi*2*t*notes(n)); % rescale y(t) = x(2t) sound(y,1/delta); % The frequencies become twice % It means an octave is raised. end