Activity No 2
Sine Wave Tone Generation
( )= (2 ) (1)
A- amplitude
F- frequency in Hz (analog)
Setting the sampling rate to 8000 samples per second (common to PC sound cards), the
sampling period is 1/8000 or 0.000125. A 440Hz sine wave (the musical note 'do') can be
expressed as
%samplecode2-1.m
clear;
t=[0:0.000125:0.5] % from 0 to 0.5 second with 8000Hz sampling rate
a=sin(2*pi*440*t);
b=sin(2*pi*493.88*t);
cs=sin(2*pi*554.37*t);
d=sin(2*pi*587.33*t);
e=sin(2*pi*659.26*t);
fs=sin(2*pi*739.99*t);
line1=[a,a,e,e,fs,fs,e,e,];
line2=[d,d,cs,cs,b,b,a,a,];
line3=[e,e,d,d,cs,cs,b,b];
song=[line1,line2,line3,line3,line1,line2];
sound(song,8000);
Study the each line above and identify the purpose of each.
Alternatively, we can express equation 1 as a discrete time signal by applying the formula;
And since,
( )= (2 )
Thus we have,
( )= 2 (2)
440
= = 0.055 /
8000
( )= (2 0.055 )
%samplecode2-2.m
n=[0:4000] % 0.5 second duration
do=sin(2*pi*0.055*n);
sound(do,8000);
Problem 2.1. Rewrite the sample code 2-1 as a discrete time signal similar to what we did to
the note do in sample code 2-2. The increments are now 1 instead of 1/8000.
Problem 2.2. Select a song and encode its melody in MATLAB. Musical notes and their
frequencies can be found in this link. http://www.phy.mtu.edu/~suits/notefreqs.html
Save your work as a wav file using the functions wavwrite or audiowrite.
Example works of other students who previously took this course will be provided to you as
your guide.
Extra Credit (+10 pts) : From the generated signal in problem2.2 above, develop a simple
system that will produce an 'echo' effect when the melody is played.