Line 8: Line 8:
 
delta = 0.00005;
 
delta = 0.00005;
  
% A loop is made to separate Question 1 into 3 parts
+
% A loop is made to separate Question 1 into 3 parts<br>
 
for p = 1:3
 
for p = 1:3
 
     if p ==2
 
     if p ==2

Revision as of 08:52, 19 January 2011

% Sharifah Fareena Aljunid % BME 301 Homework 1 % Professor Mimi Boutin

% Part 1 clear clc delta = 0.00005;

% A loop is made to separate Question 1 into 3 parts
for p = 1:3

   if p ==2
       bpm = 112*2; % indicating the tune will be twice as fast
   else
       bpm = 112; % normal beats per minute
   end
   
   % Calculation to determine the length of the  in seconds
   H = 0:delta:(2*60/bpm);
   Q = 0:delta:(1*60/bpm);
   E = 0:delta:(0.5*60/bpm);
   DQ = 0:delta:(1.5*60/bpm);
   
   % Part 3, rescaling the frequency of A4
   if p == 3
       fa = 880; % the frequency is double the original as y(t) = x(2t)
   else
       fa = 440; % original frequency of A4
   end
   
   % Calculation of the frequency of any note related to the frequency of A4
   fG = 2^(-2/12)*fa;
   fC = 2^(3/12)*fa;
   fBf = 2^(1/12)*fa;
   fDf = 2^(4/12)*fa;
   
   % Calculation of all note length using a sine wave
   GQ = sin(2*pi*fG*Q);
   BfQ = sin(2*pi*fBf*Q);
   CDQ = sin(2*pi*fC*DQ);
   DfE = sin(2*pi*fDf*E);
   CH = sin(2*pi*fC*H);
   
   % The tune of the song to be played
   z = [GQ, BfQ, CDQ, GQ, BfQ, DfE, CH, GQ, BfQ, CDQ, BfQ, GQ];
   sound(z,1/delta);
   
   % Adjust song according to what is asked for in Question 1
   if p == 1
       wavwrite(z,1/delta,32,'Normal melody')
   elseif p == 2
       wavwrite(z,1/delta,32,'Faster melody')
   else
       wavwrite(z,1/delta,32,'Transformation x(2t)')
   end

end

Media:Normal melody.wav
Media:Faster melody.wav
Media:Transformation x(2t).wav

% Part 2 clear clc % Use wavread to read and store the Beatles song [song,Fs] = wavread('Beatles.wav'); song_reversed = flipud(song); % this will flip the song and play it in reverse sound(song_reversed,Fs);

The song played in forward say "Number Nine". When it is played in reversed the sound that comes out is "Turn me on dead man".

Alumni Liaison

To all math majors: "Mathematics is a wonderfully rich subject."

Dr. Paul Garrett