Revision as of 21:38, 17 January 2011 by Pbuason (Talk | contribs)

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

 %Plengrapin Buason
%ECE301 Spring 2011 Homework#1
%Explanation: This program is designed to play the song called Smoke on the
%Water in 3 different ways.

clc;
clear all;

%Questions 1
%Part1
%Explanation: This program is designed to play the main melody of the song
%"Smoke On The Water".

delta_t = 0.00005; %determind the length of each tempo

q_l = 60/112; %quarter length
e_l = q_l/2; %eighth length
dq_l = q_l*1.5; %dotted quarter length
half_note = 2*q_l; %half-note length

%Note lengths calculated in seconds
Q = 0:delta_t:q_l;
E = 0:delta_t:e_l;
DQ = 0:delta_t:dq_l;
H = 0:delta_t:half_note;

freq_A = 440; %frequency of A
freq_G = (2^(-2/12))*freq_A; %frequency of G
freq_Bflat = (2^(1/12))*freq_A; %frequency of B-flat
freq_C = (2^(3/12))*freq_A; %frequency of C
freq_Dflat = (2^(4/12))*freq_A; %frequency of D-flat

G_Q = sin(2*pi*freq_G*Q); %generate G,Q
Bflat_Q = sin(2*pi*freq_Bflat*Q);%genertae B-flat,Q
C_DQ = sin(2*pi*freq_C*DQ); %generate C,DQ
Dflat_E = sin(2*pi*freq_Dflat*E);%generate Dflat,E
Half_C = sin(2*pi*freq_C*H); %generate C,H

music1= [G_Q,Bflat_Q,C_DQ,G_Q,Bflat_Q,Dflat_E,Half_C,G_Q,Bflat_Q,C_DQ,Bflat_Q,G_Q]; %show the order of notes
sound(music1,1/delta_t); %play the music

wavwrite(music1,1/delta_t,'smokeonthewater1.wav'); %save a file

pause(5); %pause for 5 seconds

%Question1
%Part2
%Explanation: The tune of part1 is played 2 times faster.

%Note length calculated in seconds
Q2 = 0:delta_t:(q_l)/2;
E2 = 0:delta_t:(e_l)/2;
DQ2 = 0:delta_t:(dq_l)/2;
H2 = 0:delta_t:(half_note)/2;

%frequency of A, G, B-fat, C, and D-flat respectively
freq_A = 440;
freq_G = (2^(-2/12))*freq_A;
freq_Bflat = (2^(1/12))*freq_A;
freq_C = (2^(3/12))*freq_A;
freq_Dflat = (2^(4/12))*freq_A;

%generate GQ, B-flatQ, DQC, D-flatE and CHalf respectively
G_Q2 = sin(2*pi*freq_G*Q2);
Bflat_Q2 = sin(2*pi*freq_Bflat*Q2);
C_DQ2 = sin(2*pi*freq_C*DQ2);
Dflat_E2 = sin(2*pi*freq_Dflat*E2);
Half_C2 = sin(2*pi*freq_C*H2);

music2 = [G_Q2,Bflat_Q2,C_DQ2,G_Q2,Bflat_Q2,Dflat_E2,Half_C2,G_Q2,Bflat_Q2,C_DQ2,Bflat_Q2,G_Q2]; %show the order of notes
sound(music2,1/delta_t); %play the music

wavwrite(music2,1/delta_t,'smokeonthewater2.wav'); %save a file

pause(5); %pause for 5 seconds

%Question1
%Part3
%Explanation: Rescale the signal x(t) from part 1 according to the
%transformation y(t) = x(2t).

%Note length calculated in seconds
Q = 0:delta_t:(q_l);
E = 0:delta_t:(e_l);
DQ = 0:delta_t:(dq_l);
H = 0:delta_t:(half_note);

%frequency of A, G, B-fat, C, and D-flat respectively
freq_A3 = 880;
freq_G3 = (2^(-2/12))*freq_A3;
freq_Bflat3 = (2^(1/12))*freq_A3;
freq_C3 = (2^(3/12))*freq_A3;
freq_Dflat3 = (2^(4/12))*freq_A3;

%generate GQ, B-flatQ, DQC, D-flatE and CHalf respectively
G_Q3 = sin(2*pi*freq_G3*Q);
Bflat_Q3 = sin(2*pi*freq_Bflat3*Q);
C_DQ3 = sin(2*pi*freq_C3*DQ);
Dflat_E3 = sin(2*pi*freq_Dflat3*E);
Half_C3 = sin(2*pi*freq_C3*H);

music3 = [G_Q3,Bflat_Q3,C_DQ3,G_Q3,Bflat_Q3,Dflat_E3,Half_C3,G_Q3,Bflat_Q3,C_DQ3,Bflat_Q3,G_Q3]; %show the order of the notes
sound(music3,1/delta_t); %play the music
wavwrite(music3,1/delta_t,'smokeonthewater3.wav'); %save a file
pause(5); %pause for 5 seconds

%Question2
%Explanation: Extract the subliminal message by playing the extract
%backwards.
clear all;
clc;

[beatles, Fs] = wavread('Beatles.wav'); %read the file
Beatles_reversed = flipud(beatles); %reverse the song
sound(Beatles_reversed,Fs); %play the music
wavwrite(Beatles_reversed,Fs,'Beatles_reversed.wav');%save the sound file

%Questions
%1. The forward repeated phrase is 'number nine'.
%2. The reverse song contains a message. I believe the message is 'Turn me
%on, gentleman.'

File:Smokeonthewater1.wav

File:Smokeonthewater2.wav

File:Smokeonthewater3.wav

File:Beatles reversed.wav

Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn