Line 9: Line 9:
 
for i = 1:1:3   
 
for i = 1:1:3   
 
%% a loop to perform three iterations for parts a,b,c
 
%% a loop to perform three iterations for parts a,b,c
 +
  
 
delta = 0.00005 ;   
 
delta = 0.00005 ;   
 
%sampling rate
 
%sampling rate
 +
  
 
if x == 2
 
if x == 2
 
   bpm = 2*112  ;  
 
   bpm = 2*112  ;  
 
%beats per minute for parts a and c
 
%beats per minute for parts a and c
 +
  
 
else
 
else
 
     bpm = 112 ;  
 
     bpm = 112 ;  
 
%beats per minute for part b
 
%beats per minute for part b
 +
  
 
end
 
end
 +
  
 
bps = 60/bpm ; %beats per second
 
bps = 60/bpm ; %beats per second
 +
  
 
rest= 0:delta:3*bps;   
 
rest= 0:delta:3*bps;   
 
% there is a three beat rest at the end of the song
 
% there is a three beat rest at the end of the song
 +
  
 
q = 0:delta:bps ;  
 
q = 0:delta:bps ;  
 
% length of a quarter note in terms of tempo
 
% length of a quarter note in terms of tempo
 +
  
 
h = 0:delta:2*bps  ;  
 
h = 0:delta:2*bps  ;  
 
% length of a half note in terms of tempo
 
% length of a half note in terms of tempo
 +
  
 
e = 0:delta:0.5*bps  ;  
 
e = 0:delta:0.5*bps  ;  
 
% length of an eighth note in terms of tempo
 
% length of an eighth note in terms of tempo
 +
  
 
dq = 0:delta:1.5*bps  ;  
 
dq = 0:delta:1.5*bps  ;  
 
% length of a dotted quarter note in terms of tempo  
 
% length of a dotted quarter note in terms of tempo  
 +
  
 
if x==3
 
if x==3
 
A_note = 2*440 ;   
 
A_note = 2*440 ;   
%Pitch frequency for A4
+
%%changes the pitch by multiplying the A4 frequency by two
 +
 
  
 
G_note = 2^(-2/12)*A_note  ;
 
G_note = 2^(-2/12)*A_note  ;
 
%Pitch frequency for G
 
%Pitch frequency for G
 +
  
 
Bflat_note =  2^(1/12)*A_note  ;
 
Bflat_note =  2^(1/12)*A_note  ;
 
%Pitch frequency for B flat
 
%Pitch frequency for B flat
 +
  
 
C_note = 2^(3/12)*A_note  ;
 
C_note = 2^(3/12)*A_note  ;
 
%Pitch frequency for C
 
%Pitch frequency for C
 +
  
 
Dflat_note = 2^(4/12)*A_note  ;
 
Dflat_note = 2^(4/12)*A_note  ;
 
%Pitch frequency for D flat
 
%Pitch frequency for D flat
 +
  
 
else   
 
else   
%%changes the pitch by multiplying the A4 frequency by two
+
 
  
 
A_note = 440 ;   
 
A_note = 440 ;   
 
%Pitch frequency for A4
 
%Pitch frequency for A4
 +
  
 
G_note = 2^(-2/12)*A_note  ;
 
G_note = 2^(-2/12)*A_note  ;
 
%Pitch frequency for G
 
%Pitch frequency for G
 +
  
 
Bflat_note =  2^(1/12)*A_note  ;
 
Bflat_note =  2^(1/12)*A_note  ;
 
%Pitch frequency for B flat
 
%Pitch frequency for B flat
 +
  
 
C_note = 2^(3/12)*A_note  ;
 
C_note = 2^(3/12)*A_note  ;
 
%Pitch frequency for C
 
%Pitch frequency for C
 +
  
 
Dflat_note = 2^(4/12)*A_note  ;
 
Dflat_note = 2^(4/12)*A_note  ;
 
%Pitch frequency for D flat   
 
%Pitch frequency for D flat   
 
      
 
      
 +
 
end
 
end
  
Line 79: Line 100:
 
Gq = sin(2*pi*G_note*q) ;   
 
Gq = sin(2*pi*G_note*q) ;   
 
%% Standard function for quarter note, G pitch
 
%% Standard function for quarter note, G pitch
 +
  
 
Bfq = sin(2*pi*Bflat_note*q) ;   
 
Bfq = sin(2*pi*Bflat_note*q) ;   
 
%% Standard function for quarter note, B flat pitch
 
%% Standard function for quarter note, B flat pitch
 +
  
 
Ch = sin(2*pi*C_note*h) ;   
 
Ch = sin(2*pi*C_note*h) ;   
 
%% Standard function for half note, C pitch
 
%% Standard function for half note, C pitch
 +
  
 
Cdq = sin(2*pi*C_note*dq) ;   
 
Cdq = sin(2*pi*C_note*dq) ;   
 
%% Standard function for dotted quarter note, C pitch
 
