Matlab Code
%Max Paganini %mpaganin@purdue.edu %Hw 1.1 Hail Purdue clc; clear; %Hail Purdue is played at 172 Beats Per Minute = 172 quater notes per %minute. Qn = 60/172; Hn = Qn*2; % Half Note Fn = Qn*4; %Full Note En = Qn/2; % Eighth Note %Frequencies of each note in Hail Purdue A = 440; B = 495; C = 264; D = 297; E = 330; F = 352; G = 396; %Sampling Frequency is 20kHz dt = 1/20000; %Notes of Hail Purdue Chorus Notes = [G,A,B,C,D,E,E,F,F,C,D,E]; %Time Durations of each note Duration = [Fn,Hn,Hn,Fn,Fn,Fn,Fn,Fn,Fn,Fn,Fn,Fn]; %Play Song at Normal Speed, 12 notes in refrain so count from 1 to 12 disp('Now playing Hail Purdue Refrain at Normal Speed.') for count = 1:12 time = 0:dt:Duration(count); wave = sin(2*pi*time*Notes(count)); sound(wave,1/dt); end pause(4); %Play song at 2x normal speed disp('Now Playing Hail Purdue Refrain Twice as Fast.') for count = 1:12 time = 0:dt:(1/2)*Duration(count); wave = sin(2*pi*time*Notes(count)); sound(wave,1/dt); end pause(4); %Play song at double the frequency according to transformation y(t) = x(2t) disp('Now Playing Hail Purdue Refrain according to transformation y(t) = x(2t), also known as doubling the frequency.') for count = 1:12 time = 0:dt:Duration(count); wave = sin(4*pi*time*Notes(count)); sound(wave,1/dt); end