Sound Files

Matlab Code

%Phil Cannon 
%pjcannon@purdue.edu
%ECE301 HW1_1

%This file takes roughly 30 seconds to compile completely and will play
%three different versions of 'Hail Purdue'.  Note: When the wave files are
%created MatLab produces a warning, but it doesn't seem to do anything.

delta=0.00005;

%Declare notes and note lengths
%Taken from:
%http://it4musos.com/audio_workshop/guitar%20note%20frequencies.jpg
Eflat=311; E=329; F=349; Gflat=370; G=392;
Aflat=415; A=440; Bflat=466; B=494; C=523; Dflat=554;

E=.125;
Q=.25;
H=.5;
HQ=H+Q;
DotQ=Q+(.5*Q);

%Array of notes for 'Hail Purdue!'
%Taken from: 
%http://www.purdue.edu/bands/media/Sounds/aamb/Hail%20Purdue%20Piano%20Sheet.pdf
Notes = [Eflat, F, G, Aflat, Bflat, C, C, Dflat, Dflat, Dflat, Aflat, Bflat, B, C];
NLength = [HQ, Q, Q, DotQ, E, Q, Q, Q, E, E, Q, E, E, HQ];

%Part A.  Compiles 'Hail Purdue'.
c1=1;
for counter=1:(length(Notes))
    
    t=0:delta:NLength(counter);
    d=sin(2*pi*t*Notes(counter));
    
    c2=1;
    while c2<length(d)
        HailPurdue(c1)=d(c2);
        c1=c1+1;
        c2=c2+1;
    end
end
fprintf('Part 1 compiled...')

%Part B.  Compiles 'Hail Purdue', but twice as fast.
c1=1;
for counter2=1:(length(Notes))
    
    t2=0:delta:.5*NLength(counter2);
    d2=sin(2*pi*t2*Notes(counter2));
    
    c2=1;
    while c2<length(d2)
        HailPurduex2(c1)=d2(c2);
        c1=c1+1;
        c2=c2+1;
    end
end
fprintf('\nPart 2 compiled...')

%Part B.  Compiles 'Hail Purdue', but twice the pitch.
c1=1;
for counter3=1:(length(Notes))
    
    t3=0:delta:NLength(counter3);
    d3=sin(2*2*pi*t3*Notes(counter3));
    
    c2=1;
    while c2<length(d3)
        HailPurdueTrans(c1)=d3(c2);
        c1=c1+1;
        c2=c2+1;
    end
end
fprintf('\nPart 3 compiled...')
fprintf('Boiler up!\n')

sound(HailPurdue,1/delta);
sound(HailPurduex2,1/delta);
sound(HailPurdueTrans,1/delta);

wavwrite(HailPurdue, 20100, 'hw1_1a.wav');
wavwrite(HailPurduex2, 20100, 'hw1_1b.wav');
wavwrite(HailPurdueTrans, 20100, 'hw1_1c.wav');


Results

This problem took some time, but it was nice learning how to make and play Hail Purdue in Matlab. The only thing that bothered me was a warning produced in Matlab when using wavwrite, however it didn't seem to be doing anything noticeable.

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett