Notes

I used MATLAB to write the output vector to a wav file for me. It is linked here.

MATLAB Script


%header------------------------------------
%Benjamin Horst
%  September 2, 2008
%  ECE 301   ->   HW#1
%endheader---------------------------------
%start script------------------------------
%clear everything before running
clear
clc

%Define notes
A = 220;
B = 246.942;
Db = 277.183;
D = 293.665;
E = 329.628;
F = 349.228;
Gb = 369.994;
G = 391.995;
%Define the actual line of the song
songNotes = [A, B, Db, D, E, Gb, Gb, G, G, G, D, E, F, Gb ];
numberOfNotes = 14;  %useful in loops

%Define time step and time array
delta = .00005; %20kHz sample rate
noteTime = .1;  %the shortest note (appx)
%Define the durations of each note in the line
durations = [ 3, 2, 2, 3, 1, 2, 2, 2, 1, 1, 2, 1, 1, 3];

%Start an array for output...
CompleteSong = ones(1);

fprintf(1, 'Hail Hail to Old Purdue!\n')
pause(1);

%play the song normally
for i=1:numberOfNotes
    t = 0:delta:(durations(i)*noteTime);
    note = sin(2 * pi * songNotes(i) * t);
    sound(note, 1/delta);
    CompleteSong  = [CompleteSong, note];
end

pause(2);
fprintf(1, 'now, twice as fast....\n')
pause(2);

%add two second pause
pauseTime = ones(1, 1:delta:2);
CompleteSong = [CompleteSong, pauseTime];

%play the song 2x as fast
for i=1:numberOfNotes
    
        %note the '*.5' to make it faster
    t = 0:delta:(durations(i)*noteTime*.5); 
    note = sin(2 * pi * songNotes(i)*t); 
    sound(note, 1/delta);
    CompleteSong  = [CompleteSong, note];
end

pause(2);
fprintf(1, 'now transposed up as y(t)=x(2t)\n')
pause(2);

%add two second pause
CompleteSong = [CompleteSong, pauseTime];

%play the song as y(t) = x(2t)
for i=1:numberOfNotes
    t = 0:delta:(durations(i)*noteTime);
    
         %note the '* 2' at the end for transposing
    note = sin(2 * pi * songNotes(i) * t * 2);
    sound(note, 1/delta);
    CompleteSong  = [CompleteSong, note];
end
fprintf(1, 'we hope you enjoyed the show!\n\n')

%output final sound to .wav file
wavwrite(CompleteSong, 20000, 16, 'hailPU_result.wav');
%endscript---------------------------------

Alumni Liaison

Meet a recent graduate heading to Sweden for a Postdoctorate.

Christine Berkesch