Revision as of 07:41, 5 September 2008 by Nablock (Talk)

MATLAB Code

% Nicholas Block
% ECE301 Fall 2008
% Homework #1

clear;
clc;

% Part A

% Define frequencies
% All frequencies found using equations from HW sheet

B = 495;
A = 440;
G = 396;
F = 352; 
E = 330;
D = 297;
C = 264;

% Define note durations
% Assuming bpm=135

% Quarter note
Qn = 60/135;
% Eighth note
En = Qn/2;
% Half note
Hn = Qn *2;
% Whole note
Wn = Qn *4;

% Sample rate
delta = 1/44100;

% Melody

notes = [G, A, B, C, D, E, E, F, F, F, C, D, E];
rhythm = [Hn, Qn, Qn, Qn, En, Qn, Qn, Qn, En, En, Qn, Qn, Hn];

% Regular time

for counter=1:13
        t=0:delta:rhythm(counter);
        d=sin(2*pi*t*notes(counter));
        Sound(d,1/delta);
end
pause(2);

% Part B

for counter=1:13
        t=0:delta:.5*rhythm(counter);
        d=sin(2*pi*t*notes(counter));
        Sound(d,1/delta);
end
pause(2);

% Part C

for counter=1:13
        t=0:delta:rhythm(counter);
        d=sin(2*pi*t*2*notes(counter));
        Sound(d,1/delta);
end

Alumni Liaison

ECE462 Survivor

Seraj Dosenbach