Line 90: Line 90:
 
wavwrite(z,44100,32,'Hail_Purdue_rescaled.wav');
 
wavwrite(z,44100,32,'Hail_Purdue_rescaled.wav');
 
</pre>
 
</pre>
 +
 +
 +
== Sound Files ==
 +
[[Media:Hail_Purdue_ECE301Fall2008mboutin.wav]]
 +
[[Media:Hail_Purdue_faster_ECE301Fall2008mboutin.wav]]
 +
[[Media:Hail_Purdue_rescaled_ECE301Fall2008mboutin.wav]]

Revision as of 06:37, 5 September 2008

MATLAB Code to Play Hail Purdue

%Zachary Curosh
%ECE 301, Homework 1.1
%9/5/2008
clear;
clc;

%We were given the fact that an A is 440 Hz. Using the equations given on
%the homework sheet, I was able to calculate the other notes needed.

x=440*3/5;
UpperC=2*x;
B=15*x/8;
A=440;
G=3*x/2;
F=4*x/3;
E=5*x/4;
D=9*x/8;
MiddleC=x;

%The length of notes are defined below

delta = 1/20000;
eigth = .125; %Eigth Note
quarter = .25; %Quarter Note
half = .5; %Half Note
threequarter = .75; %Three Quarters Note
whole = 1; %Whole Note

%I got the following notes to Hail Purdue from a couple of websites.

H_Purdue = [E, F, G, A, B, UpperC, UpperC, D, D, D, A, B, B, UpperC];

Timing = [half, quarter, quarter, quarter+eigth, eigth, quarter, quarter, ...
    quarter, eigth, eigth, quarter, eigth, eigth, half+quarter];

%Now, to play the song at normal speed

c1=1;
for lcv=1:14
    t=0:delta:Timing(lcv);
    x=sin(2*pi*t*H_Purdue(lcv));
    c2=1;
    while c2<length(x)
        HailPurdue(c1)=x(c2);
        c1=c1+1;
        c2=c2+1;
    end
end
sound(HailPurdue,1/delta);

pause(3);

%Now play the song twice as fast
c1=1;
for lcv2=1:14
    t2=0:delta:0.5*Timing(lcv2);
    y=sin(2*pi*t2*H_Purdue(lcv2));
    
    c2=1;
    while c2<length(y)
        Hail.Purdue.twice(c1)=y(c2);
        c1=c1+1;
        c2=c2+1;
    end
end
sound(Hail.Purdue.twice,1/delta);

pause(3);

%Now play the song rescaled y(t)=x(2t)
c1=1;
for lcv2=1:14
    t2=0:delta:Timing(lcv2);
    z=sin(2*pi*t2*2*H_Purdue(lcv2));
    
    c2=1;
    while c2<length(z)
        Hail.Purdue.rescale(c1)=z(c2);
        c1=c1+1;
        c2=c2+1;
    end
end
sound(Hail.Purdue.rescale,1/delta);

%now to write each of the songs to a file
wavwrite(x,44100,32,'Hail_Purdue.wav');
wavwrite(y,44100,32,'Hail_Purdue_faster.wav');
wavwrite(z,44100,32,'Hail_Purdue_rescaled.wav');


Sound Files

Media:Hail_Purdue_ECE301Fall2008mboutin.wav Media:Hail_Purdue_faster_ECE301Fall2008mboutin.wav Media:Hail_Purdue_rescaled_ECE301Fall2008mboutin.wav

Alumni Liaison

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

Dr. Paul Garrett