Revision as of 08:07, 4 September 2008 by Zcurosh (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

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

Timing = [half, quarter, quarter, (quarter+eigth), eight, quarter, ...
    quarter, quarter, eigth, eigth, quarter, eigth, eigth, (half+quarter)];

%Now, to play the song at normal speed

for lcv=1:14
    t=0:delta:Timing(lcv);
    x(lcv)=sin(2*pi*t*Hail_Purdue(lcv));
    sound(x(lcv),1/delta);
end

pause(3);

%Now play the song twice as fast

for lcv=1:14
    t=0:delta:0.5*Timing(lcv);
    y(lcv)=sin(2*pi*t*Hail_Purdue(lcv));
    sound(y(lcv),1/delta);
end

pause(3);

%Now play the song rescaled y(t)=x(2t)

for lcv=1:14
    t=0:delta:Timing(lcv);
    z(lcv)=sin(2*pi*t*2*Hail_Purdue(lcv));
    sound(z(lcv), 1/delta);
end

%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');

Alumni Liaison

Abstract algebra continues the conceptual developments of linear algebra, on an even grander scale.

Dr. Paul Garrett