Line 2: | Line 2: | ||
clear all | clear all | ||
+ | |||
clc | clc | ||
f_A = 440; % Frequency of A4 | f_A = 440; % Frequency of A4 | ||
+ | |||
tempo = 112/60; % Tempo of the song | tempo = 112/60; % Tempo of the song | ||
+ | |||
delta = 5e-5; % Spacing between data | delta = 5e-5; % Spacing between data | ||
+ | |||
fs = 1/delta; % Frequency at which the song will be played | fs = 1/delta; % Frequency at which the song will be played | ||
+ | |||
G = 2^(-2/12)*f_A; % Calculates the frequency of G | G = 2^(-2/12)*f_A; % Calculates the frequency of G | ||
+ | |||
C = 2^(3/12)*f_A; % Calculates the frequency of C | C = 2^(3/12)*f_A; % Calculates the frequency of C | ||
+ | |||
Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat | Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat | ||
+ | |||
Dflat = 2^(4/12)*f_A; % Calculates the frequency of D 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 | 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 | 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 | 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 | 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 | % 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)]; | + | |
+ | 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 | sound(z, fs) % Plays the song | ||
+ | |||
wavwrite(z, fs, 'Question1A.wav'); %Writes song into wav file | wavwrite(z, fs, 'Question1A.wav'); %Writes song into wav file | ||
+ | |||
[[Media:Question1A.wav]] | [[Media:Question1A.wav]] | ||
+ | |||
%HW 1 Problem 1b | %HW 1 Problem 1b | ||
clear all | clear all | ||
+ | |||
clc | clc | ||
+ | |||
f_A = 440; % Frequency of A4 | f_A = 440; % Frequency of A4 | ||
+ | |||
tempo = 112/60; % Tempo of the song | tempo = 112/60; % Tempo of the song | ||
+ | |||
delta = 5e-5; % Spacing between data | delta = 5e-5; % Spacing between data | ||
+ | |||
fs = 1/delta; % Frequency at which the song will be played | fs = 1/delta; % Frequency at which the song will be played | ||
+ | |||
G = 2^(-2/12)*f_A; % Calculates the frequency of G | G = 2^(-2/12)*f_A; % Calculates the frequency of G | ||
+ | |||
C = 2^(3/12)*f_A; % Calculates the frequency of C | C = 2^(3/12)*f_A; % Calculates the frequency of C | ||
+ | |||
Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat | Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat | ||
+ | |||
Dflat = 2^(4/12)*f_A; % Calculates the frequency of D 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 | 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 | 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 | 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 | 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 | % 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)]; | 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 | 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 | wavwrite(z ,fs ,'Question1B.wav'); %Writes song into wav file | ||
− | + | ||
%HW 1 Problem 1c | %HW 1 Problem 1c | ||
+ | |||
clear all | clear all | ||
+ | |||
clc | clc | ||
+ | |||
f_A = 440; % Frequency of A4 | f_A = 440; % Frequency of A4 | ||
+ | |||
tempo = 112/60; % Tempo of the song | tempo = 112/60; % Tempo of the song | ||
+ | |||
delta = 5e-5; % Spacing between data | delta = 5e-5; % Spacing between data | ||
+ | |||
fs = 1/delta; % Frequency at which the song will be played | 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) | 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 | G = 2^(-2/12)*f_A; % Calculates the frequency of G | ||
+ | |||
C = 2^(3/12)*f_A; % Calculates the frequency of C | C = 2^(3/12)*f_A; % Calculates the frequency of C | ||
+ | |||
Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat | Bflat = 2^(1/12)*f_A; % Calculates the frequency of B flat | ||
+ | |||
Dflat = 2^(4/12)*f_A; % Calculates the frequency of D 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 | 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 | 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 | 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 | 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 | % 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)]; | 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 | sound(z, fs) % Plays the rescaled song | ||
+ | |||
wavwrite(z, fs, 'Question1C.wav'); %Writes song into wav file | wavwrite(z, fs, 'Question1C.wav'); %Writes song into wav file | ||
+ | |||
[[Media:Question1C.wav]] | [[Media:Question1C.wav]] | ||
+ | |||
%HW 1 Problem 2 | %HW 1 Problem 2 | ||
+ | |||
clear all | clear all | ||
+ | |||
clc | clc | ||
+ | |||
[x,f] = wavread('Beatles.wav'); %Reads Beatles wav file and places it a matrix x and variable f for the function | [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 | y = flipud(x); %System which flips the data for the song allowing it to be reveresed | ||
+ | |||
wavplay(y,f) % Plays the reversed song | wavplay(y,f) % Plays the reversed song | ||
+ | |||
wavwrite(y, f, 'Question2.wav'); %Writes song into wav | wavwrite(y, f, 'Question2.wav'); %Writes song into wav | ||
+ | |||
% The reverse song doesn't sound like anything to me. After a quick google | % 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 | % search its suppose to say "turn me on dead man" and then can I kind of |
Revision as of 16:46, 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 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.