Line 2: Line 2:
 
%Hetong Li
 
%Hetong Li
 
%09/01/08
 
%09/01/08
%ECE301 hw1
+
%ECE301 hw1.1
  
 
clear;
 
clear;
 
clc;
 
clc;
%initialze basic variables
+
scale=1; %initialize scale
x=440*3/5;%basic frequency.
+
t=[];
 
delta=0.0005;
 
delta=0.0005;
dur=0.5;
+
%define frequencies for each tone
t=0:delta:dur;
+
for n=1:19
scale=1;
+
    freq(n)=220*2^((n-1)/12);
 
+
end
%assign frequencies for each tone.
+
A=freq(1);  
fmidC=x;
+
Bb=freq(2); 
fD=9*x/8;
+
B=freq(3);   
fE=5*x/4;
+
C=freq(4);  
fF=4*x/3;
+
Db=freq(5); 
fG=3*x/2;
+
D=freq(6);   
fA=5*x/3;
+
Eb=freq(7);   
fB=15*x/8;
+
E=freq(8);  
fupC=2*x;
+
F=freq(9);
 
+
Gb=freq(10);   
part = input('Please choose the part you want to play(a,b,c):','s');
+
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');
 +
y=[];
 
if(strcmp(part,'a'))
 
if(strcmp(part,'a'))
     dur=0.5;
+
     for i = 1:length(dur)
 +
        t = 0:delta:dur(i);
 +
        y = sin(2*pi*x(i)*t*scale);
 +
        sound(y,1/delta);
 +
    end
 
elseif(strcmp(part,'b'))
 
elseif(strcmp(part,'b'))
     dur=0.25;
+
     dur=dur./2;
 +
    for i = 1:length(dur)
 +
        t = 0:delta:dur(i);
 +
        y= sin(2*pi*x(i)*t*scale);
 +
        sound(y,1/delta);
 +
    end
 
elseif(strcmp(part,'c'))
 
elseif(strcmp(part,'c'))
 
     scale=2;
 
     scale=2;
 +
    for i = 1:length(dur)
 +
        t = 0:delta:dur(i);
 +
        y = sin(2*pi*x(i)*t*scale);
 +
        sound(y,1/delta);
 +
    end
 
else
 
else
 
     fprintf('Sorry,there is no corresponding part');
 
     fprintf('Sorry,there is no corresponding part');
 
end
 
end
 
t=0:delta:dur;
 
%assign signals of each tone.
 
midC=sin(2*pi*fmidC*t*scale);
 
D=sin(2*pi*fD*t*scale);
 
E=sin(2*pi*fE*t*scale);
 
F=sin(2*pi*fF*t*scale);
 
G=sin(2*pi*fG*t*scale);
 
A=sin(2*pi*fA*t*scale);
 
B=sin(2*pi*fB*t*scale);
 
upC=sin(2*pi*fupC*t*scale);
 
 
y=[midC,midC,G,G,A,A,G,G,F,F,E,E,D,D,midC];
 
sound(y,1/delta);
 

Revision as of 16:50, 1 September 2008

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

clear;
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');
y=[];
if(strcmp(part,'a'))
    for i = 1:length(dur)
        t = 0:delta:dur(i); 
        y = sin(2*pi*x(i)*t*scale);
        sound(y,1/delta);
    end
elseif(strcmp(part,'b'))
    dur=dur./2;
    for i = 1:length(dur)
        t = 0:delta:dur(i); 
        y= sin(2*pi*x(i)*t*scale);
        sound(y,1/delta);
    end
elseif(strcmp(part,'c'))
    scale=2;
    for i = 1:length(dur)
        t = 0:delta:dur(i); 
        y = sin(2*pi*x(i)*t*scale);
        sound(y,1/delta);
    end
else
    fprintf('Sorry,there is no corresponding part');
end

Alumni Liaison

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood