0% found this document useful (0 votes)
53 views8 pages

Lab 3-Synthesis of Sinusoidal Signals and Sampling Theorem

The document discusses synthesizing sinusoidal signals and the sampling theorem using MATLAB. It describes creating sinusoidal signals of different frequencies and amplitudes, adding them together, and playing the resulting signal. It also covers sampling theory, the Nyquist rate, aliasing, and loading and saving wave files. The lab experiment involves generating sinusoidal signals, concatenating and modifying them, and exploring the effects of changing the sampling rate.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views8 pages

Lab 3-Synthesis of Sinusoidal Signals and Sampling Theorem

The document discusses synthesizing sinusoidal signals and the sampling theorem using MATLAB. It describes creating sinusoidal signals of different frequencies and amplitudes, adding them together, and playing the resulting signal. It also covers sampling theory, the Nyquist rate, aliasing, and loading and saving wave files. The lab experiment involves generating sinusoidal signals, concatenating and modifying them, and exploring the effects of changing the sampling rate.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

School of Applied Medical Science

Department of Biomedical Engineering


Medical Signal Processing Lab (BM323)

Experiment 3: Synthesis of Sinusoidal Signals and Sampling


Theorem
Objectives:
1. Learn more about the spectral representation of signals using MATLAB.
2. Establish a connection between sounds, their frequencies and sinusoids using
MATLAB.
3. Try to add other features to the synthesis signal in order to improve the subjective
quality for listening.
4. Understand the sampling theorem, oversampling and aliasing phenomena using
MATLAB.

Introduction:

Synthesis of Sinusoidal Sounds


The basic building blocks that used in making complicated signals are sinusoids.
Complicated waveform can be constructed out of sums of sinusoidal signals of different
amplitudes, phases and frequencies. The most powerful method for producing new
signals from sinusoids is additive linear combination, where a signal is created by adding
constant and N sinusoids together, each with different frequency, amplitude and phase.
The music synthesis, vowel synthesis and many other signals can be done with sinusoidal
waveforms by using the following form:
)

In this lab, the periodic waveforms and music signals will be created with the intention of
playing them out through a loudspeaker, and then we will try to add other features to

1
synthesis in order to improve the subjective quality for listening. Therefore, it is
necessary to take into account the fact that a conversion is needed from the digital
samples, which are numbers stored in the computer memory to the actual voltage
waveform that will be amplified for the speakers.

Theory of Sampling
Sampling is the process of converting an analog signal into a sequence of discrete values.
If done correctly, sampling does not introduce distortions into the system. The sampling
theorem states that when the sampling rate is greater than twice the highest frequency
contained in the spectrum of analog signal, the original signal can be reconstructed
exactly from samples.
The idealized process of sampling a signal and the subsequent reconstruction of the
signal from its samples is depicted in Figure 3. 1.

Figure 3.1: Sampling and reconstruction of a continuous-time signal.

This figure shows a transformation or operation that acts on a continuous- time input
signal x (t), which is sampled by the continuous-to-discrete (C-to-D) converter to produce
a sequence of samples x[n] = x (nTs), where n is the integer sample index and Ts is the
sampling period. The sampling rate is fs = 1/Ts where the units are samples per second.
The actual hardware systems that do sampling is an analog to digital (A-to-D) converter,
which approximate the perfect sampling of the C-to-D converter.

The ideal discrete-to-continuous (D-to-C) converter takes the input samples and
interpolates a smooth curve between them. The Sampling Theorem tells us that if the
input signal x(t) is a sum of sine waves, then the output y(t) will be equal to the input x(t)
if the sampling rate is more than twice the highest frequency fmax in the input, i.e. fs >

2
2fmax. In other words, if sampling is fast enough then there will be no problems
synthesizing the continuous signals from x[n].
Most computers have a built-in analog-to-digital (A-to-D) converter and a digital-to-
analog (D-to-A) converter (usually on the sound card). These hardware systems are
physical realizations of the idealized concepts of C-to-D and D-to-C converters
respectively, but for purposes of this lab, we will assume that the hardware A/D and D/A
are perfect realizations.

Aliasing
Analog signals contain frequency components that make up the characteristics of the
signal’s waveform. If these analog signals are sampled at low rate lower than the Nyquist
rate, the finer detail of the signal may be missed. Slow sampling tends to miss the high
frequency components while measuring only the signal’s lower frequency components or
inadvertently introducing nonexistent components. This is called aliasing error. Figure
3.2 is an example of aliasing phenomena, where the reconstructed signal built from data
sampled at a rate lower than the Nyquist rate of the original signal.

Figure 3.2: Aliasing phenomena due to undersampling in the time domain

Wave Files and Sound in MATLAB

Many sound processing functions may be used for a windows PC. Some functions are
used in the playing of MATLAB vectors (matrices) through the PC sound board, while the
others are used to read and write wave files to and from the MATLAB workspace. Table
3.1 lists some of these functions.

3
Table 3.1: MATLAB Sound Functions

MATLAB Sound Related Function

Sound (y,Fs) Convert a vector into sound and play at sampling rate
Fs. Amplitude values must lie between -1 and +1.

soundsc(y,Fs) Convert a vector into sound and play at sampling rate


Fs with automatic amplitude scaling.

[y, Fs, nbits] Load windows wav format sound file into workspace
=wavread(fname) variable y. Also returns sampling rate and bits/sample.

From MATLAB, the sound output is done by the soundsc (xx,fs) function which support
a variable D-to-A sampling rate if the hardware on the machine has such capability. A
convenient choice for the D-to-A conversion rate is 11025 samples per second, so Ts =
1/11025 seconds; another common choice is 8000 samples/sec. Both of these rates satisfy
the requirement of sampling fast enough. Usually sampling rate should typically be
sampled at one of the standard Windows audio device rates: 8000, 11025, 22050, or
44100 Hz.
Analog audio is recorded by sampling it 44,100 times per second because the high
frequency limit of human hearing is about 20 kHz (the range of hearing of the human ears
is roughly 20 Hz to 20,000 Hz), and the sampling theorem state that the sampling
rate must be twice of the maximum frequency so the sampling rate had to be at least
40 kHz.
If you are using soundsc(xx,fs ), the vector xx will be scaled automatically for the D-to-A
converter, but if you are using sound(xx,fs ) , you must scale the vector xx so that it lies
between ±1.

4
Procedure

Task one

1. Using MATLAB, Create a vector x1 of samples of a sinusoidal signal (use cosine


wave) with A1 = 100, ω1 = 2π(800), and Φ1= − π/3. Use a sampling rate of 11025
samples/second, and compute a total number of samples equivalent to time
duration of 0.5 seconds. You may find it helpful to recall that MATLAB
statement such as tt=(0:0.01:3); would create a vector of numbers from 0 through
3 with increments of0.01. Therefore, it is only necessary to determine the time
increment needed to obtain 11025 samples in one second.

2. Use soundsc (x1,fs) to play the resulting vector through the D-to-A converter of
your computer, assuming that the hardware can support the fs = 11025 Hz rate.
Listen to the output.

3. Now create another vector x2 of samples of a second sinusoidal signal (0.5 secs. in
duration) for this case A2 = 80, ω1 = 2π (1200), and Φ1= − π /4. Listen to the
signal reconstructed from these samples. How does its sound, compare it with the
signal in step 2?
4. Add x1 to x2 to create x3, Listen to the signal reconstructed from these samples.
How does its sound compare it with the signal in step 3?

5. Concatenate the two signals x1 and x2 with a short duration of 0.2 seconds of
silence in between. You should be able to use a statement something like:
xx = [ x1, zeros(1,N), x2 ] ;
Assuming that both x1 and x2 are row vectors. Determine the correct value of N
to make about 0.2 seconds of silence.
6. Verify that the concatenation operation was done correctly in the previous part by
making the following plot:
tt = (1/11025)*(1:length(xx)); plot( tt, xx );

5
This will plot a huge number of points, but it will show the “envelope” of the
signal and verify that the amplitude changes from 100 to zero and then to 80 at the
correct times. Notice that the time vector tt was created to have exactly the same
length as the signal vector xx.

7. Listen to this new signal to verify that it is correct.

8. Now send the vector xx to the D-to-A converter again, but change the sampling
rate parameter in soundsc (xx, fs) to 22050 samples/second. Do not re-compute
the samples in xx, just tell the D-to-A converter that the sampling rate is 22050
samples/second. Describe how the duration and pitch of the signal were affected.
Explain.

Task Two:

1. Generate 12 Hz sinusoidal signal with 10 s duration, sampled at 1000 Hz and plot


it as a function of time , Make sure to title the graph , label x and y axis .

2. Sample the generated sinusoidal with sampling frequency 100 Hz.

3. Plot the sampled signal, the reconstructed signal and the signal plotted in step 1 in
the same graph (x axis should be from 0 to 2), use stem command for sampled
signal. Make sure to label x and y axis and title of the figure.

4. Repeat step 2 and 3 with 21 Hz sampling frequency , Compare the graphs with
what you get in step 3 ,what do you note ?

5. Repeat step 2 and 3 with 11 Hz sampling frequency, calculate the frequency of


the reconstructed signal and compare the value with the original one, what do you
note.

6
Lab Exercise

1. Generate three sinusoidal signals with frequencies of 3 Hz , 7Hz and 13 Hz ,


Sample these three signal with sampling rate of 10 sample /second , plot the sampled
signal , the reconstructed signal and the original signal ( use sub plot to verify the
difference between sampled signals easily ) .Make sure to title the graph , label x and
y axis . Determine at which frequencies did the aliasing happen?

2. Complex amplitudes for the periodic signal that approximate the waveform
produced by a man speaking the vowel sound “ah “ with 100 Hz fundamental
frequency are represented in Table 3.2 . Create a MATLAB code that generate x2
and add x2 to the 400 Hz cosine signal to represent x4 , then add x4 to the 500 Hz
cosine signal to represent x5 and so on .Your code must do the following :

a) Plot x2 , x4 ,x5.x16 and x17 as a function of time ( use subplot command )

b) Listen to the sound that is generated from x2 , x4 ,x5, x16 and x17 and compare
the generated sound , What do you note ?

c) Listen to these signals with a short duration of 0.2 seconds of silence in between
each one as the following form:

xx = [ x2, delay , x4 , delay , x5, delay , x16 , delay, x17]

d) Verify that the concatenation operation was done correctly in the previous part,
make the following plot:
tt = (1/fs)*(1:length(xx)); plot( tt, xx )

Table 3.2
K fk (Hz) Ak Mag Phase
1 100 0 0 0
2 200 386+j 6101 6113 1.508
3 300 0 0 0

7
4 400 -4433+j 14024 14708 1.877
5 500 24000-j4498 24418 -0.185
6 600 0 0 0
. . . . .
. . . . .
15 1500 0 0 0
16 1600 828- j6760 6811 -1.449
17 1700 2362+j0 2362 0

Sources

• Signal Processing First , James H.McClellau , Ranald W.Schafe, Mark A.Yoder ,


2003 Pearson Education, Inc.

You might also like