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

Normal Speed : Hail Purdue

2x Speed : Hail Purdue

Normal Speed : Hail Purdue

Matlab Code

%Wei Jian Chan
%ECE 301 homework 1.1
%Hail Purdue based on E.J. Wotawa simplified by myself
%Score Source : http://www.sibeliusmusic.com/cgi-bin/show_score.pl?scoreid=105548

%Define the Sampling frequency and the pace of the song
Pace = 140;
Smp_fre = 1/20000;

%The delay for each note 
%since there is 140 Crotchets in a minute, therefore :
C = 60/Pace;
M = 60/(Pace/2);
B = 60 /(Pace/4);
Q = 60/(Pace*2);
SQ = 60/(Pace*4);
DM = M + C;
DDM = M + C + Q;
DC = C + Q;

%Note Frequency 
%Based on the frequency i found on the web
%Source : http://www.phy.mtu.edu/~suits/notefreqs.html

C4  = 261.63; 
Db4 = 277.18; 
D4  = 293.66;
Eb4 = 311.13; 
E4  = 329.63; 
F4  = 349.23; 
Gb4 = 369.99; 
G4  = 392.00;
Ab4 = 415.30;
A4  = 440.00;
Bb4 = 466.16;
B4  = 493.88;
C5  = 523.25;
Db5 = 554.37;
D5  = 587.33;
Eb5 = 622.25;
E5  = 659.26;
F5  = 698.46; 
Gb5 = 739.99;
G5  = 783.99;
Ab5 = 830.61;
A5  = 880.00;
Bb5 = 932.33;
B5  = 987.77;
Re  = 0;

%Set up vectors for the notes of the songs 
Notes = [Eb4 F4 G4 Ab4 G4 Ab4 G4 Ab4 G4 Ab4 Bb4 Ab4 Eb4 F4 G4 Re ...
         G4 Ab4 A4 Bb4 A4 Bb4 A4 Bb4 A4 Bb4 C5 Bb4 Eb4 Db5 C5 Re  ...
         Eb4 F4 G4 Ab4 G4 Ab4 G4 Ab4 G4 Ab4 Eb5 C5 Bb4 Ab4 Db5 Ab4 Ab4 ...
         Bb4 Bb4 B4 B4 C5 Db5 Eb5 C5 Bb4 G4 C5 Bb4 Ab4 Bb4 Re...
         Eb4 F4 G4 Ab4 Bb4 C5 C5 Db5 Db5 Db5 Ab4 Bb4 B4 C5 Re ...
         C5 C5 Bb4 Ab4 Bb4 C5 C5 Bb4 F4 G4 Ab4 G4 F4 Bb4 Bb4 Re Eb5 Re ...
         Eb4 Eb4 F4 G4 Ab4 Bb4 C5 C5 C5 Db5 Db5 Ab4 Bb4 C5 Re ...
         F4 G4 Ab4 F4 Eb4 Ab4 C5 Eb4 F4 C5 Bb4 Ab4 Ab4 Re];

%Set up time vector for the notes
Time = [C C C C C C Q Q Q Q C C C C DM C ...
        C C C C C C Q Q Q Q C C C C DM C ...
        C C C C C C Q Q Q Q C C C C DM Q Q ...
        DC Q DC Q DC Q Q Q Q Q M DC Q DDM Q...
        M C C DC Q C C C Q Q C Q Q DDM Q ...
        M C C DC Q C C C Q Q C Q Q M Q Q Q Q ...
        DC Q C C DC Q C Q Q C C C C DM C ...
        DC Q C C C C C C DC Q DC Q M C];

for i = 1:length(Notes)
    t = 0:Smp_fre:Time(i);
    Output = sin(2*pi*Notes(i)*t);
    Sound(Output, 1/Smp_fre);
end

pause(2)

% Song played at twice the speed
% The time is cut half
for i = 1:length(Notes)
    t = 0:Smp_fre:0.5*Time(i);
    Output = sin(2*pi*Notes(i)*t);
    Sound(Output, 1/Smp_fre);
end

pause(2)

% Song goes thru a tranformation 
% As for the same note for every octave, the note is twice the frequency of
% the previous note, thus the octave for the song is raised

for i = 1:length(Notes)
    t = 0:Smp_fre:Time(i);
    Output = sin(2*2*pi*Notes(i)*t);
    Sound(Output, 1/Smp_fre);
end

Alumni Liaison

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood