(→Sound files) |
(→Sound files) |
||
Line 6: | Line 6: | ||
Here is the fight song at twice the frequency: [http://kiwi.ecn.purdue.edu/ECE301Fall2008mboutin/images/0/0a/HW1_2Freq.wav Twice Frequency] | Here is the fight song at twice the frequency: [http://kiwi.ecn.purdue.edu/ECE301Fall2008mboutin/images/0/0a/HW1_2Freq.wav Twice Frequency] | ||
+ | |||
+ | == MATLAB Code == | ||
+ | % Virgil Hsieh | ||
+ | % Homework 1.1: Purdue fight song normal, double speed, and double freq. | ||
+ | |||
+ | % The following two lines clears the screen and all variables | ||
+ | clc | ||
+ | clear all | ||
+ | |||
+ | % This marks the sampling rate | ||
+ | delta = 0.00005; | ||
+ | |||
+ | % Lengths of notes | ||
+ | E = 0.125; | ||
+ | Q = 0.25; | ||
+ | H = 0.5; | ||
+ | HQ = H + Q; | ||
+ | DQ = Q + E; | ||
+ | |||
+ | % Declares all of the notes needed for 'Hail Purdue' amd their freq. | ||
+ | Af = 415; | ||
+ | An = 440; | ||
+ | Bf = 466; | ||
+ | Bn = 494; | ||
+ | Cn = 523; | ||
+ | Df = 554; | ||
+ | Ef = 311; | ||
+ | En = 329; | ||
+ | Fn = 349; | ||
+ | Gf = 370; | ||
+ | Gn = 392; | ||
+ | |||
+ | % This is an array of notes for the Purdue fight song | ||
+ | Notes = [Ef, Fn, Gn, Af, Bf, Cn, Cn, Df, Df, Df, Af, Bf, Bn, Cn]; | ||
+ | Length = [HQ, Q, Q, DQ, E, Q, Q, Q, E, E, Q, E, E, HQ]; | ||
+ | |||
+ | count1 = 1; | ||
+ | |||
+ | % Imbedded loop that creates the fight song | ||
+ | for walker = 1: (length (Notes)) | ||
+ | count2 = 1; | ||
+ | t = 0: delta: Length (walker); | ||
+ | FightSong = sin (2 * 3.14 * t* Notes (walker)); | ||
+ | FSlen = length (FightSong); | ||
+ | |||
+ | while count2 < FSlen | ||
+ | HailPurdue (count1) = FightSong (count2); | ||
+ | count1 = count1 + 1; | ||
+ | count2 = count2 + 1; | ||
+ | end | ||
+ | end | ||
+ | |||
+ | % Plays the fight song to make sure it works | ||
+ | sound (HailPurdue, 1 / delta); | ||
+ | |||
+ | % Makes a wav file for the song | ||
+ | wavwrite (HailPurdue, 'HW1_Normal.wav'); | ||
+ | |||
+ | count1 = 1; | ||
+ | |||
+ | % Imbedded loop that creates the fight song | ||
+ | for walker = 1: (length (Notes)) | ||
+ | count2 = 1; | ||
+ | t = 0: delta: (Length (walker))/2; | ||
+ | FightSong2 = sin (2 * 3.14 * t* Notes (walker)); | ||
+ | FSlen = length (FightSong2); | ||
+ | |||
+ | while count2 < FSlen | ||
+ | HailPurdue2 (count1) = FightSong2 (count2); | ||
+ | count1 = count1 + 1; | ||
+ | count2 = count2 + 1; | ||
+ | end | ||
+ | end | ||
+ | |||
+ | % Plays the fight song to make sure it works | ||
+ | sound (HailPurdue2, 1 / delta); | ||
+ | |||
+ | % Makes a wav file for the song | ||
+ | wavwrite (HailPurdue2, 'HW1_2Speed.wav'); | ||
+ | |||
+ | count1 = 1; | ||
+ | |||
+ | % Imbedded loop that creates the fight song | ||
+ | for walker = 1: (length (Notes)) | ||
+ | count2 = 1; | ||
+ | t = 0: delta: (Length (walker)); | ||
+ | FightSong3 = sin (2 * 2 * 3.14 * t* Notes (walker)); | ||
+ | FSlen = length (FightSong3); | ||
+ | |||
+ | while count2 < FSlen | ||
+ | HailPurdue3 (count1) = FightSong3 (count2); | ||
+ | count1 = count1 + 1; | ||
+ | count2 = count2 + 1; | ||
+ | end | ||
+ | end | ||
+ | |||
+ | % Plays the fight song to make sure it works | ||
+ | sound (HailPurdue2, 1 / delta); | ||
+ | |||
+ | % Makes a wav file for the song | ||
+ | wavwrite (HailPurdue3, 'HW1_2Freq.wav'); |
Revision as of 14:06, 4 September 2008
Sound files
Here is the fight song at normal speed: Fight Song Normal Speed
Here is the fight song at twice the speed: Twice Speed
Here is the fight song at twice the frequency: Twice Frequency
MATLAB Code
% Virgil Hsieh % Homework 1.1: Purdue fight song normal, double speed, and double freq.
% The following two lines clears the screen and all variables clc clear all
% This marks the sampling rate delta = 0.00005;
% Lengths of notes E = 0.125; Q = 0.25; H = 0.5; HQ = H + Q; DQ = Q + E;
% Declares all of the notes needed for 'Hail Purdue' amd their freq. Af = 415; An = 440; Bf = 466; Bn = 494; Cn = 523; Df = 554; Ef = 311; En = 329; Fn = 349; Gf = 370; Gn = 392;
% This is an array of notes for the Purdue fight song Notes = [Ef, Fn, Gn, Af, Bf, Cn, Cn, Df, Df, Df, Af, Bf, Bn, Cn]; Length = [HQ, Q, Q, DQ, E, Q, Q, Q, E, E, Q, E, E, HQ];
count1 = 1;
% Imbedded loop that creates the fight song for walker = 1: (length (Notes))
count2 = 1; t = 0: delta: Length (walker); FightSong = sin (2 * 3.14 * t* Notes (walker)); FSlen = length (FightSong); while count2 < FSlen HailPurdue (count1) = FightSong (count2); count1 = count1 + 1; count2 = count2 + 1; end
end
% Plays the fight song to make sure it works sound (HailPurdue, 1 / delta);
% Makes a wav file for the song wavwrite (HailPurdue, 'HW1_Normal.wav');
count1 = 1;
% Imbedded loop that creates the fight song for walker = 1: (length (Notes))
count2 = 1; t = 0: delta: (Length (walker))/2; FightSong2 = sin (2 * 3.14 * t* Notes (walker)); FSlen = length (FightSong2); while count2 < FSlen HailPurdue2 (count1) = FightSong2 (count2); count1 = count1 + 1; count2 = count2 + 1; end
end
% Plays the fight song to make sure it works sound (HailPurdue2, 1 / delta);
% Makes a wav file for the song wavwrite (HailPurdue2, 'HW1_2Speed.wav');
count1 = 1;
% Imbedded loop that creates the fight song for walker = 1: (length (Notes))
count2 = 1; t = 0: delta: (Length (walker)); FightSong3 = sin (2 * 2 * 3.14 * t* Notes (walker)); FSlen = length (FightSong3); while count2 < FSlen HailPurdue3 (count1) = FightSong3 (count2); count1 = count1 + 1; count2 = count2 + 1; end
end
% Plays the fight song to make sure it works sound (HailPurdue2, 1 / delta);
% Makes a wav file for the song wavwrite (HailPurdue3, 'HW1_2Freq.wav');