%% Standard function for dotted quarter note, C pitch
 +
  
 
Dfe = sin(2*pi*Dflat_note*e) ;   
 
Dfe = sin(2*pi*Dflat_note*e) ;   
 
%% Standard function for eighth note, D flat pitch
 
%% Standard function for eighth note, D flat pitch
 +
  
  
 
smoke_song = [Gq,Bfq,Cdq,Gq,Bfq,Dfe,Ch,Gq,Bfq,Cdq,Bfq,Gq,rest];
 
smoke_song = [Gq,Bfq,Cdq,Gq,Bfq,Dfe,Ch,Gq,Bfq,Cdq,Bfq,Gq,rest];
 +
  
 
if x==1
 
if x==1
Line 99: Line 126:
 
wavwrite(smoke_song,1/delta, 'normal_smoke_on_the_water');
 
wavwrite(smoke_song,1/delta, 'normal_smoke_on_the_water');
 
elseif x==2
 
elseif x==2
 +
 +
 
sound(smoke_song, 1/delta);
 
sound(smoke_song, 1/delta);
 +
 
wavwrite(smoke_song,1/delta, 'fast_smoke_on_the_water');
 
wavwrite(smoke_song,1/delta, 'fast_smoke_on_the_water');
 
else
 
else
 +
 +
 
sound(smoke_song, 1/delta);
 
sound(smoke_song, 1/delta);
 +
 
wavwrite(smoke_song,1/delta, 'highpitch_smoke_on_the_water');
 
wavwrite(smoke_song,1/delta, 'highpitch_smoke_on_the_water');
 +
  
 
end
 
end

Latest revision as of 08:18, 19 January 2011

clc

clear

% Part 1

x = 1; 

%initializes counter for iterations for i = 1:1:3 %% a loop to perform three iterations for parts a,b,c


delta = 0.00005 ; %sampling rate


if x == 2

  bpm = 2*112  ; 

%beats per minute for parts a and c


else

   bpm = 112 ; 

%beats per minute for part b


end


bps = 60/bpm ; %beats per second


rest= 0:delta:3*bps; % there is a three beat rest at the end of the song


q = 0:delta:bps ; % length of a quarter note in terms of tempo


h = 0:delta:2*bps  ; % length of a half note in terms of tempo


e = 0:delta:0.5*bps  ; % length of an eighth note in terms of tempo


dq = 0:delta:1.5*bps  ; % length of a dotted quarter note in terms of tempo


if x==3 A_note = 2*440 ; %%changes the pitch by multiplying the A4 frequency by two


G_note = 2^(-2/12)*A_note  ; %Pitch frequency for G


Bflat_note = 2^(1/12)*A_note  ; %Pitch frequency for B flat


C_note = 2^(3/12)*A_note  ; %Pitch frequency for C


Dflat_note = 2^(4/12)*A_note  ; %Pitch frequency for D flat


else


A_note = 440 ; %Pitch frequency for A4


G_note = 2^(-2/12)*A_note  ; %Pitch frequency for G


Bflat_note = 2^(1/12)*A_note  ; %Pitch frequency for B flat


C_note = 2^(3/12)*A_note  ; %Pitch frequency for C


Dflat_note = 2^(4/12)*A_note  ; %Pitch frequency for D flat


end


Gq = sin(2*pi*G_note*q) ; %% Standard function for quarter note, G pitch


Bfq = sin(2*pi*Bflat_note*q) ; %% Standard function for quarter note, B flat pitch


Ch = sin(2*pi*C_note*h) ; %% Standard function for half note, C pitch


Cdq = sin(2*pi*C_note*dq) ; %% Standard function for dotted quarter note, C pitch


Dfe = sin(2*pi*Dflat_note*e) ; %% Standard function for eighth note, D flat pitch


smoke_song = [Gq,Bfq,Cdq,Gq,Bfq,Dfe,Ch,Gq,Bfq,Cdq,Bfq,Gq,rest];


if x==1 sound(smoke_song, 1/delta); wavwrite(smoke_song,1/delta, 'normal_smoke_on_the_water'); elseif x==2


sound(smoke_song, 1/delta);

wavwrite(smoke_song,1/delta, 'fast_smoke_on_the_water'); else


sound(smoke_song, 1/delta);

wavwrite(smoke_song,1/delta, 'highpitch_smoke_on_the_water');


end

x=x+1;

end


%%Part 2

[song, fs] = wavread('Beatles.wav'); %Original clip says 'Number 9' repeatedly

reverse = flipud(song);

sound(20*reverse,fs); %% could not hear the song so had to amplify it

wavwrite(reverse,fs,'reverse_Beatles') %reversed clip sounds like 'Let me on, Desmond' repeatedly

Media:normal_smoke_on_the_water.wav
Media:fast_smoke_on_the_water.wav
Media:highpitch_smoke_on_the_water.wav
Media:reverse_Beatles.wav

Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn