(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
=Playing Hail Purdue with MATLAB=
 +
[[Homework 1_ECE301Fall2008mboutin|HW1]],  [[ECE301]], Fall 2008
 +
 +
>[[HW1.1 Allen Humphreys_ECE301Fall2008mboutin| 1.1]]  >[[HW1.2 Allen Humphreys_ECE301Fall2008mboutin| 1.2]] >[[HW1.3 Allen Humphreys_ECE301Fall2008mboutin| 1.3]] >[[HW1.4 Allen Humphreys_ECE301Fall2008mboutin| 1.4]] >[[HW1.5 Allen Humphreys_ECE301Fall2008mboutin| 1.5]]
 +
----
 
==M-file==
 
==M-file==
  
Line 35: Line 40:
 
               C C Bf F G    Af G F Bf Ef  Ef R F G A    Bf C C C Df ...   
 
               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];  
 
               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 ...
+
duration =    [W H H TQ Q  H H H Q Q    H Q Q W H    H W H H TQ ...
 
               Q H H H Q    Q H Q Q W  H H TQ Q H    H TQ Q H Q  ...  
 
               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];
 
               Q H H H H W    H TQ H Q H  H H H H H  TQ Q TQ Q W H];
Line 59: Line 64:
 
sound (song, (1/(delta)));  %play the sound
 
sound (song, (1/(delta)));  %play the sound
 
</pre>
 
</pre>
 +
=Sound File=
 +
[[Media:AllensHailPU_ECE301Fall2008mboutin.wav]]
 +
----
 +
[[Main_Page_ECE301Fall2008mboutin|Back to ECE301 Fall 2008 Prof. Boutin]]

Latest revision as of 06:01, 23 September 2013

Playing Hail Purdue with MATLAB

HW1, ECE301, Fall 2008

> 1.1 > 1.2 > 1.3 > 1.4 > 1.5


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 TQ  ...
               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


Back to ECE301 Fall 2008 Prof. Boutin

Alumni Liaison

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

Dr. Paul Garrett