(Results)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Here is my wav file [[Media:Newalert_ECE301Fall2008mboutin.wav]]
+
== Matlab Code ==
 +
<pre>
 +
  %% Joshua Long
 +
  %% ECE 301
 +
  %% HW 1.1 Playing Music
 +
 
 +
  %% clear memory
 +
  clear
 +
 
 +
  %% clear console
 +
  clc
 +
 
 +
  delta = .00005;
 +
 
 +
  tempo = 60/140;
 +
 
 +
  %%Values for note lengths
 +
  hn = 0:delta:2*tempo;
 +
  qn = 0:delta:tempo;
 +
  en = 0:delta:.5*tempo;
 +
  dqn = 0:delta:1.5*tempo;
 +
 
 +
  %%Values for note lengths for Twice the tempo
 +
  thn = 0:delta:.5*2*tempo;
 +
  tqn = 0:delta:.5*tempo;
 +
  ten = 0:delta:.5*.5*tempo;
 +
  tdqn = 0:delta:.5*1.5*tempo;
 +
 
 +
  %%Values for the freq. of notes
 +
  Eb = 311.13;
 +
  F = 349.23;
 +
  G = 392.00;
 +
  Ab = 415.30;
 +
  Bb = 466.16;
 +
  C = 523.25;
 +
 
 +
  %%Regular Tempo
 +
  y = [sin(2*pi*Eb*hn),sin(2*pi*F*qn),sin(2*pi*G*qn),sin(2*pi*Ab*dqn),sin(2*pi*Bb*en), sin(2*pi*C*qn)];
 +
  %%Transformation of x(t) = y(2)
 +
  x = [sin(2*pi*2*Eb*hn),sin(2*pi*2*F*qn),sin(2*pi*2*G*qn),sin(2*pi*2*Ab*dqn),sin(2*pi*2*Bb*en), sin(2*pi*2*C*qn)];
 +
  %%Tempo Twice as Fast
 +
  z = [sin(2*pi*Eb*thn),sin(2*pi*F*tqn),sin(2*pi*G*tqn),sin(2*pi*Ab*tdqn),sin(2*pi*Bb*ten), sin(2*pi*C*tqn)];
 +
 
 +
  sound(y,1/delta);
 +
  sound(z,1/delta);
 +
  sound(x,1/delta);
 +
 
 +
  %%Save a wav file:
 +
  wavwrite([y,z,x],44100/2.2,32,'N:\Personal\ECE301\Hail_Purdue.wav');
  
 +
</pre>
  
== MY MATLAB CODE ==
 
  
<pre>
+
== Results ==
  
% Ben Laskowski (blaskows@purdue.edu)
+
The [[Media:JAL_Hail_Purdue.wav _ECE301Fall2008mboutin| audio file]] contains the regular Hail Purdue followed by the tune being played twice as fast followed by the y(t)=x(2t) transformation.
% September 5, 2008
+
% ECE301 Section 2 HW1
+
%
+
% This file is supposed to play Hail Purdue.
+
  
% Begin by clearing the output console and all memory.
+
The first two have the same sounding notes but the 2nd is just half the time to play. However, the last one made the frequency twice as fast and made it half the tempo.
clear;
+
clc;
+
 
+
%Define note durations.
+
% Take the time signature as 4/4 and let the quarter note = 172bpm.
+
% Then we have 172 quarter notes per minute, so the quarter note duration is 60/172 minute.
+
Q=60/172;
+
%Use the quarter note as a reference for the other note types.
+
H=2*Q; % Half note
+
W=4*Q; % Whole note
+
En=Q/2; %Eighth note
+
DQ=Q+En;%Dotted quarter
+
DH=H+Q; %Dotted half
+
 
+
%Now, define frequencies for each note starting with the A below middle C and extending an octave.
+
for note=0:12
+
Frequency(note+1)=220*2^(note/12);
+
end
+
 
+
%Define a constant for each note.
+
% Even though this will be in the key of D, I do not like sharp keys and will therefore define all accidentals as flats.
+
A=Frequency(1);
+
Bb=Frequency(2);
+
B=Frequency(3);
+
C=Frequency(4);
+
Db=Frequency(5);
+
D=Frequency(6);
+
Eb=Frequency(7);
+
E=Frequency(8);
+
F=Frequency(9);
+
Gb=Frequency(10);
+
G=Frequency(11);
+
Ab=Frequency(12);
+
A2=Frequency(13);
+
 
+
%Now, define arrays of notes and durations.
+
Notes=[A,B,Db,D,Db,D,Db,D,Db,D,E,D,A,B,Db, ...      %Cheer your call once more we rally, Alma Mater hear our praise
+
      Db,D,Eb,E,Eb,E,Eb,E,Eb,E,Gb,E,A,G,Gb, ...    %Where the Wabash spreads its valley, filled with joy our voices raise
+
      A,B,Db,D,Db,D,Db,D,Db,D,A2,Gb,E,D,G, ...    %From the skies in swelling echoes come the cheers that tell the tale
+
      D,D,E,E,F,F,Gb,Gb,G,A2,Gb,E,D,Gb,E,E, ...    %Of your vict'ries and your heroes, all hail Purdue, we sing all hail
+
      A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb, ...        %Hail, hail to old Purdue!  All hail to our old gold and black
+
      Gb,Gb,E,D,E,Gb,Gb,E,B,Db,D,Db,B,E, ...       %Hail, hail to old Purdue!  Our friendship may she never lack!
+
      A,A,B,Db,D,E,Gb,Gb,Gb,G,G,D,E,Gb, ...        %Ever grateful, ever true, thus we raise our song anew...
+
      B,Db,D,B,A,D,Gb,A,B,Gb,E,D,D];              %Of the days we spend with you, all hail our old Purdue!
