0% found this document useful (0 votes)
130 views

03-Signal and Data

This document discusses periodic signals and their representation and generation. It introduces concepts like the Fourier transform and sampling criteria. It provides examples of generating sinusoidal, square, and sawtooth periodic signals in MATLAB. The key topics covered are the representation of periodic signals as samples, decomposing periodic signals into sine and cosine components using Fourier analysis, and generating different periodic test signals programmatically.
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)
130 views

03-Signal and Data

This document discusses periodic signals and their representation and generation. It introduces concepts like the Fourier transform and sampling criteria. It provides examples of generating sinusoidal, square, and sawtooth periodic signals in MATLAB. The key topics covered are the representation of periodic signals as samples, decomposing periodic signals into sine and cosine components using Fourier analysis, and generating different periodic test signals programmatically.
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/ 27

Part I

Signals and Data


Chapter 1
Periodic Signals

1.1 Introduction

This chapter is devoted to initial fundamental concepts of signal processing. Periodic


signals provide a convenient context for this purpose.
The chapter is also an introduction to the Signal Processing Toolbox. A number
of figures and MATLAB programs have been included to illustrate the concepts and
functions being introduced. This methodology is continued in the next chapters of
the book.
Some examples include sound output, which contributes for a more intuitive study
of periodic signals.
Of course, a main reference for this chapter and the rest of the book is the Docu-
mentation that accompanies the MATLAB Signal Processing Toolbox. Other more
specific references are indicated when opportune in the different sections of the
chapter.
The most important contents to be considered in the next pages refers to the Fourier
transform and to sampling criteria. Both are introduced by way of examples. The
Appendix A of the book contains a more formal exposition of these topics, including
bibliography.
The two final sections of this chapter include Internet addresses of interesting
resources, and a list of literature references. The book [3] provides a convenient
background for this chapter.

1.2 Signal Representation

Suppose you have a signal generator so you have the capability of generating a square
wave with 1 Hz frequency. You adjust the generator, so the low level of the signal is
0 v. and the high level is 1 v. Figure 1.1 shows 3 s of such signal:
The signal in Fig. 1.1 repeats three consecutive times the same pattern. It is a
periodic signal with period T = 1 s.
© Springer Science+Business Media Singapore 2017 3
J.M. Giron-Sierra, Digital Signal Processing with Matlab Examples, Volume 1,
Signals and Communication Technology, DOI 10.1007/978-981-10-2534-1_1
4 1 Periodic Signals

Fig. 1.1 A square signal 1.5

0.5

-0.5
0 0.5 1 1.5 2 2.5 3
seconds

Suppose you also have a computer with a data acquisition channel, so it is possible
to get samples of the 1 Hz square signal. For instance, let us take 10 samples per
second. In this case, you get from 3 s of signal, a data set like the following:

A = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0];

From this data set, with 30 numbers, it is possible to reproduce the signal, provided
information about time between samples is given. In order to have such information,
another parallel set of 30 sampling times could be recorded when you get the data;
or just keep in memory or paper what the sampling frequency was (or the total time
of signal that was sampled).
Figure 1.2 plots the data set A versus 30 equally spaced time intervals along the
3 s.
The MATLAB code to generate Fig. 1.2 is the following:
Program 1.1 Square signal
% Square signal
A=[1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,...
1,1,1,1,1,0,0,0,0,0];
fs=10; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(3-tiv); %time intervals set (30 values)
plot(t,A,'*'); %plots figure
axis([0 3 -0.5 1.5]);
xlabel('sec.'); title('square wave samples');

MATLAB handles signals using data sets (vectors). Usually the Signal Processing
Toolbox routines ask for the signal samples data set, and for information about the
sampling frequency.
1.3 Generation of Periodic Signals 5

Fig. 1.2 The sampled 1.5


square signal

0.5

-0.5
0 0.5 1 1.5 2 2.5 3
seconds

1.3 Generation of Periodic Signals

Let us use the periodic signals included in the Signal Processing Toolbox.

1.3.1 Sinusoidal

The following MATLAB program generates a sinusoidal signal with 1 s period. It is


based on the use of the sin() function.
Program 1.2 Sine signal
% Sine signal
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
fs=60; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(3-tiv); %time intervals set, 180 values
y=sin(wy*t); %signal data set
plot(t,y,'k'); %plots figure
axis([0 3 -1.5 1.5]);
xlabel('seconds'); title('sine signal');

Figure 1.3 shows the results of the Program 1.2, it is a 180 points data set covering
3 s of the 1 Hz signal.
In the next program, both sine and cosine signals, with the same 1 Hz frequency,
are generated.
6 1 Periodic Signals

Fig. 1.3 Sinusoidal signal 1.5

0.5

-0.5

-1

-1.5
0 0.5 1 1.5 2 2.5 3
seconds

Fig. 1.4 Sine (solid) and 1.5


cosine (dashed) signals
1

0.5

-0.5

-1

-1.5
0 0.5 1 1.5 2 2.5 3
seconds

Program 1.3 Sine and cosine signals


% Sine and cosine signals
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
fs=60; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(3-tiv); %time intervals set
ys=sin(wy*t); %signal data set
plot(t,ys,'k'); hold on; %plots figure
axis([0 3 -1.5 1.5]);
xlabel('seconds');
yc=cos(wy*t); %signal data set
plot(t,yc,'--k'); %plots figure
1.3 Generation of Periodic Signals 7

axis([0 3 -1.5 1.5]);


xlabel('seconds'); title('sine (solid) and cosine (dashed)');

Figure 1.4 shows the results of Program 1.3, two superimposed (using hold on)
signals. Notice the 90◦ phase difference between both signals.
As shall be seen shortly, periodic signals can be decomposed into a sum of sine
and cosine signals.

1.3.2 Square

The following MATLAB program generates 0.03 s of a square signal with 0.01 s
period (100 Hz frequency). The signal generation is based on the use of the square()
function. A feature of this function is that it is possible to specify the duty cycle (the
percent of the period in which the signal is positive), in order to generate rectangular
signals.
Program 1.4 Square signal
% Square signal
fy=100; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
duy=0.03; %signal duration in seconds
fs=20000; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(duy-tiv); %time intervals set
y=square(wy*t); %signal data set
plot(t,y,'k'); %plots figure
axis([0 duy -1.5 1.5]);
xlabel('seconds'); title('square signal');

Figure 1.5 shows the results of Program 1.4.

Fig. 1.5 Square signal 1.5

0.5

-0.5

-1

-1.5
0 0.005 0.01 0.015 0.02 0.025 0.03
seconds
8 1 Periodic Signals

1.3.3 Sawtooth

The following MATLAB program generates 0.03 s of a sawtooth signal with 0.01 s
period (100 Hz frequency). The signal generation is based on the use of the sawtooth()
function.
Program 1.5 Sawtooth signal
% Sawtooth signal
fy=100; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
duy=0.03; %signal duration in seconds
fs=20000; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(duy-tiv); %time intervals set
y=sawtooth(wy*t); %signal data set
plot(t,y,'k'); %plots figure
axis([0 duy -1.5 1.5]);
xlabel('seconds'); title('sawtooth signal');

Figure 1.6 shows the results of Program 1.5.


The shape of the sawtooth signal can be modified using a feature (a width specifi-
cation) of this function. Figure 1.7 shows four examples. Look into the sentences with
the sawtooth() function in the Program 1.6, to see the width specifications applied in
the examples.

Fig. 1.6 Sawtooth signal 1.5

0.5

-0.5

-1

-1.5
0 0.005 0.01 0.015 0.02 0.025 0.03
seconds
1.3 Generation of Periodic Signals 9

1.5 1.5
1 1
0.5 0.5
0 0
-0.5 -0.5
-1 -1
-1.5 -1.5
0 0.01 0.02 0.03 0 0.01 0.02 0.03
seconds seconds

1.5 1.5
1 1
0.5 0.5
0 0
-0.5 -0.5
-1 -1
-1.5 -1.5
0 0.01 0.02 0.03 0 0.01 0.02 0.03
seconds seconds

Fig. 1.7 Different sawtooth signals

Program 1.6 Sawtooth signals


% Sawtooth signals
fy=100; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
duy=0.03; %signal duration in seconds
fs=20000; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(duy-tiv); %time intervals set
y=sawtooth(wy*t,0.1); %signal data set (width 0.1)
subplot(2,2,1); plot(t,y,'k'); %plots figure
axis([0 duy -1.5 1.5]);
xlabel('seconds'); title('sawtooth signal');
y=sawtooth(wy*t,0.3); %signal data set (width 0.3)
subplot(2,2,2); plot(t,y,'k'); %plots figure
axis([0 duy -1.5 1.5]);
xlabel('seconds'); title('sawtooth signal');
y=sawtooth(wy*t,0.5); %signal data set (width 0.5)
subplot(2,2,3); plot(t,y,'k'); %plots figure
axis([0 duy -1.5 1.5]);
xlabel('seconds'); title('sawtooth signal');
y=sawtooth(wy*t,0.9); %signal data set (width 0.9)
subplot(2,2,4); plot(t,y,'k'); %plots figure
axis([0 duy -1.5 1.5]);
xlabel('seconds'); title('sawtooth signal');
10 1 Periodic Signals

1.4 Hearing the Signals

Many computers have loudspeakers, or a connector for headsets. Using MATLAB it


is possible to hear the signals under study, provided the frequencies of these signals
are in the audio range. Frequencies in the 100–1000 Hz range give comfortable sound.
The Program 1.7 generates a 300 Hz sinusoidal signal along 5 s. There is a sen-
tence with the function sound() that sends this signal, with sufficient power, to the
loudspeaker.
Program 1.7 Sine audio signal
% Sine signal sound
fy=300; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
fs=6000; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(5-tiv); %time intervals set (5 seconds)
y=sin(wy*t); %signal data set
sound(y,fs); %sound
t=0:tiv:(0.01-tiv); %time intervals set (0.01 second)
y=sin(wy*t); %signal data set
plot(t,y,'k'); %plots figure
axis([0 0.01 -1.5 1.5]);
xlabel('seconds'); title('sine signal');

Figure 1.8 shows the sinusoidal audio signal.

1.5

0.5

-0.5

-1

-1.5
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
seconds

Fig. 1.8 The sinusoidal audio signal


1.5 Operations with Signals 11

1.5 Operations with Signals

We can add, subtract, multiply, etc. signals. It is interesting to deal, in this section,
with some basic examples.

1.5.1 Adding Signals

In Program 1.8 we add three sinusoidal signals. This is done in the sentence with the
following expression:

y = 0.64 sin(ω y t) + 0.21 sin(3ω y t) + 0.12 sin(5ω y t) (1.1)

Notice that the amplitude and frequency of the three sinusoids are the following:

signal amplitude frequency


1st harmonic 0.64 ω (300 Hz)
3r d harmonic 0.21 3 ω (900 Hz)
5th harmonic 0.12 5 ω (1500 Hz)

The Program 1.8 is as follows:


Program 1.8 Sum of sines signal
% Sum of sines signal
fy=300; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
fs=6000; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(5-tiv); %time intervals set (5 seconds)
%signal data set:
y=0.64*sin(wy*t)+0.21*sin(3*wy*t)+0.12*sin(5*wy*t);
sound(y,fs); %sound
t=0:tiv:(0.01-tiv); %time intervals set (0.01 second)
%signal data set:
y=0.6*sin(wy*t)+0.3*sin(3*wy*t)+0.2*sin(5*wy*t);
plot(t,y,'k'); %plots figure
axis([0 0.01 -1.5 1.5]);
xlabel('seconds'); title('sum of sines signal');

Figure 1.9 shows the result of adding the three sinusoidal signal. It is a periodic
signal with frequency 300 Hz. It looks similar to a square signal.
Fourier series are sums of sinusoidal harmonics. In the case of Program 1.8 we
are taking the first three non-zero harmonics of the series corresponding to a square
12 1 Periodic Signals

1.5

0.5

-0.5

-1

-1.5
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
seconds

Fig. 1.9 Sum of three sinusoidal signals

signal. By adding more non-zero harmonics we can improve the approximation to


the square signal.
The Program 1.8 includes the sound() function so it is possible to hear the 300 Hz
square-like signal and compare it with the smoother sound of the pure 300 Hz sinu-
soidal signal (Program 1.7).
The reader is invited to obtain other waveforms by changing the expression of the
signal y in Program 1.8. This is one of the typical activities when using a music syn-
thesizer [6]. A few web sites on sound synthesis have been included in the Resources
section at the end of the chapter.

1.5.2 Multiplication

Figure 1.10 shows the result of multiplying two sinusoidal signals. One of the signals
has 70 Hz frequency and the other has 2 Hz frequency. Both signals have amplitude 1.
The result obtained is a modulated signal. Chapter 8 of this book is devoted to
modulation, and a similar example will be seen in more detail.
Program 1.9 has been used to generate the Fig. 1.10. It includes a sentence with
a sound() function. When hearing the modulated signal, notice the tremolo effect
caused by the 2 Hz signal. The Internet address of a tutorial on sound amplitude
modulation has been included in the Resources section.
1.5 Operations with Signals 13

Fig. 1.10 Multiplication of 1.5


two sinusoidal signals
1

0.5

-0.5

-1

-1.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
seconds

Program 1.9 Multiplication of sines


% Multiplication of sines signal
fx=70; %signal frequency in Hz
wx=2*pi*fx; %signal frequency in rad/s
fz=2; %signal frequency in Hz
wz=2*pi*fz; %signal frequency in rad/s
fs=6000; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(8-tiv); %time intervals set (8 seconds)
y=sin(wx*t).*sin(wz*t); %signal data set
sound(y,fs); %sound
t=0:tiv:(1-tiv); %time intervals set (1 second)
y=sin(wx*t).*sin(wz*t); %signal data set
plot(t,y,'k'); %plots figure
axis([0 1 -1.5 1.5]);
xlabel('seconds'); title('multiplication of sines signal');

1.6 Harmonics. Fourier

Periodic signals can be decomposed into sums of sine and cosine signals, according
with the following expression, which is a Fourier series:

 ∞

y(t) = a0 + an cos (n · w0 t) + bn sin(n · w0 t) (1.2)
n=1 n=1

where ω0 is the frequency (rad/s) of the periodic signal.


14 1 Periodic Signals

Fig. 1.11 Example of odd 1


signal (sawtooth signal, 3
periods) 0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 0.5 1 1.5 2 2.5 3
seconds

Several types of periodic signals can be distinguished, considering symmetries.


Let us explore some of these types.

1.6.1 Odd Signals

Odd signals have the following symmetry:

y(−t) = − y(t) (1.3)

The sine signal is an odd signal. All other odd signals can be obtained with:


y(t) = bn sin (n · w0 t) (1.4)
n=1

Let us consider the example shown in Fig. 1.11. It is a sawtooth signal (which is an
odd signal).
Figure 1.11 has been obtained with the Program 1.10 (very similar to
Program 1.5)
Program 1.10 Sawtooth signal to be analyzed
%sawtooth signal to be analyzed
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
1.6 Harmonics. Fourier 15

tiv=1/fs; %time interval between samples;


t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)
y3=sawtooth(wy*t); %signal data set
plot(t,y3'k');
xlabel('seconds'); title('sawtooth signal (3 periods)');

By using the function fft() (fast Fourier transform) we can obtain the values of
coefficients bi in Eq. (1.4). Let us apply this function for the y(t) sawtooth signal.
Program 1.11 obtains the first ten coefficients. Notice that it is enough to pass to fft()
one signal period.
Program 1.11 Fourier transform of sawtooth signal
%Fourier Transform of sawtooth signal
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(Ty-tiv); %time intervals set
y=sawtooth(wy*t); %signal data set
fou=fft(y,fs); %Fourier Transform (set of complex numbers)
hmag=imag(fou); bh=hmag/N; %get set of harmonic amplitudes
stem(0:9,bh(1:10)); %plot of first 10 harmonics
axis([0 10 0 1]);
xlabel('Hz'); title('sawtooth signal harmonics');

Figure 1.12 shows the values of the coefficients bi versus frequencies 0, ω0 , 2ω0 ,
3ω0 , etc. in Hz.

Fig. 1.12 Amplitude of the 1


first ten harmonics of the
0.9
sawtooth signal
0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 1 2 3 4 5 6 7 8 9 10
Hz
16 1 Periodic Signals

Fig. 1.13 Example of even 1


signal (rectified sine signal, 3
periods) 0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.5 1 1.5 2 2.5 3
seconds

1.6.2 Even Signals

Even signals have the following symmetry:

y(−t) = y(t) (1.5)

The cosine signal is an even signal. All other even signals can be obtained with:


y(t) = a0 + an cos (n · w0 t) (1.6)
n=1

where a0 is the average value of the signal.


Consider the signal shown in Fig. 1.13. It is a rectified sine signal (which is an
even signal). This signal is found, for instance, in AC to DC electronics conversion
for power supply.
The signal in Fig. 1.13 has been obtained with the Program 1.12.
Program 1.12 Rectified signal to be analyzed
%rectified sine signal to be analyzed
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)
y3=abs(sin(wy*t)); %signal data set
plot(t,y3'k');
xlabel('seconds'); title('rectified sine signal (3 periods)');
1.6 Harmonics. Fourier 17

Now, let us apply fft() to obtain the an coefficients in Eq. (1.6). This is done with
the Program 1.13.
Program 1.13 Fourier transform of rectified signal
%Fourier Transfom of rectified sine signal
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(Ty-tiv); %time intervals set
y=abs(sin(wy*t)); %signal data set
fou=fft(y,fs); %Fourier Transform (set of complex numbers)
hmag=real(fou); ah=hmag/N; %get set of harmonic amplitudes
stem(0:9,ah(1:10)); hold on; %plot of first 10 harmonics
plot([0 10],[0 0],'k');
xlabel('Hz'); title('rectified sine signal harmonics');

Figure 1.14 shows the values of the coefficients ai versus frequencies 0, ω0 , 2ω0 ,
3ω0 , etc. in Hz.
Since the rectified sine has a non-zero average value, Fig. 1.14 shows a non-zero
value of a0 .

Fig. 1.14 Amplitude of the 0.8


first ten harmonics of the
rectified sine signal 0.6

0.4

0.2

-0.2

-0.4

-0.6
0 1 2 3 4 5 6 7 8 9 10
Hz
18 1 Periodic Signals

1.6.3 Half Wave Symmetry

A signal has half-wave symmetry if:


 
T0
y t+ = − y(t) (1.7)
2

For this kind of signals, the harmonics for frequencies 0, 2ω0 , 4ω0 , 8ω0 , etc. have
zero amplitude.
Consider the signal shown in Fig. 1.15. It is a triangular signal, which has half-
wave symmetry. It is also an even signal (it will have only cosine harmonics).
The signal in Fig. 1.15 has been obtained with the Program 1.14.
Program 1.14 Triangular signal to be analyzed
%triangular signal to be analyzed
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)
y3=-sawtooth(wy*t,0.5); %signal data set
plot(t,y3'k');
xlabel('seconds'); title('triangular signal (3 periods)');

Let us apply fft() to obtain the an coefficients corresponding to the triangular


signal. This is done with the Program 1.15.

Fig. 1.15 Example of signal 1


with half-wave symmetry
0.8
(triangular signal, 3 periods)
0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 0.5 1 1.5 2 2.5 3
seconds
1.6 Harmonics. Fourier 19

Fig. 1.16 Amplitude of the 0.9


first ten harmonics of the
0.8
triangular signal
0.7

0.6

0.5

0.4

0.3

0.2

0.1

-0.1
0 1 2 3 4 5 6 7 8 9 10
Hz

Program 1.15 Fourier transform of triangular signal


%Fourier Transfom of triangular signal
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(Ty-tiv); %time intervals set
y=-sawtooth(wy*t,0.5); %signal data set
fou=fft(y,fs); %Fourier Transform (set of complex numbers)
hmag=real(fou); ah=hmag/N; %get set of harmonic amplitudes
stem(0:9,ah(1:10)); hold on; %plot of first 10 harmonics
plot([0 10],[0 0],'k');
xlabel('Hz'); title('triangular signal harmonics');

Figure 1.16 shows the values of the coefficients ai versus frequencies 0, ω0 , 2ω0 ,
3ω0 , etc. in Hz.
Notice that amplitudes of harmonics with frequencies 0, 2ω0 , 4ω0 , 6ω0 , etc. are
zero.

1.6.4 Pulse Train

Consider the case of a pulse train signal, as shown in Fig. 1.17.


The signal in Fig. 1.17 has been obtained with the Program 1.16.
20 1 Periodic Signals

Fig. 1.17 A pulse train


signal (3 periods) 1

0.8

0.6

0.4

0.2

0 0.5 1 1.5 2 2.5 3


seconds

Program 1.16 Pulse train signal


%pulse train signal to be analyzed
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)
W=20;
%signal first part:
y1=zeros(256,1); y1(1:W)=1; y1((256-W):256)=1;
yt=cat(1,y1,y1,y1); %signal to be plotted
plot(t,yt'k');
xlabel('seconds'); title('pulse train signal (3 periods)');

The width of the high level parts of the signal can be modified by changing the
value of W in Program 1.16.
Again, let us apply fft() to obtain the an coefficients corresponding to the pulse
train signal, which is an even signal (Program 1.17).
Program 1.17 Fourier transform of pulse train signal
%Fourier Transform of pulse train signal
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256; W=20;
fs=N*fy; %sampling frequency in Hz
y1=zeros(256,1); y1(1:W)=1; y1((256-W):256)=1; %signal period
fou=fft(y1,fs); %Fourier Transform (set of complex numbers)
hmag=real(fou); ah=hmag/N; %get set of harmonic amplitudes
1.6 Harmonics. Fourier 21

stem(0:49,ah(1:50)); hold on; %plot of first 50 harmonics


plot([0 50],[0 0],'k');
xlabel('Hz'); title('pulse train signal harmonics');

