(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
== Wav Files ==
 +
* a. [[Media: music-a_ECE301Fall2008mboutin.wav|part a]] (normal speed)
 +
* b. [[Media: music-b_ECE301Fall2008mboutin.wav|part b]] (fast speed)
 +
* c. [[Media: music-c_ECE301Fall2008mboutin.wav|part c]] (higher pitch)
 +
 +
== Matlab Code ==
 +
 
<pre>
 
<pre>
 
%Hetong Li
 
%Hetong Li
Line 6: Line 13:
 
clear;
 
clear;
 
clc;
 
clc;
scale=1; %initialize scale
 
t=[];
 
delta=0.0005;
 
%define frequencies for each tone
 
for n=1:19
 
    freq(n)=220*2^((n-1)/12);
 
end
 
A=freq(1);   
 
Bb=freq(2); 
 
B=freq(3);   
 
C=freq(4);   
 
Db=freq(5); 
 
D=freq(6);   
 
Eb=freq(7);   
 
E=freq(8);   
 
F=freq(9);
 
Gb=freq(10);   
 
G=freq(11);   
 
A2b=freq(12);   
 
A2=freq(13);   
 
B2b=freq(14);   
 
B2=freq(15);   
 
C2=freq(16);   
 
D2b=freq(17);   
 
D2=freq(18);   
 
E2b=freq(19);   
 
O=0;     
 
%define durations
 
P=60/172;
 
TP=P*2; 
 
FP=P*4; 
 
THP=P*3; 
 
QP=P*1.5;
 
H=P/2;
 
%Notes and Duration   
 
x = [Eb,F,G,A2b,G,A2b,G,A2b,G,A2b,B2b,A2b,Eb,F,G,O, ...
 
    G,A2b,A2,B2b,A2,B2b,A2,B2b,A2,B2b,C2,B2b,Eb,D2b,C2,O, ...
 
    Eb,F,G,A2b,G,A2b,G,A2b,G,A2b,E2b,C2,B2b,A2b,D2b,A2b,A2b, ...
 
    B2b,B2b,B2,B2,C2,D2b,E2b,C2,B2b,A2b,C2,B2b,B2b, ...
 
    Eb,F,G,A2b,B2b,C2,C2,D2b,D2b,D2b,A2b,B2b,B2,C2, ...
 
    C2,C2,B2b,A2b,B2b,C2,C2,B2b,F,G,A2b,G,F,B2b, ...
 
    Eb,Eb,F,G,A2b,B2b,C2,C2,C2, ...
 
    D2b,D2b,A2b,B2b,C2,O,F,G, ...
 
    A2b,F,Eb,A2b,C2,Eb,C2,B2b,A2b,A2b];
 
 
 
dur = [P,P,P,P,P,P,H,H,H,H,P,P,P,P,THP,P, ...
 
      P,P,P,P,P,P,H,H,H,H,P,P,P,P,THP,P, ...
 
      P,P,P,P,P,P,H,H,H,H,P,P,P,P,THP,H,H, ...
 
      QP,H,QP,H,QP,H,H,H,H,H,TP,TP,FP, ...
 
      TP,P,P,QP,H,P,P,P,H,H,P,H,H,FP, ...
 
      TP,P,P,QP,H,P,P,P,H,H,P,H,H,FP, ...
 
      QP,H,P,P,QP,H,P,H,H, ...
 
      P,P,P,P,THP,P,QP,H, ...
 
      P,P,P,P,TP,QP,H,QP,H,THP];
 
% I almost know nothing about music thoery,so I referred to previous submitted hws for frequency formula.
 
% and notes of hail purdue.
 
  
part = input('Please choose the partyou want to play(a,b,c):','s');
+
% PART A
y=[];
+
 
if(strcmp(part,'a'))
+
delta = 0.0005;
    for i = 1:length(dur)
+
H=0:delta: 1;          %half
        t = 0:delta:dur(i);  
+
Q=0:delta:0.5;        %quacter
        y = sin(2*pi*x(i)*t*scale);
+
DQ_time=0:delta:0.75;  %dotted quacter
        sound(y,1/delta);
+
EN=0:delta:0.25;      %one eighth
    end
+
 
elseif(strcmp(part,'b'))
+
%Assign signals for each used note
    dur=dur./2;
+
AH = sin(2*pi*220*H);
    for i = 1:length(dur)
+
BQ= sin(2*pi*493.88/2*Q);
        t = 0:delta:dur(i);  
+
DBQ=sin(2*pi*277.18*Q);
        y= sin(2*pi*x(i)*t*scale);
+
DDQ = sin(2*pi*293.66*DQ_time);
        sound(y,1/delta);
+
DQ = sin(2*pi*293.66*Q);
    end
+
EEN =sin(2*pi*329.63*EN);
elseif(strcmp(part,'c'))
+
GBQ=sin(2*pi*369.99*Q);
    scale=2;
+
GQ=sin(2*pi*392*Q);
    for i = 1:length(dur)
+
GEN=sin(2*pi*392*EN);
        t = 0:delta:dur(i);  
+
FEN= sin(2*pi*349.23*EN);
        y = sin(2*pi*x(i)*t*scale);
+
GBEN=sin(2*pi*369.99*EN);
        sound(y,1/delta);
+
 
    end
+
notes= [AH BQ DBQ DDQ EEN GBQ GBQ GQ GEN GEN DQ EEN FEN GBEN];
else
+
 
    fprintf('Sorry,there is no corresponding part');
+
sound (notes,1/delta);
end
+
wavwrite(notes,1/delta,32,'music-a.wav');
 +
 
 +
% PART B
 +
 
 +
%half the duration
 +
%we will hear the some plays at twice speed as before
 +
 
 +
delta = 0.0005;
 +
H=0:delta: 0.5;
 +
Q=0:delta:0.25;
 +
DQ_time=0:delta:0.375;
 +
EN=0:delta:0.125;
 +
 
 +
AH = sin(2*pi*220*H);
 +
BQ= sin(2*pi*493.88/2*Q);
 +
DBQ=sin(2*pi*277.18*Q);
 +
DDQ = sin(2*pi*293.66*DQ_time);
 +
DQ = sin(2*pi*293.66*Q);
 +
EEN =sin(2*pi*329.63*EN);
 +
GBQ=sin(2*pi*369.99*Q);
 +
GQ=sin(2*pi*392*Q);
 +
GEN=sin(2*pi*392*EN);
 +
FEN= sin(2*pi*349.23*EN);
 +
GBEN=sin(2*pi*369.99*EN);
 +
 
 +
notes= [AH BQ DBQ DDQ EEN GBQ GBQ GQ GEN GEN DQ EEN FEN GBEN];
 +
 
 +
sound (notes,1/delta);
 +
wavwrite(notes,1/delta,32,'music-b.wav');
 +
 
 +
% PART C
 +
 
 +
%Change the duration back to part a
 +
delta = 0.0005;
 +
H=0:delta: 1;
 +
Q=0:delta:0.5;
 +
DQ_time=0:delta:0.75;
 +
EN=0:delta:0.25;
 +
 
 +
%as we replace t with 2t,so double the time in signal function
 +
%which also means double the frequency of each signal
 +
%we will hear a song with higher pitch
 +
 
 +
AH = sin(2*pi*2*220*H);
 +
BQ= sin(2*pi*2*493.88/2*Q);
 +
DBQ=sin(2*pi*2*277.18*Q);
 +
DDQ = sin(2*pi*2*293.66*DQ_time);
 +
DQ = sin(2*pi*2*293.66*Q);
 +
EEN =sin(2*pi*2*329.63*EN);
 +
GBQ=sin(2*pi*2*369.99*Q);
 +
GQ=sin(2*pi*2*392*Q);
 +
GEN=sin(2*pi*2*392*EN);
 +
FEN= sin(2*pi*2*349.23*EN);
 +
GBEN=sin(2*pi*2*369.99*EN);
 +
 
 +
notes= [AH BQ DBQ DDQ EEN GBQ GBQ GQ GEN GEN DQ EEN FEN GBEN];
 +
 
 +
 
 +
sound (notes,1/delta);
 +
wavwrite(notes,1/delta,32,'music-c.wav');

Latest revision as of 17:52, 3 September 2008

Wav Files

Matlab Code

%Hetong Li
%09/01/08
%ECE301 hw1.1

clear;
clc;

% PART A

delta = 0.0005;
H=0:delta: 1;          %half
Q=0:delta:0.5;         %quacter
DQ_time=0:delta:0.75;  %dotted quacter
EN=0:delta:0.25;       %one eighth

%Assign signals for each used note
AH = sin(2*pi*220*H);
BQ= sin(2*pi*493.88/2*Q);
DBQ=sin(2*pi*277.18*Q);
DDQ = sin(2*pi*293.66*DQ_time);
DQ = sin(2*pi*293.66*Q);
EEN =sin(2*pi*329.63*EN);
GBQ=sin(2*pi*369.99*Q);
GQ=sin(2*pi*392*Q);
GEN=sin(2*pi*392*EN);
FEN= sin(2*pi*349.23*EN);
GBEN=sin(2*pi*369.99*EN);

notes= [AH BQ DBQ DDQ EEN GBQ GBQ GQ GEN GEN DQ EEN FEN GBEN];

sound (notes,1/delta);
wavwrite(notes,1/delta,32,'music-a.wav');

% PART B

%half the duration
%we will hear the some plays at twice speed as before

delta = 0.0005;
H=0:delta: 0.5;
Q=0:delta:0.25;
DQ_time=0:delta:0.375;
EN=0:delta:0.125;

AH = sin(2*pi*220*H);
BQ= sin(2*pi*493.88/2*Q);
DBQ=sin(2*pi*277.18*Q);
DDQ = sin(2*pi*293.66*DQ_time);
DQ = sin(2*pi*293.66*Q);
EEN =sin(2*pi*329.63*EN);
GBQ=sin(2*pi*369.99*Q);
GQ=sin(2*pi*392*Q);
GEN=sin(2*pi*392*EN);
FEN= sin(2*pi*349.23*EN);
GBEN=sin(2*pi*369.99*EN);

notes= [AH BQ DBQ DDQ EEN GBQ GBQ GQ GEN GEN DQ EEN FEN GBEN];

sound (notes,1/delta);
wavwrite(notes,1/delta,32,'music-b.wav');

% PART C

%Change the duration back to part a
delta = 0.0005;
H=0:delta: 1;
Q=0:delta:0.5;
DQ_time=0:delta:0.75;
EN=0:delta:0.25;

%as we replace t with 2t,so double the time in signal function
%which also means double the frequency of each signal
%we will hear a song with higher pitch

AH = sin(2*pi*2*220*H);
BQ= sin(2*pi*2*493.88/2*Q);
DBQ=sin(2*pi*2*277.18*Q);
DDQ = sin(2*pi*2*293.66*DQ_time);
DQ = sin(2*pi*2*293.66*Q);
EEN =sin(2*pi*2*329.63*EN);
GBQ=sin(2*pi*2*369.99*Q);
GQ=sin(2*pi*2*392*Q);
GEN=sin(2*pi*2*392*EN);
FEN= sin(2*pi*2*349.23*EN);
GBEN=sin(2*pi*2*369.99*EN);

notes= [AH BQ DBQ DDQ EEN GBQ GBQ GQ GEN GEN DQ EEN FEN GBEN];


sound (notes,1/delta);
wavwrite(notes,1/delta,32,'music-c.wav');

Alumni Liaison

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood