Revision as of 17:35, 18 January 2011 by Cprivera (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

%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

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett