Results File

Wav file of Matlab code

Matlab Code for Hail Purdue

%Joseph Mazzei ECE 301 HW1 Problem 1

%Clear the command window and all variables
clc
clear all

%Note Frequencies
C4 = 261.63;
Df4 = 277.18;
D4 = 293.66;
Ef4 = 311.13;
E4 = 329.63;
F4 = 349.23;
Gf4 = 369.99;
G4 = 392.00;
Af4 = 415.30;
A4 = 440;
Bf4 = 466.16;
B4 = 493.88;
C5 = 523.25;
Df5 =  554.37;
D5 = 587.33;
Ef5 = 622.25;
E5 = 659.26;
F5 = 698.46;
Gf5 = 739.99;
G5 = 783.99;
Af5 = 830.61;
A5 = 880.00;
Bf5 = 932.33;
B5 = 987.77;
R = 0; %Rest

%To setup the Tempo Quarter Note = 140 bpm
qn = 60/140; %Quarter Note
en = qn/2; %Eighth Note
hn = qn*2; %Half Note
dqn = 3*en; %Dotted quarter Note
sn = en/2; %Sixteenth Note
dhn = qn*3; %Dotted Half Note
wn = qn*4; %Whole Note

delta = 0.00005; %sampling frequency

%Vector for each note value
note = [Ef4 F4 G4 Af4 Bf4 C5 C5 Df5 Df5 Df5 Af4 Bf4 B4 C5 C5 C5 Bf4...
    Af4 Bf4 C5 C5 Bf4 F4 G4 Af4 G4 F4 Bf4 Bf4 R Ef5 R... 
    Ef4 Ef4 F4 G4 Af4 Bf4 C5 C5 C5 Df5 Df5 Af4 Bf4 C5 R... 
    F4 Gf4 Af4 F4 Ef4 Af4 C5 Ef4 F4 Af4 C5 Bf4 Af4 Af4 R];

%Vector for the duration of each note
duration = [hn qn qn dqn en qn qn qn en en qn en en wn hn qn qn...
    dqn en qn qn qn en en qn en en hn en en en en dqn en qn qn dqn en qn en en... 
    qn qn qn qn dhn qn dqn en qn qn qn qn qn qn dqn en dqn en dhn qn ];

%Loop for Song at orignal tempo
for n=1:length(duration) 
  t = 0:delta:duration(n);
  y = sin(2*pi*note(n)*t);
  sound(y,1/delta)
end

pause(2) %Have 2 seconds of silience between versions.

%Loop for song in double time
for n = 1:length(duration)
    t2 = 0:delta:duration(n)/2;
    y = sin(2*pi*t2*note(n));
    sound(y,1/delta)
end

pause(2) %Have 2 seconds of silience between versions.

%Loop for transformation of song 
%It ends up making the song a whole ocatve higher.
for n = 1:length(duration)
  t = 0:delta:duration(n);
  y = sin(2*pi*2*note(n)*t);
  sound(y,1/delta)
end

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang