(5 intermediate revisions by the same user not shown) | |||
Line 88: | Line 88: | ||
wavwrite(z ,fs ,'Question1B.wav'); %Writes song into wav file | wavwrite(z ,fs ,'Question1B.wav'); %Writes song into wav file | ||
+ | |||
Line 149: | Line 150: | ||
− | [x,f] = wavread('Beatles.wav'); %Reads Beatles wav file and places it a matrix x and variable f for the | + | [x,f] = wavread('Beatles.wav'); %Reads Beatles wav file and places it a matrix x for the data and variable f for the frequency |
− | + | ||
y = flipud(x); %System which flips the data for the song allowing it to be reveresed | y = flipud(x); %System which flips the data for the song allowing it to be reveresed | ||
Latest revision as of 16:54, 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
%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
%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
%HW 1 Problem 2
clear all
clc
[x,f] = wavread('Beatles.wav'); %Reads Beatles wav file and places it a matrix x for the data and variable f for the frequency
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.