(New page: %ECE 301 Homework 1 %Zachary Flohr %Semester - Spring 2011 clear clc %PART1-A %Time and beat information fa = 440; %Hz BPM = 112; %beats per minute sec = 1/(112/60); %seconds per beat ...)
 
Line 1: Line 1:
 
%ECE 301 Homework 1
 
%ECE 301 Homework 1
 +
 
%Zachary Flohr
 
%Zachary Flohr
 +
 
%Semester - Spring 2011
 
%Semester - Spring 2011
  
 
clear
 
clear
 +
 
clc
 
clc
 +
  
 
%PART1-A
 
%PART1-A
  
 
%Time and beat information
 
%Time and beat information
 +
 
fa = 440; %Hz
 
fa = 440; %Hz
 +
 
BPM = 112; %beats per minute
 
BPM = 112; %beats per minute
 +
 
sec = 1/(112/60); %seconds per beat
 
sec = 1/(112/60); %seconds per beat
 +
  
 
%Length of each type of note
 
%Length of each type of note
 +
 
%This is an array of time for each note.  The time step is chosen to be
 
%This is an array of time for each note.  The time step is chosen to be
 +
 
%very small to get a good sampling rate
 
%very small to get a good sampling rate
  
 
timestep = 0.00001; %seconds
 
timestep = 0.00001; %seconds
 +
 
Half = 0:timestep:(2*sec); %half note
 
Half = 0:timestep:(2*sec); %half note
 +
 
Quarter = 0:timestep:(1*sec); %quarter note
 
Quarter = 0:timestep:(1*sec); %quarter note
 +
 
Eighth = 0:timestep:(0.5*sec); %eighth note
 
Eighth = 0:timestep:(0.5*sec); %eighth note
 +
 
DottedQuarter = 0:timestep:(1.5*sec); %dotted quarter note
 
DottedQuarter = 0:timestep:(1.5*sec); %dotted quarter note
  

Revision as of 13:00, 18 January 2011

%ECE 301 Homework 1

%Zachary Flohr

%Semester - Spring 2011

clear

clc


%PART1-A

%Time and beat information

fa = 440; %Hz

BPM = 112; %beats per minute

sec = 1/(112/60); %seconds per beat


%Length of each type of note

%This is an array of time for each note. The time step is chosen to be

%very small to get a good sampling rate

timestep = 0.00001; %seconds

Half = 0:timestep:(2*sec); %half note

Quarter = 0:timestep:(1*sec); %quarter note

Eighth = 0:timestep:(0.5*sec); %eighth note

DottedQuarter = 0:timestep:(1.5*sec); %dotted quarter note

%Composition of each note - Each frequency is produced for the needed time %of each note

Note1a = sin(2*pi*fa*2^(-2/12)*Quarter); Note2a = sin(2*pi*fa*2^(1/12)*Quarter); Note3a = sin(2*pi*fa*2^(3/12)*DottedQuarter); Note4a = sin(2*pi*fa*2^(-2/12)*Quarter); Note5a = sin(2*pi*fa*2^(1/12)*Quarter); Note6a = sin(2*pi*fa*2^(4/12)*Eighth); Note7a = sin(2*pi*fa*2^(3/12)*Half); Note8a = sin(2*pi*fa*2^(-2/12)*Quarter); Note9a = sin(2*pi*fa*2^(1/12)*Quarter); Note10a = sin(2*pi*fa*2^(3/12)*DottedQuarter); Note11a = sin(2*pi*fa*2^(1/12)*Quarter); Note12a = sin(2*pi*fa*2^(-2/12)*Quarter);

%Combine each of the notes into one sound file Smoke1 = [Note1a, Note2a, Note3a, Note4a, Note5a, Note6a, Note7a, Note8a, Note9a, Note10a, Note11a, Note12a];

%Play the finished sound file sound(Smoke1,1/timestep); wavwrite(Smoke1,1/timestep,'zflohr_ECE301_HW1_Part1a');


pause(6); %Has a pause between the different sound files

%PART1-B %Play the tune at twice the speed %Since the BPM doubles, then the length of each note is cut in half %The arrays of the notes will only be half the length as the original

timestep = 0.00001; %seconds Half = 0:timestep:(2*sec/2); %half note Quarter = 0:timestep:(1*sec/2); %quarter note Eighth = 0:timestep:(0.5*sec/2); %eighth note DottedQuarter = 0:timestep:(1.5*sec/2); %dotted quarter note

%Re-composition of each note - Calculated in the same manner as in Part 1 %with the length of the notes being altered.

Note1b = sin(2*pi*fa*2^(-2/12)*Quarter); Note2b = sin(2*pi*fa*2^(1/12)*Quarter); Note3b = sin(2*pi*fa*2^(3/12)*DottedQuarter); Note4b = sin(2*pi*fa*2^(-2/12)*Quarter); Note5b = sin(2*pi*fa*2^(1/12)*Quarter); Note6b = sin(2*pi*fa*2^(4/12)*Eighth); Note7b = sin(2*pi*fa*2^(3/12)*Half); Note8b = sin(2*pi*fa*2^(-2/12)*Quarter); Note9b = sin(2*pi*fa*2^(1/12)*Quarter); Note10b = sin(2*pi*fa*2^(3/12)*DottedQuarter); Note11b = sin(2*pi*fa*2^(1/12)*Quarter); Note12b = sin(2*pi*fa*2^(-2/12)*Quarter);

%Combine each of the notes into one sound file Smoke2 = [Note1b, Note2b, Note3b, Note4b, Note5b, Note6b, Note7b, Note8b, Note9b, Note10b, Note11b, Note12b];

%Play the finished tune sound(Smoke2,1/timestep); wavwrite(Smoke2,1/timestep,'zflohr_ECE301_HW1_Part1b');

pause(6); %Has a pause between the sound files

%PART1-C %Transform of y(t) = x(2t) %We can play the original sound file Smoke1 at a frequency twice as fast as %originally played. The length of the original notes remain in tact while %the playing frequency is affected by the transformation of y(t) = x(2t)

%Play original file at new frequency and write the sound file sound(Smoke1,2/timestep); wavwrite(Smoke1,2/timestep,'zflohr_ECE301_HW1_Part1c');

pause(6) %Has a pause between the sound files

%PART 2 - Beatles Song "Hidden Message" %The initial sound file is assumed to be in the same directory. The file %is read in and saved

[y,fs] = wavread('Beatles.wav');

%The flipud command reverses the array and saves it as z. I amplified the %file by 5 to better hear the output. z = flipud(y); z = z*5;

%The sound file is played and written to the file. sound(z,fs); wavwrite(z,fs,'zflohr_ECE301_HW1_Part2');

%The original sound file repeated the phrase "Number 9" over and over. The %reversed file has a repeated phrase as well, which sounds like "Turn me %on, dead man".

Alumni Liaison

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood