(New page: == MATLAB Code to Play Hail Purdue == <pre> %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 hom...)
 
Line 31: Line 31:
 
%I got the following notes to Hail Purdue from a couple of websites.
 
%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];
+
H_Purdue = [E, F, G, A, B, UpperC, UpperC, D, D, D, A, B, B, UpperC];
  
Timing = [half, quarter, quarter, (quarter+eigth), eight, quarter, ...
+
Timing = [half, quarter, quarter, quarter+eigth, eigth, quarter, quarter, ...
     quarter, quarter, eigth, eigth, quarter, eigth, eigth, (half+quarter)];
+
     quarter, eigth, eigth, quarter, eigth, eigth, half+quarter];
  
 
%Now, to play the song at normal speed
 
%Now, to play the song at normal speed
  
 +
c1=1;
 
for lcv=1:14
 
for lcv=1:14
 
     t=0:delta:Timing(lcv);
 
     t=0:delta:Timing(lcv);
     x(lcv)=sin(2*pi*t*Hail_Purdue(lcv));
+
     x=sin(2*pi*t*H_Purdue(lcv));
     sound(x(lcv),1/delta);
+
     c2=1;
 +
    while c2<length(x)
 +
        HailPurdue(c1)=x(c2);
 +
        c1=c1+1;
 +
        c2=c2+1;
 +
    end
 
end
 
end
 +
sound(HailPurdue,1/delta);
  
 
pause(3);
 
pause(3);
  
 
%Now play the song twice as fast
 
%Now play the song twice as fast
 
+
c1=1;
for lcv=1:14
+
for lcv2=1:14
     t=0:delta:0.5*Timing(lcv);
+
     t2=0:delta:0.5*Timing(lcv2);
     y(lcv)=sin(2*pi*t*Hail_Purdue(lcv));
+
     y=sin(2*pi*t2*H_Purdue(lcv2));
     sound(y(lcv),1/delta);
+
      
 +
    c2=1;
 +
    while c2<length(y)
 +
        Hail.Purdue.twice(c1)=y(c2);
 +
        c1=c1+1;
 +
        c2=c2+1;
 +
    end
 
end
 
end
 +
sound(Hail.Purdue.twice,1/delta);
  
 
pause(3);
 
pause(3);
  
 
%Now play the song rescaled y(t)=x(2t)
 
%Now play the song rescaled y(t)=x(2t)
 
+
c1=1;
for lcv=1:14
+
for lcv2=1:14
     t=0:delta:Timing(lcv);
+
     t2=0:delta:Timing(lcv2);
     z(lcv)=sin(2*pi*t*2*Hail_Purdue(lcv));
+
     z=sin(2*pi*t2*2*H_Purdue(lcv2));
     sound(z(lcv), 1/delta);
+
      
 +
    c2=1;
 +
    while c2<length(z)
 +
        Hail.Purdue.rescale(c1)=z(c2);
 +
        c1=c1+1;
 +
        c2=c2+1;
 +
    end
 
end
 
end
 +
sound(Hail.Purdue.rescale,1/delta);
  
 
%now to write each of the songs to a file
 
%now to write each of the songs to a file

Revision as of 09:47, 4 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');

Alumni Liaison

Meet a recent graduate heading to Sweden for a Postdoctorate.

Christine Berkesch