Figure 1.18 shows the values of the coefficients ai versus frequencies 0, ω0 , 2ω0 ,
3ω0 , etc. in Hz.
For a certain value nc, it will happen that all coefficients an with n>nc will have
an absolute value less than a0 /100. Let us take this value nc as a practical limit of
the number of harmonics that deserve to be considered. Also, let us take wnc as the
maximum frequency of interest for the study of the signal.
If you decrease the value of W in Program 1.17, making the pulses to narrow, you
will notice an increase of nc and of wnc . From the point of view of data transmission
it means that the narrower the pulses to be transmitted through a channel (for instance
a wire), the larger the channel bandwidth must be.
Look at the data points in Fig. 1.18. They draw a peculiar curve that we shall meet
again in other parts of the book. It corresponds to the sinc() function:

sin(x)
sinc(x) = (1.8)
x
Figure 1.19 depicts part of the sinc(t) function. It is usual to represent this function
with respect to negative and positive values of time.

Fig. 1.18 Amplitude of the 0.35


first 50 harmonics of the
pulse train signal 0.3

0.25

0.2

0.15

0.1

0.05

-0.05

-0.1
0 5 10 15 20 25 30 35 40 45 50
Hz
22 1 Periodic Signals

Fig. 1.19 The sinc(t) 1.2


function
1

0.8

0.6

0.4

0.2

-0.2

-0.4
-6 -4 -2 0 2 4 6
seconds

Figure 1.19 has been obtained with Program 1.18.


Program 1.18 Sinc function
%sinc function
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
Ty=1/fy; %signal period in seconds
N=256;
fs=N*fy; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
%time intervals set (12 periods):
t=-((6*Ty)-tiv):tiv:((6*Ty)-tiv);
y=sinc(t); %signal data set
plot(t,y'k'); hold on;
plot([0 0],[-0.4 1.2],'k');
xlabel('seconds'); title('sinc function');

1.7 Sampling Frequency

Notice than all signals in Sect. 1.3. have been generated with a sampling frequency
that is higher enough with respect to the signal frequency. Let us see what happens
lowering the sampling frequency. Next program generates a 1 Hz sinusoidal signal
using a 7 Hz sampling frequency.
1.7 Sampling Frequency 23

Program 1.19 Sine signal and low sampling frequency


% Sine signal and low sampling frequency
fy=1; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
fs=7; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(3-tiv); %time intervals set
y=sin(wy*t); %signal data set
plot(t,y,'-kd'); %plots figure
axis([0 3 -1.5 1.5]);
xlabel('seconds'); title('sine signal');

Figure 1.20 shows the results of Program 1.19. Notice how the signal looks dis-
torted with respect to a pure sine.
It is interesting to play with the Program 1.19, changing the sampling frequency
and looking at the results. In particular, there may appear peculiar effects if the
sampling frequency is equal or lower than two times the signal frequency.
For example let us consider the case of the sampling frequency and the signal
frequency being equal. In this case the signal data points draw a horizontal line. It
seems that there is a simple constant (DC) signal. This can happen, and has happened,
in reality: you measure at a certain sampling frequency, you believe from sampled
data that there is a constant signal, but it is not true (what you see on the computer
screen is an impostor, a signal “alias”) [2, 5].
So it is important to determine the frequency of the signal you are sampling.

Fig. 1.20 Effect of a low 1.5


sampling frequency
(sampled sine signal)
1

0.5

-0.5

-1

-1.5
0 0.5 1 1.5 2 2.5 3
seconds
24 1 Periodic Signals

1.5
1
0.5
fs=100 0
-0.5
-1
-1.5
0 0.5 1 1.5 2 2.5 3

1.5
1
0.5
fs=4

0
-0.5
-1
-1.5
0 0.5 1 1.5 2 2.5 3
seconds

Fig. 1.21 Aliasing example (3 Hz sine signal)

Figure 1.21 shows what happens when a 3 Hz sinusoidal signal is sampled at 4 Hz


sampling frequency. This figure is obtained with Program 1.20.
Program 1.20 Sine signal and aliasing
% Sine signal and aliasing
fy=3; %signal frequency in Hz
wy=2*pi*fy; %signal frequency in rad/s
% good sampling frequency
fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(3-tiv); %time intervals set
y=sin(wy*t); %signal data set
subplot(2,1,1); plot(t,y,'k'); %plots figure
axis([0 3 -1.5 1.5]);
title('3Hz sine signal');
ylabel('fs=100');
% too slow sampling frequency
fs=4; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(3-tiv); %time intervals set
y=sin(wy*t); %signal data set
subplot(2,1,2); plot(t,y,'-kd'); %plots figure
axis([0 3 -1.5 1.5]);
xlabel('seconds');
ylabel('fs=4');
1.7 Sampling Frequency 25

