Anda di halaman 1dari 5

# EE213: Introduction to Signal Processing

## Lab 4: Signal Superposition and Capturing

1 Objectives
Generate a complex signal using signal superposition.
Record an audio signal using PC-based audio input device.
Represent the recorded signal in time domain.
Investigate the effects of sampling rate on signal recovery.

NOTE
1. Adjust the speaker volume to low level at the beginning of the lab.
2. Increase the speak volume gradually until you can hear the sound clearly.
3. You can bring your own headset (preferred with a microphone) if you want.

2 Procedures
2.1 Signal Superposition
An important result of Fourier analysis is the conclusion that complex signals can be synthesized from rather simple signals, i.e., sinusoids. We will explore this idea in the first
part of the lab with the application of music synthesis.
2.1.1 Pure tones
A pure tone (or musical note) of frequency f Hz is a sinusoidal signal given by
x(t) = A sin(2f t + )
where A is the amplitude of the tone, f is the frequency in Hz, and is the phase. We
can simply assume = 0 in this lab since the phase has no effect on the type of sounds
considered in this lab. In general, a note has two characteristics
Volume represented by the amplitude A.

## Pitch represented by frequency, f , in hertz. Each frequency generates a distinct

note. For example the frequencies of the notes in the scale from middle C are given
in the following table.
Note
Frequency (Hz)

C4
261.63

D4
293.66

E4
329.63

F4
349.23

G4
391.99

A4
440

B4
493.88

C5
523.25

## Table 1: Approximate Frequencies of the notes between C4 and C5 in Hz.

In Lab 2 we know how to deal with a continuous signal x(t) in MATLAB. Explicitly, we
need to obtain a discrete version of x(t) by sampling it with a proper sampling period. The
following is a brief introduction to the sampling processing which is sufficient for completing
this lab.
Let x(t), t [0, T ], be a continuous-time signal defined over the time interval [0, T ].
Suppose we want to obtain Fs samples in a second. In signal processing Fs is termed
sampling frequency or sampling rate and the unit is samples per second (samples/sec
or Hz). With the sampling rate of Fs , the time between two consecutive samples (called the
sampling period) is Ts , the sampling process generates a sequence of discrete samples:
x[n] = x(nTs ), i.e., x[0] = s(0), x[1] = x(Ts ), x[2] = x(2Ts ), and so on.
Suppose we want to describe the signal s(t) = sin(220t) with the sampling frequency
of Fs = 1000 (samples/sec). This can be implemented in MATLAB by the following code
Fs = 1000; % sampling f r e q u e n c y .
Ts = 1 / Fs ; % sampling p e r i o d , i . e . , t h e t i m e between samples
d = 1 ; % t h e d u r a t i o n ( i n seconds ) o f t h e s i g n a l t h a t we want t o
consider
t = 0 : Ts : d ; % v e c t o r o f sampling p o i n t s .
s = sin (2* p i *20* t ) ; % the values of the s i g n a l
p l o t ( t ( 1 : 1 0 0 ) , s ( 1 : 1 0 0 ) ) % p l o t t h e f i r s t 100 s i g n a l samples .
Now set the sample frequency to be Fs = 11025 Hz and complete the following tasks
Task 1 Write an M-file to generate a A4 note for 0.5 seconds. Play the sound signal
using the soundsc command.
HINT: To play the signal contained in vector x as sound with sample frequency
Fs, we use the command soundsc(x,Fs) in MATLAB.
Task 2 Write an M-file to sequentially generate and play all the notes from C4 to C5
in Table in 1. The length of each note is 0.5 seconds and the length of pause
between notes is 0.1 seconds.
HINT: To create a pause between notes we just simply insert a vector of all
zeros. The command zeros(1,n) create a row vector of n zeros.
2.1.2 Harmonics
When a particular note is played on a musical instrument such as piano, flute, or violin,
not only is the fundamental frequency (tone) generated but also higher harmonics of the
pure tones at the frequencies 2f , 3f , 4f ,... These harmonics give the instrument a richer
sound. The kth harmonic is given by
xk (t) = Ak sin(2kf t)

## Fall semester, 2015

where Ak is the amplitude of the kth harmonic. Each musical instrument differs in the
amplitudes of the higher harmonics ans thus gives a different sound.
Now set the sample frequency to be Fs = 44100 Hz and complete the following tasks.
Task 3 Write an M-function to compute a signal which is the sum of a pure tone
and its harmonics. Your function may have the following structure
y
%
%
%

= sumharmonics ( f , A , d , Fs )
y : output signal
f : fundemental frequency , e . g . , f =440 f o r A4 note
A: vector t h a t s contains the amplitude of the
harmonics . The l e n g t h o f A i s t h e number o f
c o ns i d e r e d harmonics
% d : duration of the s i g n a l
% Fs : sampling f r e q u e n cy
Hint: You may use the code in the last task of Lab 2 to compute the sum of
harmonics.
Task 4 Use your function in Task 3 to generate and play a sound for 0.5 seconds
when a flute plays an A4 note. Plot the sound signal for two cycles. See
Table 2 for the amplitudes of the harmonics of a flute playing A4.1
Harmonic
Amplitude

1
1

2
3
0.6 0.15

4
5
0.2 0.05

## Table 2: Amplitudes of the harmonics of a flute playing A4.

Task 5 Use your function in Task 3 to generate and play a sound for 0.5 seconds
when a violin plays an A4 note. Plot the sound signal for two cycles and
compare with the one obtained in Task 4. See Table 2 for the amplitudes of
the harmonics of a flute playing A4.
Harmonic
Amplitude

1
1

2
3
0.5 0.4

4
5
0.5 0.7

6
7
8
0.6 0.8 0.6

9
10
0.5 0.4

11
12
0.3 0.08

13 14
0.3 0.3

## 2.2 Signal Capturing

In the second part of this lab we will capture an audio signal, deliver it to a PC, and plot
the captured signal in time domain. First, make sure the Sound Recorder functionality on
the PC works well by completing the following steps.
Connect your microphone to the audio input on the front panel of the PC.
Test the sound recording program in Windows.
1

## Fall semester, 2015

If you are unable to record your voice using Sound Recorder, or unable to listen to
the recorded signal using e.g., Window Media Player, then you may need to adjust
microphone input volume since it is probably too low to record your voice.
Control Panel -> Hardware and Sound -> Sound -> Recording.
Task 6 Now collect a sample of your speech with a microphone, and plot the signal
data. Run the following code
% s e t t h e sampling r a t e t o be 11025 Hz .
Fs = 11025;
% r e c o r d i n g t i m e i n seconds .
d = 3;
%c r e a t e s an 8 b i t , 1channel a u d i o r e c o r d e r o b j e c t
recObj = a u d i o r e c o r d e r ( Fs , 8 , 1 ) ;
d i s p ( S t a r t speaking . )
r e c o r d b l o c k i n g ( recObj , d ) ;
d i s p ( End o f Recording . ) ;
% Play back t h e r e c o r d i n g .
p l a y ( recObj ) ; % Y o u l l hear your speech again
% S t o r e data i n doublep r e c i s i o n a r r a y .
myRecording = g e t a u d i o d a t a ( recObj ) ;
% P l o t t h e waveform .
p l o t ( myRecording ) ;
You are expected to obtain a figure similar to Fig. 1 below
0.15

0.1

Amplitue

0.05

0.05

0.1

0.15

0.2

0.5

1.5
Time (seconds)

2.5

## Figure 1: Time domain representation of an audio signal.

Task 7 Repeat Task 6 for smaller sampling rates such as Fs = 4000, Fs = 8000, and
Fs = 1000. Comments on (in the report file) the quality of the recorded signals when the sampling rate is reduced and notice the sampling rate when
you can hardly recognise your speech signal.

## Fall semester, 2015

Task 8 Sketch a proper diagram (labelling all the blocks) to describe the signal processing (from analogue speech signal to digital data stored on PC) in Tasks
6 and 7.

3 Reports
Your report should have the following structure
All the plots you obtained during the lab and the your comments and opinions on the
results.
A summary of what you gained in the lab.

3.1 Submission
Each student submits a single report. You also need to submit all the MATLAB
codes for the lab.
To be uploaded via moodle before 6PM the following day.
A penalty 10% of each day will be applied to late submission.
Poorly written report is subject to deduction.