Revision as of 12:19, 4 September 2008 by Drmorris (Talk)

%Dan Morris
%drmorris@purdue.edu
%EE 301 Hw1.1
clear;clc;
%define sampling rate as 20 kHz
delta=1/20000;
%now define the duration of each note, take quater note (q) to be 172 bpm.
q=60/172;  %quater
h=2*q;     %half 
w=4*q;     %whole
e=q/2;     %eighth
dotq=3/2*q;   %dotted quater
doth=3*q;     %dotted half
%now define the note frequencies
x=3/5*440;   %(440=5x/3 => x=3*440/5 => x=264)
A=5/3*x;
B=15/8*x;
C=x;
D=9*x/8;
Db= 277.18;
E=5/4*x;
F=4/3*x;
G=3/2*x;
Gb= 369.99;
%now to define the song using arrays
notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb];
duration=[h,q,q,dotq,e,q,q,q,e,e,q,e,e,doth]; 
%A) now to play the song at normal speed
for n=1:length(notes)
    time=1:delta:duration(i);
    song=sin(2*pi*notes(i)*time);
    sound(song, 1/delta);
end
pause(3)
%B) now to play the song at twice as fast
for n=1:length(notes)
    time=1:delta:0.5*duration(i);
    song=sin(2*pi*notes(i)*time);
    sound(song, 1/delta);
end
pause(3)
%C) now play the song x(t) scaled to y(t) = x(2t) 
for n=1:length(notes)
    time=1:delta:duration(i);
    song=sin(2*2*pi*notes(i)*time);
    sound(song, 1/delta);
end

Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn