(New page: %ECE 301 Homework 1 Problem 1 % Part 1: Play "Smoke on the Water" clear clc delta = 5E-5; %Establishes the time step for the code bpm = 112; %Establishes the tempo of the song bps = 112 /...)
 
Line 69: Line 69:
 
%a statement that repeats itself that possibly says "Turn me on deadman".
 
%a statement that repeats itself that possibly says "Turn me on deadman".
  
[[Media:Beatles.wave]]
+
[[Media:Beatles.wav]]

Revision as of 15:59, 18 January 2011

%ECE 301 Homework 1 Problem 1 % Part 1: Play "Smoke on the Water" clear clc

delta = 5E-5; %Establishes the time step for the code bpm = 112; %Establishes the tempo of the song bps = 112 / 60; %Converts tempo into beats per second spb = 1 / bps; %Converts tempo into seconds per beat

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

quarter_note = 0:delta:(1 * spb); %Establishes the amount of time a quarter note will be held eighth_note = 0:delta:((1 / 2) * spb); % Establishes the amount of time an eighth note will be held half_note = 0:delta:(2 * spb); % Establishes the amount of time a half note will be held dotted_quarter_note = 0:delta:((3 / 2) * spb); %Establishes the amount of time a dotted quarter not will be held

half_rest_size = half_note / delta; eighth_rest_size = eighth_note / delta;

G_q = sin(2 * pi * freq_G * quarter_note); Bflat_q = sin(2 * pi * freq_Bflat * quarter_note); C_dq = sin(2 * pi * freq_C * dotted_quarter_note); G_tied_e = sin(2 * pi * freq_G * eighth_note); Dflat_e = sin(2 * pi * freq_Dflat * eighth_note); C_h = sin(2 * pi * freq_C * half_note); Bflat_tied_e = sin(2 * pi * freq_Bflat * eighth_note); eighth_rest = zeros(eighth_rest_size , 1); half_rest = zeros(half_rest_size , 1);

%Now that all the frequencies and values of the notes above have been %established, all that is left is to arrange them in the proper order as %shown by the music provided and to play the notes using the sound %function. Notes = [G_q,Bflat_q,C_dq,G_tied_e,G_tied_e,Bflat_q,Dflat_e,C_h,G_q,Bflat_q,C_dq,Bflat_tied_e,Bflat_tied_e,G_q,eighth_rest,half_rest]; sound(Notes , 1 / delta)

%Part 2: Play Song Two Times Faster sound(Notes, 2 / delta) %Scales the time step in order to play the song faster

%Part 3: Rescale Song to make y(t) = x(2t) G_q_new = sin(4 * pi * freq_G * quarter_note); Bflat_q_new = sin(4 * pi * freq_Bflat * quarter_note); C_dq_new = sin(4 * pi * freq_C * dotted_quarter_note); G_tied_e_new = sin(4 * pi * freq_G * eighth_note); Dflat_e_new = sin(4 * pi * freq_Dflat * eighth_note); C_h_new = sin(4 * pi * freq_C * half_note); Bflat_tied_e_new = sin(4 * pi * freq_Bflat * eighth_note); eighth_rest = zeros(eighth_rest_size , 1); half_rest = zeros(half_rest_size , 1);

%Above, all the notes that will be played in the piece have been altered %in order to shift the notes one octave higher and now as in Part 1, the %new notes will be properly arranged as denoted by the music provided. New_Notes = [G_q_new,Bflat_q_new,C_dq_new,G_tied_e_new,G_tied_e_new,Bflat_q_new,Dflat_e_new,C_h_new,G_q_new,Bflat_q_new,C_dq_new,Bflat_tied_e_new,Bflat_tied_e_new,G_q_new,eighth_rest,half_rest]; sound(New_Notes , 1 / delta)

%ECE 301 Homework 1 Problem 2 %Import Beatles Song and Play Backwords [input,frequency] = wavread('Beatles.wav'); %Imports the wav audio file into MATLAB new_input = flipud(input); %Reverses the audio file imported in the previous step wavplay(10 * new_input,frequency) %Plays the reversed audio file and amplifies the sound in order for the person to properly hear the song.

%From the sound generated by reversing the Beatles song, there seems to be %a statement that repeats itself that possibly says "Turn me on deadman".

Media:Beatles.wav

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang