(New page: %ANANYA PANJA %ECE 301 %Hail Purdue Chorus A=220; B=247; Db=278; D=294; E=330; F=349; Gb=370; G=392; delta=.0005; stop=.4; Notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb]; t=0:delta:stop; for i=...) |
|||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | =[[Homework_1_ECE301Fall2008mboutin|HW1]], [[ECE301]], Prof. [[user:mboutin|Boutin]]= | ||
+ | In this homework assignment, we were asked to write a Matlab code to play the "Hail Purdue" song with different speeds and pitch. | ||
+ | ---- | ||
%ANANYA PANJA | %ANANYA PANJA | ||
+ | |||
%ECE 301 | %ECE 301 | ||
+ | |||
%Hail Purdue Chorus | %Hail Purdue Chorus | ||
+ | |||
A=220; | A=220; | ||
+ | |||
B=247; | B=247; | ||
+ | |||
Db=278; | Db=278; | ||
+ | |||
D=294; | D=294; | ||
+ | |||
E=330; | E=330; | ||
+ | |||
F=349; | F=349; | ||
+ | |||
Gb=370; | Gb=370; | ||
+ | |||
G=392; | G=392; | ||
+ | |||
delta=.0005; | delta=.0005; | ||
+ | |||
stop=.4; | stop=.4; | ||
Notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb]; | Notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb]; | ||
+ | |||
t=0:delta:stop; | t=0:delta:stop; | ||
for i=length(Notes) | for i=length(Notes) | ||
+ | |||
Hail=sin(2*pi*t*Notes(i)); | Hail=sin(2*pi*t*Notes(i)); | ||
+ | |||
sound(Hail,1/delta); | sound(Hail,1/delta); | ||
end | end | ||
pause(3); | pause(3); | ||
+ | |||
%To play the song twice as fast | %To play the song twice as fast | ||
for T=1:length(Notes) | for T=1:length(Notes) | ||
+ | |||
t=0:delta:.5*length(Notes(T));%.5 is the scaling factor | t=0:delta:.5*length(Notes(T));%.5 is the scaling factor | ||
+ | |||
Hail_1=sin(2*pi*t*Notes(T)); | Hail_1=sin(2*pi*t*Notes(T)); | ||
+ | |||
sound(Hail_1,1/delta); | sound(Hail_1,1/delta); | ||
end | end | ||
pause(3); | pause(3); | ||
+ | |||
%To play the song at double frequency | %To play the song at double frequency | ||
for T=1:length(Notes) | for T=1:length(Notes) | ||
+ | |||
t=0:delta:length(Notes(T)); | t=0:delta:length(Notes(T)); | ||
+ | |||
Hail_2=sin(2*2*pi*t*Notes(T))%2 is the scaling here | Hail_2=sin(2*2*pi*t*Notes(T))%2 is the scaling here | ||
+ | |||
sound(Hail_2,1/delta); | sound(Hail_2,1/delta); | ||
+ | |||
end | end |
Latest revision as of 09:04, 27 August 2010
HW1, ECE301, Prof. Boutin
In this homework assignment, we were asked to write a Matlab code to play the "Hail Purdue" song with different speeds and pitch.
%ANANYA PANJA
%ECE 301
%Hail Purdue Chorus
A=220;
B=247;
Db=278;
D=294;
E=330;
F=349;
Gb=370;
G=392;
delta=.0005;
stop=.4;
Notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb];
t=0:delta:stop;
for i=length(Notes)
Hail=sin(2*pi*t*Notes(i));
sound(Hail,1/delta);
end
pause(3);
%To play the song twice as fast
for T=1:length(Notes)
t=0:delta:.5*length(Notes(T));%.5 is the scaling factor
Hail_1=sin(2*pi*t*Notes(T));
sound(Hail_1,1/delta);
end
pause(3);
%To play the song at double frequency
for T=1:length(Notes)
t=0:delta:length(Notes(T));
Hail_2=sin(2*2*pi*t*Notes(T))%2 is the scaling here
sound(Hail_2,1/delta);
end