(HW1.1)
Line 60: Line 60:
 
</pre>
 
</pre>
 
=Sound File=
 
=Sound File=
 +
[[Media:AllensHailPU_ECE301Fall2008mboutin.wav]]

Revision as of 14:19, 5 September 2008

M-file

%Allen Humphreys
%ECE301  
%HW1.1
clear;
clc;

delta = 0.00005; %time between samples

%Define the notes
A = 220;
Af = 207.65;
Bf = 233.08;
B = 246.94;
C = 261.63;
Df = 277.18;
D = 293.66;
Ef = 311.13;
E = 329.63;
F = 349.23;
G = 392.00;
R = 0;

s = .75; %a scale factor
W = 1 ;  %desired play time for a whole note
TQ = .75;
H = .5 ;
Q = .25;

%create a vector corresponding to the sound
song = [];
notes=       [Ef F G Af Bf   C C Df Df Df   Af Bf B C C   R C Bf Af Bf ...   
              C C Bf F G    Af G F Bf Ef   Ef R F G A     Bf C C C Df ...   
              Df Af Bf C F     G Af R F Ef    Af C Ef F C Bf Af Af]; 
duration =    [W H H TQ Q  H H H Q Q    H Q Q W H    H W H H T  ...
               Q H H H Q     Q H Q Q W   H H TQ Q H    H TQ Q H Q  ... 
               Q H H H H W     H TQ H Q H   H H H H H   TQ Q TQ Q W H];
for i=1:1:length(notes) %each for loop generates a part of the song, this does part a
    t=(0:delta:(duration(i)*s)); %vector for length of notes
    note = sin(2*pi*notes(i)*t); %generates the discrete vector to represent the note
    song = [song note];          %concantenates each of the prior notes
end

s = .5*s; %changing the scaling factor by 1/2 doubles the speed of the song
for i=1:1:length(notes) %part b
    t = (0:delta:(duration(i)*s));
    note = sin(2*pi*notes(i)*t);
    song = [song note];
end

s = .75;
for i=1:1:length(notes) %part c
    t = (0:delta:(duration(i)*s));
    note = sin(2*pi*notes(i)*t*2); %replace t by t*2 to get a time crunch
    song = [song note];
end
sound (song, (1/(delta)));  %play the sound

Sound File

Media:AllensHailPU_ECE301Fall2008mboutin.wav

Alumni Liaison

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

Dr. Paul Garrett