(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | =[[Homework_1_ECE301Fall2008mboutin|HW1]], [[ECE301]], Prof. [[user:mboutin|Boutin]]= | ||
+ | In this homework assignment, we were asked to write a Matlab code to play the "Hail Purdue" song with different speeds and pitch. Here are my results: | ||
+ | *[[Media:HailPurdue_ECE301Fall2008mboutin.wav|Original Hail Purdue]] | ||
+ | *[[Media:HailPurduefaster_ECE301Fall2008mboutin.wav|Hail Purdue twice as fast]] | ||
+ | *[[Media:HailPurdueHigher_ECE301Fall2008mboutin.wav|Hail Purdue one octave higher]] | ||
+ | |||
+ | Below is my code. | ||
+ | ---- | ||
Hail Purdue Code: | Hail Purdue Code: | ||
<pre> | <pre> | ||
Line 91: | Line 99: | ||
[[Media:HailPurdue_ECE301Fall2008mboutin.wav]] | [[Media:HailPurdue_ECE301Fall2008mboutin.wav]] | ||
[[Media:HailPurduefaster_ECE301Fall2008mboutin.wav]] | [[Media:HailPurduefaster_ECE301Fall2008mboutin.wav]] | ||
− | [[Media: | + | [[Media:HailPurdueHigher_ECE301Fall2008mboutin.wav]] |
Latest revision as of 08:07, 27 August 2010
HW1, ECE301, Prof. Boutin
In this homework assignment, we were asked to write a Matlab code to play the "Hail Purdue" song with different speeds and pitch. Here are my results:
Below is my code.
Hail Purdue Code:
%Adrian Delancy clear all %Finding Frequencies (v) of notes: for n=0:11; v(1+n)= 220*2.^(n/12); end A=v(1); Bb=v(2); B=v(3); C=v(4);%Middle C Db=v(5); D=v(6); Eb=v(7); E=v(8); F=v(9); Gb=v(10);%(F#) G=v(11); Ab=v(12);%(G#) bpm =30; %Specify beats per minute bps=bpm/60; delta = 0.0005; d=1/delta;%Sampling rate %Defining note values eg. quaver (q),half-note etc... cr =0:delta:bps;%crotchet or quater note - 1 beat dotcr=0:delta:bps*(3/2);%dotted quater note or crotchet - 3/2 beats h=0:delta:bps*2;%Half note or minim - 2 beats wh=0:delta:bpm*4;%Whole note - 4 beats doth = 0:delta:bps*3;%dotted minim - 3 beats q=0:delta:bps/2;%quaver or eighth note - 1/2 beat dotq=0:delta:bps*0.75;% - dotted quaver - 3/4 beat k=2*pi; %Playing the first part of Hail Purdue chours in the key of A flat (Ab) in 2/4 time: y = [sin(k*Eb*h) sin(k*F*cr) sin(k*G*cr) sin(k*Ab*dotcr) sin(k*Bb*2*q) sin(k*2*C*cr) sin(k*C*2*cr) sin(k*Db*2*cr) sin(k*Db*2*q) sin(k*Db*2*q) sin(k*Ab*cr) sin(k*Bb*2*q) sin(k*B*2*q) sin(k*C*2*doth) sin(0*cr) sin(k*C*2*h) sin(k*C*2*cr) sin(k*Bb*2*cr) sin(k*Ab*dotcr) sin(k*2*Bb*q) sin(k*2*C*cr) sin(k*2*C*cr) sin(k*2*Bb*cr) sin(k*F*q) sin(k*G*q) sin(k*Ab*cr) sin(k*G*q) sin(k*F*q) sin(k*Bb*2*doth)]; sound(y,d); wavwrite(y,d,'HailPurdue'); %Playing the tune twice as a fast: bpm =15; bps=bpm/60; delta = 0.0005; d=1/delta; %Defining note values eg. quaver (q),half-note etc... cr =0:delta:bps; dotcr=0:delta:bps*(3/2); h=0:delta:bps*2; wh=0:delta:bpm*4; doth = 0:delta:bps*3; q=0:delta:bps/2; dotq=0:delta:bps*0.75; k=2*pi; %Playing in the key of A flat (Ab): y1= [sin(k*Eb*h) sin(k*F*cr) sin(k*G*cr) sin(k*Ab*dotcr) sin(k*Bb*2*q) sin(k*2*C*cr) sin(k*C*2*cr) sin(k*Db*2*cr) sin(k*Db*2*q) sin(k*Db*2*q) sin(k*Ab*cr) sin(k*Bb*2*q) sin(k*B*2*q) sin(k*C*2*doth) sin(0*cr) sin(k*C*2*h) sin(k*C*2*cr) sin(k*Bb*2*cr) sin(k*Ab*dotcr) sin(k*2*Bb*q) sin(k*2*C*cr) sin(k*2*C*cr) sin(k*2*Bb*cr) sin(k*F*q) sin(k*G*q) sin(k*Ab*cr) sin(k*G*q) sin(k*F*q) sin(k*Bb*2*doth)]; sound(y1,d); wavwrite(y1,d,'HailPurduefaster'); %Rescailing the original tune: %Defining note values eg. quaver (q),half-note etc... bpm=30; bps=bpm/60; cr =0:delta:bps;%crotchet or quater note - 1 beat dotcr=0:delta:bps*(3/2);%dotted quater note or crotchet - 3/2 beats h=0:delta:bps*2;%Half note or minim - 2 beats wh=0:delta:bpm*4;%Whole note - 4 beats doth = 0:delta:bps*3;%dotted minim - 3 beats q=0:delta:bps/2;%quaver or eighth note - 1/2 beat dotq=0:delta:bps*0.75;% - dotted quaver - 3/4 beat y2 = [sin(k*Eb*(2*h)) sin(k*F*cr*2) sin(k*G*cr*2) sin(k*Ab*dotcr*2) sin(k*Bb*4*q) sin(k*4*C*cr) sin(k*C*4*cr) sin(k*Db*4*cr) sin(k*Db*4*q) sin(k*Db*4*q) sin(k*Ab*2*cr) sin(k*Bb*4*q) sin(k*B*4*q) sin(k*C*4*doth)]; sound(y2,d); wavwrite(y2,d,'HailPurdueHigher')
Media:HailPurdue_ECE301Fall2008mboutin.wav Media:HailPurduefaster_ECE301Fall2008mboutin.wav Media:HailPurdueHigher_ECE301Fall2008mboutin.wav