Line 1: Line 1:
 
%HW 1 Problem 1a
 
%HW 1 Problem 1a
 +
 
clear all
 
clear all
 
clc
 
clc
Line 27: Line 28:
  
 
%HW 1 Problem 1b
 
%HW 1 Problem 1b
 +
 
clear all
 
clear all
 
clc
 
clc
Line 54: Line 56:
  
 
%HW 1 Problem 1c
 
%HW 1 Problem 1c
 +
 
clear all
 
clear all
 
clc
 
clc
Line 82: Line 85:
  
 
%HW 1 Problem 2
 
%HW 1 Problem 2
 +
 
clear all
 
clear all
 
clc
 
clc

Revision as of 16:42, 18 January 2011

%HW 1 Problem 1a

clear all clc

f_A = 440; % Frequency of A4 tempo = 112/60; % Tempo of the song delta = 5e-5; % Spacing between data fs = 1/delta; % Frequency at which the song will be played

G = 2^(-2/12)*f_A; % Calculates the frequency of G C = 2^(3/12)*f_A; % Calculates the frequency of C Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat Dflat = 2^(4/12)*f_A; % Calculates the frequency of D flat

H = 0:delta:(2/tempo); % Creates a matrix for the length of a half note Q = 0:delta:(1/tempo); % Creates a matrix for the length of a quater note E = 0:delta:((1/2)/(tempo)); % Creates a matrix for the length of a eigth note DQ = 0:delta:((3/2)/(tempo)); % Creates a matrix for the length of a dotted quater note

% Creates Matrix for the song based on the note and the time it is held z = [sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*C*DQ), sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*Dflat*E), sin(2*pi*C*H), sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*C*DQ), sin(2*pi*Bflat*Q), sin(2*pi*G*Q)];

sound(z, fs) % Plays the song wavwrite(z, fs, 'Question1A.wav'); %Writes song into wav file

Media:Question1A.wav

%HW 1 Problem 1b

clear all clc

f_A = 440; % Frequency of A4 tempo = 112/60; % Tempo of the song delta = 5e-5;  % Spacing between data fs = 1/delta; % Frequency at which the song will be played

G = 2^(-2/12)*f_A; % Calculates the frequency of G C = 2^(3/12)*f_A; % Calculates the frequency of C Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat Dflat = 2^(4/12)*f_A; % Calculates the frequency of D flat

H = 0:delta:(2/tempo); % Creates a matrix for the length of a half note Q = 0:delta:(1/tempo); % Creates a matrix for the length of a quater note E = 0:delta:((1/2)/(tempo)); % Creates a matrix for the length of a eigth note DQ = 0:delta:((3/2)/(tempo)); % Creates a matrix for the length of a dotted quater note

% Creates Matrix for the song based on the note and the time z = [sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*C*DQ), sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*Dflat*E), sin(2*pi*C*H), sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*C*DQ), sin(2*pi*Bflat*Q), sin(2*pi*G*Q)];

sound(z, 2*(fs)) % Plays the song the two times faster by multiplying the frequency by 2 wavwrite(z ,fs ,'Question1B.wav'); %Writes song into wav file

Media:Question1B.wav

%HW 1 Problem 1c

clear all clc

f_A = 440; % Frequency of A4 tempo = 112/60; % Tempo of the song delta = 5e-5;  % Spacing between data fs = 1/delta; % Frequency at which the song will be played

f_A = 2*f_A; % Rescales the song according to the transforamtion function y(t) = x(2t) G = 2^(-2/12)*f_A; % Calculates the frequency of G C = 2^(3/12)*f_A; % Calculates the frequency of C Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat Dflat = 2^(4/12)*f_A; % Calculates the frequency of D flat

H = 0:delta:(2/tempo); % Creates a matrix for the length of a half note Q = 0:delta:(1/tempo); % Creates a matrix for the length of a quater note E = 0:delta:((1/2)/(tempo)); % Creates a matrix for the length of a eigth note DQ = 0:delta:((3/2)/(tempo)); % Creates a matrix for the length of a dotted quater note

% Creates Matrix for the song based on the note and the time z = [sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*C*DQ), sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*Dflat*E), sin(2*pi*C*H), sin(2*pi*G*Q), sin(2*pi*Bflat*Q), sin(2*pi*C*DQ), sin(2*pi*Bflat*Q), sin(2*pi*G*Q)];

sound(z, fs) % Plays the rescaled song wavwrite(z, fs, 'Question1C.wav'); %Writes song into wav file

Media:Question1C.wav

%HW 1 Problem 2

clear all clc

[x,f] = wavread('Beatles.wav'); %Reads Beatles wav file and places it a matrix x and variable f for the function y = flipud(x); %System which flips the data for the song allowing it to be reveresed

wavplay(y,f) % Plays the reversed song wavwrite(y, f, 'Question2.wav'); %Writes song into wav % The reverse song doesn't sound like anything to me. After a quick google % search its suppose to say "turn me on dead man" and then can I kind of % hear it.

Media:Question2.wav

Alumni Liaison

Prof. Math. Ohio State and Associate Dean
Outstanding Alumnus Purdue Math 2008

Jeff McNeal