Contents
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.
Sound Files
MATLAB Code Hail Purdue
% Mark Frankosky (mfrankos@purdue.edu) % ECE301 HW1.1 % Hail Purdue % Set up Sample Rate SampleRate = 1/20000; timeSig = 172; % Times Q = 60/timeSig; E = 60/timeSig/2; DQ = Q+E; H = 2*Q; DH = H+Q; % Set up note frequencies... C4 = 2*130.81; C4S = 2*138.59; D4 = 2*146.83; D4S = 2*155.56; E4 = 2*164.81; F4 = 2*174.61; F4S = 2*185; G4 = 2*196; G4S = 2*207.65; A4 = 2*220; A4S = 2*233.08; B4 = 2*246.94; % Set up Notes Notes = [A4 B4 C4S D4 E4 F4S F4S G4 G4 G4 D4 E4 F4 F4S]; % Set up Times NoteLength = [H Q Q DQ E Q Q Q E E Q E E DH]; % Play normal speed for nn=1:length(NoteLength) TimeVector = 0:SampleRate:NoteLength(nn); SoundVector = sin(2*pi*Notes(nn)*TimeVector); soundsc(SoundVector, 1/SampleRate); end pause(2) % Play second time twice as fast for nn=1:length(NoteLength) TimeVector = 0:SampleRate:.5*NoteLength(nn); SoundVector = sin(2*pi*Notes(nn)*TimeVector); soundsc(SoundVector, 1/SampleRate); end pause(2) % play third time with twice the frequency % same as applying the transform x(2t) for nn=1:length(NoteLength) TimeVector = 0:SampleRate:NoteLength(nn); SoundVector = sin(2*2*pi*Notes(nn)*TimeVector); soundsc(SoundVector, 1/SampleRate); end
MATLAB Code Mario
% Mark Frankosky (mfrankos@purdue.edu) % ECE301 HW1.1 % Not quite hail purdue SampleRate = 1/20000; timeSig = 216; % Times Q = 60/timeSig; E = 60/timeSig/2; DQ = Q+E; H = 2*Q; % Set up note frequencies... % (many arent used...but didnt feel like figuring out which ones were) C3 = 130.81; C3S = 138.59; D3 = 146.83; D3S = 155.56; E3 = 164.81; F3 = 174.61; F3S = 185; G3 = 196; G3S = 207.65; A3 = 220; A3S = 233.08; B3 = 246.94; C4 = 2*130.81; C4S = 2*138.59; D4 = 2*146.83; D4S = 2*155.56; E4 = 2*164.81; F4 = 2*174.61; F4S = 2*185; G4 = 2*196; G4S = 2*207.65; A4 = 2*220; A4S = 2*233.08; B4 = 2*246.94; C5 = 3*130.81; C5S = 3*138.59; D5 = 3*146.83; D5S = 3*155.56; E5 = 3*164.81; F5 = 3*174.61; F5S = 3*185; G5 = 3*196; G5S = 3*207.65; A5 = 3*220; A5S = 3*233.08; B5 = 3*246.94; % Rest Value (no freqency) REST = 0; % Set up Note Values Notes1 = [E5 E5 REST E5 REST C5 E5 G5 REST G4 REST C5 G4 REST E4 A4 B4 ... A4S A4 G4 E5 G5 A5 F5 G5 REST E5 C5 D5 B4 C5 G4 REST E4 A4 B4 ... A4S A4 G4 E5 G5 A5 F5 G5 REST E5 C5 D5 B4]; Notes2 = [F4S F4S REST F4S REST F4S F4S G4 REST G4 REST E4 E4 REST C4 ... C4 D4 C4S C4 C4 G4 B4 C5 A4 B4 REST A4 E4 F4 D4 E4 E4 REST ... C4 C4 D4 C4S C4 C4 G4 B4 C5 A4 B4 REST A4 E4 F4 D4 ]; Notes3 = [D3 D3 REST D3 REST D3 D3 G3 REST G3 REST G3 E3 REST C3 F3 G3 ... F3S F3 E3 C4 E4 F4 D4 E4 REST C4 A3 B3 G3 G3 E3 REST C3 F3 G3... F3S F3 E3 C4 E4 F4 D4 E4 REST C4 A3 B3 G3 ]; % Set up Time values Time = [E E E E E E Q Q Q Q Q DQ E Q H Q Q E Q Q Q Q Q E E E Q E E DQ ... DQ E Q H Q Q E Q Q Q Q Q E E E Q E E DQ]; TotalVector = 0; % Play normal speed for nn=1:length(Time) t = 0:SampleRate:Time(nn); SoundVector1 = sin(2*pi*Notes1(nn)*t); SoundVector2 = sin(2*pi*Notes2(nn)*t); SoundVector3 = sin(2*pi*Notes3(nn)*t); SoundVectorSum = SoundVector1+SoundVector2+SoundVector3; TotalVector = [TotalVector SoundVectorSum]; soundsc(SoundVectorSum, 1/SampleRate); end pause(3) % play double speed for nn=1:length(Time) t = 0:SampleRate:0.5*Time(nn); SoundVector1 = sin(2*pi*Notes1(nn)*t); SoundVector2 = sin(2*pi*Notes2(nn)*t); SoundVector3 = sin(2*pi*Notes3(nn)*t); SoundVectorSum = SoundVector1+SoundVector2+SoundVector3; TotalVector = [TotalVector SoundVectorSum]; soundsc(SoundVectorSum, 1/SampleRate); end pause(3) % play with 2x frequency for nn=1:length(Time) t = 0:SampleRate:Time(nn); SoundVector1 = sin(2*2*pi*Notes1(nn)*t); SoundVector2 = sin(2*2*pi*Notes2(nn)*t); SoundVector3 = sin(2*2*pi*Notes3(nn)*t); SoundVectorSum = SoundVector1+SoundVector2+SoundVector3; TotalVector = [TotalVector SoundVectorSum]; soundsc(SoundVectorSum, 1/SampleRate); end