(Sound File)
(Matlab Code)
Line 6: Line 6:
  
 
== Matlab Code ==
 
== Matlab Code ==
 +
%Paul Scheffler
 +
%phscheff@purdue.edu
 +
%ECE 301 HW1-1.m
 +
 +
clear
 +
clc
 +
 +
%Defining Note Frequencies
 +
x=264;
 +
C=x;
 +
B=15*x/8;
 +
A=5*x/3;
 +
G=3*x/2;
 +
F=4*x/3;
 +
E=5*x/4;
 +
D=9*x/8;
 +
hC=2*C;
 +
hG=2*G;
 +
hE=2*E;
 +
hF=2*F;
 +
hB=2*B;
 +
hD=2*D;
 +
hA=2*A;
 +
 +
%Define Note Lengths, 216 bpm(from sheet music).  60/216=quarternote
 +
Ql=60/175;
 +
Hl=2*Ql;
 +
Wl=4*Ql;
 +
El=Ql/2;
 +
Sl=Ql/4;
 +
 +
%Sampling Rate from class
 +
delta=.00005;
 +
 +
%Notes
 +
Note=[hE,hE,0,hE,0,hC,hE,hG,0,G,0,hC,G,0,F,F,A,B,B,A, ...
 +
    G,hE,hG,hA,F,hG,0,hE,hC,D,B,hC,G,0,E,E,A,B,B,A,G,hE,hG,hA,F,hG, ...
 +
    hE,hC];
 +
 +
%Lenth   
 +
NoteLength = [Ql,Ql,El,Ql,El,El,Ql,Ql,Ql,Ql,Ql,Ql,El,Ql,Ql,El,Ql,Ql,El,Ql, ...
 +
    Ql,Ql,Ql,Ql,Ql,Ql,El,Ql,Ql,Ql,Ql,Ql,El,Ql,Ql,El,Ql,Ql,El,Ql,Ql,Ql,Ql,Ql,Ql,Ql, ...
 +
    Ql,Ql];
 +
 +
%Normal Music
 +
n=numel(NoteLength);
 +
song = ones(1);
 +
for Count = 1:n;
 +
    t=0:delta:NoteLength(Count);
 +
    y=sin(2*pi*Note(Count)*t);
 +
    sound(y,1/delta);
 +
    song=[song,y];
 +
end
 +
 +
wavwrite(song, 44100, 32, 'Mario1.wav')
 +
pause(5)
 +
song = ones(1);
 +
for Count = 1:n;
 +
    t=0:delta:(1/2)*NoteLength(Count);
 +
    y=sin(2*pi*Note(Count)*t);
 +
    sound(y,1/delta);
 +
    song=[song,y];
 +
end
 +
wavwrite(song, 44100, 32, 'Mario2.wav')
 +
 +
%Up an Octave
 +
 +
pause(5)
 +
song = ones(1);
 +
for Count = 1:n;
 +
    t=0:delta:NoteLength(Count);
 +
    y=sin(2*2*pi*Note(Count)*t);
 +
    sound(y,1/delta);
 +
    song=[song,y];
 +
end
 +
wavwrite(song, 44100, 32, 'Mario3.wav')

Revision as of 13:32, 4 September 2008

Sound File

Sheet music for the sound file taken from here. Part 1. Part 2. Part 2.

Matlab Code

%Paul Scheffler %phscheff@purdue.edu %ECE 301 HW1-1.m

clear clc

%Defining Note Frequencies x=264; C=x; B=15*x/8; A=5*x/3; G=3*x/2; F=4*x/3; E=5*x/4; D=9*x/8; hC=2*C; hG=2*G; hE=2*E; hF=2*F; hB=2*B; hD=2*D; hA=2*A;

%Define Note Lengths, 216 bpm(from sheet music). 60/216=quarternote Ql=60/175; Hl=2*Ql; Wl=4*Ql; El=Ql/2; Sl=Ql/4;

%Sampling Rate from class delta=.00005;

%Notes Note=[hE,hE,0,hE,0,hC,hE,hG,0,G,0,hC,G,0,F,F,A,B,B,A, ...

   G,hE,hG,hA,F,hG,0,hE,hC,D,B,hC,G,0,E,E,A,B,B,A,G,hE,hG,hA,F,hG, ...
   hE,hC];

%Lenth NoteLength = [Ql,Ql,El,Ql,El,El,Ql,Ql,Ql,Ql,Ql,Ql,El,Ql,Ql,El,Ql,Ql,El,Ql, ...

   Ql,Ql,Ql,Ql,Ql,Ql,El,Ql,Ql,Ql,Ql,Ql,El,Ql,Ql,El,Ql,Ql,El,Ql,Ql,Ql,Ql,Ql,Ql,Ql, ...
   Ql,Ql];

%Normal Music n=numel(NoteLength); song = ones(1); for Count = 1:n;

   t=0:delta:NoteLength(Count);
   y=sin(2*pi*Note(Count)*t);
   sound(y,1/delta);
   song=[song,y];

end

wavwrite(song, 44100, 32, 'Mario1.wav') pause(5) song = ones(1); for Count = 1:n;

   t=0:delta:(1/2)*NoteLength(Count);
   y=sin(2*pi*Note(Count)*t);
   sound(y,1/delta);
   song=[song,y];

end wavwrite(song, 44100, 32, 'Mario2.wav')

%Up an Octave

pause(5) song = ones(1); for Count = 1:n;

   t=0:delta:NoteLength(Count);
   y=sin(2*2*pi*Note(Count)*t);
   sound(y,1/delta);
   song=[song,y];

end wavwrite(song, 44100, 32, 'Mario3.wav')

Alumni Liaison

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

Dr. Paul Garrett