Figure 1.21 shows on top the 3 Hz sinusoidal signal. The plot below shows the
data obtained sampling the sinusoidal signal: by joining the data points it seems that
the data obtained correspond to a triangular signal. Again this is a mistake, we see
on screen an “alias” of the real sinusoidal signal.
In the case of sinusoidal signals, the sampling frequency should be higher than
two times the signal frequency [1, 7]. If this is the case of a non-sinusoidal periodic
signal, the highest frequency of interest wnc for this signal must be determined (see
the case of the pulse train in Sect. 1.6.4.) and the sampling frequency should be
higher than two times this frequency (Shannon’s theorem) [4].

1.8 Suggested Experiments and Exercises

In this brief section some signal processing experiments/exercises are suggested.


(a) Synthesizer
Based on Fourier series, a kind of simple synthesizer can be developed. The GUI for
this synthesizer could be a series of sliders, corresponding to even and odd harmonics.
It would be interesting to use as reference the frequencies of piano notes.
An opportune experiment would be to try only even harmonics, or only odd
harmonics, and hear the result.
There are databases of music instrument sounds, available from Internet, that
could be analysed using fft( ). Once the analysis was done, it would be interesting to
try to reproduce the same harmonics contents using the synthesizer. We are not yet
speaking of sound envelopes, but some curiosity about would be expected to arise.
(b) Saturation
Imagine you inject a sine signal into a device with saturation. For instance, the case
of connecting a humble, small loudspeaker to a large signal, which normally results
in much distortion and not very much sound.
What happens when there is saturation? The output will not be a pure sinusoid,
some odd harmonics appear. A basic exercise would be to analyse with fft( ) the
saturated signal.
Suppose the saturated signal is applied to a resistor. It would be interesting to
evaluate, with some graphics, the proportion of power that goes to distortion.
Saturation is a major problem in industrial scenarios, and in communication sys-
tems.
(c) Aliasing
Although one example has been already considered in the chapter, it would be con-
venient to do some more experiments about aliasing. For instance, to conduct a
systematic study of sampling frequencies that leads to aliasing in the form of other
types of signals. The original signal to be sampled could be a sinusoid, squares,
triangles, etc.
A typical aliasing effect happens when you see on a movie wheels that seem to
turn backwards while the car moves forward.
(d) Fourier transform of a signal made of sincs
26 1 Periodic Signals

This is a simple exercise that may lead to interesting observations. The idea is to
create a signal by concatenating a series of sinc functions, and then apply fft( ) to this
signal.
(e) Analysis of a modulated signal
The modulated signals obtained by multiplication have interesting harmonics con-
tents. It would be opportune to apply fft( ) and discuss the result.
One experiment could be to take a sound file and try to modulate it with a sinusoid,
and see what happens.

1.9 Resources

1.9.1 MATLAB

1.9.1.1 Tutorial Texts

• Partial List of On-line Matlab Tutorials (Duke Univ.):


http://people.duke.edu/~hpgavin/matlab.html/
• Getting Started with MATLAB (MathWorks):
http://www.mathworks.com/help/pdf_doc/matlab/getstart.pdf
• Signal Processing Toolbox Examples (MathWorks):
http://es.mathworks.com/help/signal/examples.html
• Griffiths, D.F. (1996). An Introduction to Matlab (U. Dundee.).
http://www.exercicescorriges.com/i_42456.pdf/
• Houcque, D. (2005). Introduction to MATLAB for Engineering Students (North-
western Univ.).
http://www.cse.cuhk.edu.hk/~cslui/CSCI1050/matlab_notes2.pdf/
• Overman, E. (2015). A MATLAB Tutorial (Ohio State Univ.).
https://people.math.osu.edu/overman.2/matlab.pdf
• Kalechman, M. (2009). Practical Matlab Basics for Engineers (City Univ. New
York):
http://read.pudn.com/downloads161/ebook/731301/Practical-Matlab-Basics-for-
Engineers.pdf
• MATLAB Tutorial (GA Tech):
http://users.ece.gatech.edu/bonnie/book/TUTORIAL/tutorial.html/
• YAGTOM: Yet Another Guide TO Matlab (U. Britsh Columbia):
http://ubcmatlabguide.github.io/
• MATLAB Hints and Tricks (Columbia U.):
http://www.ee.columbia.edu/~marios/matlab/matlab_tricks.html
• Some Useful Matlab Tips (K. Murphy, U. British Columbia):
http://www.cs.ubc.ca/~murphyk/Software/matlab_tips.html
1.9 Resources 27

• MATLAB Hints Index (Rensselaer I.):