+
+
Times=[Q,Q,Q,Q,Q,Q,En,En,En,En,Q,Q,Q,Q,DH, ...
+
      Q,Q,Q,Q,Q,Q,En,En,En,En,Q,Q,Q,Q,DH, ...
+
      Q,Q,Q,Q,Q,Q,En,En,En,En,Q,Q,Q,Q,DH, ...
+
      En,En,DQ,En,DQ,En,Q,En,En,En,En,En,En,H,H,W, ...
+
      H,Q,Q,DQ,En,Q,Q,Q,En,En,Q,En,En,DH, ...
+
      H,Q,Q,DQ,En,Q,Q,Q,En,En,Q,En,En,W, ...
+
      DQ,En,Q,Q,DQ,En,Q,En,En,Q,Q,Q,Q,W, ...
+
      DQ,En,Q,Q,Q,Q,Q,Q,DQ,En,DQ,En,1.5*W];
+
 
+
%Let the sampling frequency be 20kHz, since this is what was used for the demo in class.
+
delta=1/20000;
+
 
+
%I count 116 notes in the above.
+
 
+
%First, play the song at normal speed.
+
for counter=1:116
+
t=0:delta:Times(counter); %Create a vector of times with appropriate duration
+
d=sin(2*pi*t*Notes(counter)); %Generate a sine wave for the afmorementioned
+
sound(d,1/delta); %Play the sound.
+
end
+
 
+
pause(5)
+
 
+
%Second, play the song at double speed.
+
for counter=1:116
+
t=0:delta:0.5*Times(counter); %Create a vector of times with appropriate duration:
+
                                    %Here, we cut the "correct" times in half to speed up the song.                 
+
d=sin(2*pi*t*Notes(counter)); %Generate a sine wave for the afmorementioned
+
sound(d,1/delta); %Play the sound.
+
end
+
 
+
pause(5)
+
 
+
%Finally, play the song according to the transformation y(t)=x(2t).
+
%This should have the effect of transposing up an octave, or doubling the
+
%frequency.
+
for counter=1:116
+
t=0:delta:Times(counter); %Create a vector of times with appropriate duration
+
d=sin(2*2*pi*t*Notes(counter)); %Generate a sine wave for the afmorementioned
+
sound(d,1/delta); %Play the sound.
+
end
+
 
+
 
+
</pre>
+

Latest revision as of 07:17, 5 September 2008

Matlab Code

  %% Joshua Long
  %% ECE 301
  %% HW 1.1 Playing Music
  
  %% clear memory
  clear
  
  %% clear console
  clc
  
  delta = .00005;
  
  tempo = 60/140;
  
  %%Values for note lengths
  hn = 0:delta:2*tempo;
  qn = 0:delta:tempo;
  en = 0:delta:.5*tempo;
  dqn = 0:delta:1.5*tempo;
  
  %%Values for note lengths for Twice the tempo
  thn = 0:delta:.5*2*tempo;
  tqn = 0:delta:.5*tempo;
  ten = 0:delta:.5*.5*tempo;
  tdqn = 0:delta:.5*1.5*tempo;
  
  %%Values for the freq. of notes
  Eb = 311.13;
  F = 349.23;
  G = 392.00;
  Ab = 415.30;
  Bb = 466.16;
  C = 523.25;
  
  %%Regular Tempo
  y = [sin(2*pi*Eb*hn),sin(2*pi*F*qn),sin(2*pi*G*qn),sin(2*pi*Ab*dqn),sin(2*pi*Bb*en), sin(2*pi*C*qn)];
  %%Transformation of x(t) = y(2)
  x = [sin(2*pi*2*Eb*hn),sin(2*pi*2*F*qn),sin(2*pi*2*G*qn),sin(2*pi*2*Ab*dqn),sin(2*pi*2*Bb*en), sin(2*pi*2*C*qn)];
  %%Tempo Twice as Fast
  z = [sin(2*pi*Eb*thn),sin(2*pi*F*tqn),sin(2*pi*G*tqn),sin(2*pi*Ab*tdqn),sin(2*pi*Bb*ten), sin(2*pi*C*tqn)];
  
  sound(y,1/delta);
  sound(z,1/delta);
  sound(x,1/delta);
  
  %%Save a wav file:
  wavwrite([y,z,x],44100/2.2,32,'N:\Personal\ECE301\Hail_Purdue.wav');

 


Results

The audio file contains the regular Hail Purdue followed by the tune being played twice as fast followed by the y(t)=x(2t) transformation.

The first two have the same sounding notes but the 2nd is just half the time to play. However, the last one made the frequency twice as fast and made it half the tempo.

Alumni Liaison

BSEE 2004, current Ph.D. student researching signal and image processing.

Landis Huffman