Revision as of 05:09, 5 September 2008 by Zhang79 (Talk)

MATLAB Code

% Hang Zhang
% ECE301
% Homework 1.1
% 9-5-08

%Preparation
clc
clear all

%Solve for X given 440Hz is an A note by using the directions given on instruction sheet.
A = 440;
x = 440*3/5;
upC = 2*x; %upper C
B = 15*x/8;
G = 3*x/2;
F = 4*x/3;
E = 5*x/4;
D = 9*x/8;
midC = x; %middle C

delta = 1/20000;

noteLength = .25;%length of note being played
noteList = [A, B, D, D*2, E, G, G, G*2, G*2, G*2, D*2, E, F, G]; %list of notes

song = [0];

%Normal speed
for count=1:length(noteList);
  t = 0:delta:0.5;
  song = [song sin(2*pi*t*noteList(count))];
end
sound(song, 1/delta);
wavwrite(song, 20000, 16, 'hailPurd_norm.wav');
fprintf('Press enter after music stops....\n')
pause

%Twice as fast
songFast = [0];
for count=1:length(noteList);
  t = 0:delta:0.25;
  songFast = [songFast sin(2*pi*t*noteList(count))];
end
sound(songFast, 1/delta);
wavwrite(songFast, 20000, 16, 'hailPurd_fast.wav');
fprintf('Press enter after music stops....\n')
pause

%Twice the frequency
songHigh = [0];
for count=1:length(noteList)
  t = 0:delta:0.5;
  songHigh = [songHigh sin(2*pi*t*2*noteList(count))];
end
sound(songHigh, 1/delta);
wavwrite(song, 20000, 16, 'hailPurd_highpitch.wav');

Sound Files

Normal Rate: Media:HailPurd_norm_ECE301Fall2008mboutin.wav

Fast Rate: Media:HailPurd_fast_ECE301Fall2008mboutin.wav

Higher pitched (but for some reason could not get to work): Media:HailPurd_highpitch_ECE301Fall2008mboutin.wav

Alumni Liaison

Have a piece of advice for Purdue students? Share it through Rhea!

Alumni Liaison