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

Revision as of 12:19, 4 September 2008

%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

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett