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

Revision as of 11:26, 4 September 2008

Matlab Code

%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

Comments

I don't know how to upload the sound file.

Alumni Liaison

BSEE 2004, current Ph.D. student researching signal and image processing.

Landis Huffman