Sound File

Matlab Code

%Kevin Hoyt
%ECE 301 HW 1
%Part A
delta = .000005; %

%frequencies of notes
A = 440;
As = 466.16;
B = 493.99;
C = 523.25;
Cs = 554.37;
D = 587.33;
Ds = 622.25;
E = 659.26;
F = 698.46;
Fs = 739.99;
G = 783.99;
Gs = 830.61;
A2 = 880;

tempo = 180 %controls speed of the song

%make variables for all the note lengths
Q = 60/tempo;
En = 30/tempo;
Hn = 120/tempo;
Wn = 240/tempo;
DQ = 90/tempo;
DH = 180/tempo;
DWn = 360/tempo;
%make a vector containing the notes to the song

notes = [A B Cs D Cs D Cs D Cs D E D A B Cs Cs D Ds E Ds ...
    E Ds E Ds E Fs E A G Fs A B Cs D Cs D Cs D Cs D A2 ...
    Fs E D G D D E E F F Fs Fs G A2 Fs E D Fs E E A B ...
    Cs D E Fs Fs G G G D E F Fs Fs Fs E D E Fs Fs E B ...
    Cs D Cs B E A A B Cs D E Cs Cs Cs G G D E Fs B Cs ...
    D B A D Fs A B Fs E D D]; 
%make a vector containing the length of each note
times = [Q Q Q Q Q Q En En En En Q Q Q Q DH Q Q Q Q Q Q ...
    En En En En Q Q Q Q DH Q Q Q Q Q Q En En En En Q ...
    Q Q Q DH En En DQ En DQ En Q En En En En En En Hn ...
    Hn Wn Hn Q Q DQ En Q Q Q En En Q En En DH Hn Q Q ...
    DQ En Q Q Q En En Q En En Wn DQ En Q Q DQ En Q En ...
    En Q Q Q Q Wn DQ En Q Q Q Q Q Q DQ En DQ En DWn];

%for loop to put the notes and the times together and play the song
for k = 1:1:length(notes);
    note = notes(k);
    time = 0:delta:times(k);
    y = sin(note*2*pi*time);
    sound(y,1/delta);
 
    end
%Part B
%to play the song at double speed we just divide the time from the previous
%for loop by 2
for k = 1:1:length(notes);
    note = notes(k);
    time = 0:delta:times(k)/2;
    y = sin(note*2*pi*time);
    sound(y,1/delta);
 
end

%part C
%just take the for loop again and multiply everything in the sin by 2
for k = 1:1:length(notes);
    note = notes(k);
    time = 0:delta:times(k);
    y = sin((note*2*pi*time)*2);
    sound(y,1/delta);
 
end

Alumni Liaison

BSEE 2004, current Ph.D. student researching signal and image processing.

Landis Huffman