http://www.rpi.edu/dept/acs/rpinfo/common/Computing/Consulting/Software/
MATLAB/Hints/matlab.html
• High-Quality Graphics in Matlab:
http://dgleich.github.io/hq-matlab-figs/
• High-Quality Figures in Matlab (Univ. Utah.):
https://www.che.utah.edu/department_documents/Projects_Lab/Projects_Lab_
Handbook/MatlabPlots.pdf
• How to Make Pretty Figures with Matlab (D. Varagnolo):
http://staff.www.ltu.se/~damvar/Matlab/HowToMakePrettyFiguresWithMatlab.
pdf

1.9.1.2 Toolboxes

• Signal Processing Toolbox MATLAB:


http://es.mathworks.com/products/signal/
• Data Visualization Toolbox for MATLAB:
http://www.datatool.com/prod02.htm
• WFDB Toolbox (Physiologic signals):
http://physionet.org/physiotools/matlab/wfdb-app-matlab/

1.9.1.3 MATLAB Code

• Matlab Signal Processing Examples:


http://eleceng.dit.ie/dorran/matlab/resources/MatlabSignalProcessingExamples.
pdf
• Digital Signal Processing Demonstrations (Purdue Univ.):
https://engineering.purdue.edu/VISE/ee438/demos/Demos.html
• Matlab Signal Processing, Plotting and Recording Notes,
J. Vignola (Catholic Univ. America):
http://faculty.cua.edu/vignola/Vignola_CUA/ME_560_files/Matlabsignal.proce
ssing-plotingand-recording-knotes.pdf
• Lecture Support Material and Code (Cardiff Univ.):
http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/
• Audio Processing in Matlab (McGill Univ.):
http://www.music.mcgill.ca/~gary/307/week1/matlab.html
• Sound Processing in Matlab (U. Dayton):
http://homepages.udayton.edu/~hardierc/ece203/sound.htm
• Matlab Implementation of some Reverberation Algorithms (U. Zaragoza):
http://www.cps.unizar.es/~fbeltran/matlab_files.html
• Sound Processing in Matlab:
http://alex.bikfalvi.com/research/advanced_matlab_boxplot/
28 1 Periodic Signals

1.9.2 Web Sites

• Educational Matlab GUIs (GA Tech):


http://users.ece.gatech.edu/mcclella/matlabGUIs/
• Signal Processing FIRST (Book site, demos):
http://www.rose-hulman.edu/DSPFirst/visible3/contents/index.htm/
• OnLine Demos (Book site):
http://users.ece.gatech.edu/bonnie/book/applets.html
• Signal Processing Tools (U. Maryland):
http://terpconnect.umd.edu/~toh/spectrum/SignalProcessingTools.html
• Music Analysis and Synthesis (M.R. Petersen):
http://amath.colorado.edu/pub/matlab/music/
• Music Signal Processing (J. Fessler):
http://web.eecs.umich.edu/~fessler/course/100/
• Sound based on sinewaves (D. Ellis):
http://labrosa.ee.columbia.edu/matlab/sinemodel/
• Tutorial on sound amplitude modulation:
https://docs.cycling74.com/max5/tutorials/msp-tut/mspchapter09.html

References

1. P. Cheung, Sampling & Discrete Signals. Lecture presentation, Imperial College Lon-
don (2011). http://www.ee.ic.ac.uk/pcheung/teaching/ee2_signals/Lecture2013-Sampling&
discrete-signals.pdf
2. M. Handley, Audio Basics. Lecture presentation, University College London (2002). www0.cs.
ucl.ac.uk/teaching/Z24/02-audio.pdf
3. J.H. McClellan, R.W. Schafer, M.A. Yoder, Signal Processing First (Prentice Hall, Upper Saddle
River, 2003)
4. T.K. Moon, Sampling. Lecture Notes, UtahState Univ. (2006). http://ocw.usu.edu/Electrical_
and_Computer_Engineering/Signals_and_Systems/lecture6.pdf
5. B.A. Olshausen. Aliasing. Lecture Notes, UC Berkeley (2000).
redwood.berkeley.edu/bruno/npb261/aliasing.pdf
6. H.D. Pfister. Fourier Series Synthesizer. Lecture Notes, Duke Univ. (2013). http://pfister.ee.
duke.edu/courses/ecen314/project1.pdf
7. J. Schesser. Sampling and Aliasing. Lecture presentation, New Jersey Institute of Technology
(2009). https://web.njit.edu/~joelsd/Fundamentals/coursework/BME310computingcw6.pdf

You might also like