Signals and Systems Expertment Instruction Material

You might also like

You are on page 1of 30

Signals and Systems

Experiment Instruction Material


School of Mechanical and Automotive Engineering,
Xiamen University of Technology

Jiesi Luo

Sep 10, 2015

Experiment 1 Basic operation and representation of signals in MATLAB


1. Experiment Objectives

(1) Familiar with the commonly used MATLAB function for signals and systems simulation

analysis in the time-domain;

(2) Learn to express the continuous-time signals and discrete-time signals with MATLAB, and

write the simulation programs in MATLAB.

(3) Familiar with the principle and method for the basic transform and operation of signals in

time-domain, and realize the above principle and method in the MATLAB simulation

environment.

(4) Implement the periodic extension for the time-limited signals.

(5) Use the MATLAB convolution toolbox to perform the convolution operation.

2. The principle of experiment

(1) Unit step signal u(t) and unit impulse signal (t) are two very important signals in

signals and systemstheir definition are as follows;


(t )dt 1
t 1.1(a)
(t ) 0, t0

1, t 0
u (t ) 1.1(b)

0, t 0
The MATLAB extension function to generate the unit impulse signal and the unit step signal are
respectively given in the following;
% The MATLAB extension function to generate the unit impulse signal (t)
function y = delta(t)
dt = 0.01;
y = (u(t)-u(t-dt))/dt;
% The MATLAB extension function to generate the unit step signal u(t)
function y = u(t)
y = (t>=0); % y = 1 for t > 0, else y = 0

Please name the above two MATLAB extension function as delta and u in order, and store them in
Word for the later use.
(2) The discrete-time unit step signal are defined as:

1, n 0
u[n] 1.2

0, n 0
In addition to the above MATLAB extension function, the MATLAB inner function
ones(1,N) also can be used to generate the discrete-time unit step signal. It is worth noting that
ones(1,N) cant generate the true discrete-time unit step signal, and it only generate a unit gate
signal with N length, i.e., u[n]-u[n-N]. However, in a limited graphical window, what we can see
is a unit step series.
(3) Addition and multiplication operation for signals

The (transient) sum of signal f1 and f2 is the sum-signal f3=f1+f2 which consisted of the sum
value of signal f1 and f2 at the same instant. Similarly, the transient product signal of f1 and f2 is
the product-signal f3=f1*f2 which consisted of the product value of signal f1 and f2 at the same
instant. In other words, the addition (or multiplication) of the discrete series can be calculated by
adding (or) multiplying the corresponding value of the discrete series together.

Implement the following operation in MATLAB: f1=sin(t), f2=sin(t),


f1=sin(t) f2=sin(t) f3=f1+f2,f4=f1*f2;x=[0 1 1 1 1 1],h=[2 1 3 4 1
1],y=x+h, g=x.*h;
% The program to implement the addition and multiplication operation for the
continuous signals
% Program 1-3
t=0:0.01:4*pi;
f1=sin(t);
f2= sin(t);
f3=f1+f2;
f4=f1.*f2;
subplot(221);
plot(t,f1);
title('f1 signal');
subplot(222);
plot(t,f2);
title('f2 signal');
subplot(223);
plot(t,f3);
title('f1+f2 signal');
subplot(224);
plot(t,f4);
title('f1*f2 signal');
The result is displayed as follows;

Figure 1.1 the figure for the result of program 1-3


% The program to implement the addition and multiplication operation for the discrete
signals
% Program 1-4
x=[0 1 1 1 1 1];
h=[2 1 3 4 1 1];
y=x+h,g=x.*h;
subplot(221);
stem(x);
title('x signal');
subplot(222);
stem(h);
title('h signal');
subplot(223);
stem(y);
title('x+h signal');
subplot(224);
stem(g);
title('x.*h signal');
The result is shown as Figure1.2;

Figure 1.2 the figure for the result of program 1-4

(4) Time shift of signals


Time shift of signals can be described as the following mathematical expression;
Time shift of a continuous signal x(t) which denoted as y(t) can be expressed as
y(t) = x(t - t0) 1.3
In equation (1.3 ), t0 is the shift value, if t0>0, then y(t) is the result of shift signal x(t) to the
right by 2seconds. Whereas, if t0<0, then y(t) is the result of shift signal x(t) to the left by 2
seconds.
Time shift operation in MATLAB is the same as its expression in mathematics.
For a given continuous signal x(t) = e-0.5tu(t) by left shift 2 seconds and right shift 2
seconds, then the result signal are x1(t) = e-0.5(t+2)u(t+2) and 2(t) = e-0.5(t-2)u(t-2),
respectively.
The implementation program are as follows:
% Program 1-5
clear,
close all,
t = -5:0.01:5;
x = exp(-0.5*t).*u(t); % Generate the original signal x(t)
x1 = exp(-0.5*(t+2)).*u(t+2); % Shift x(t) to the left by 2 second to
get x1(t)
x2 = exp(-0.5*(t-2)).*u(t-2); % Shift x(t) to the right by 2 second to
get x2(t)
subplot(311)
plot(t,x) % Plot x(t)
grid on,
title (' x = exp(-0.5*t).*u(t)')
subplot (312)
plot (t,x1) % Plot x1(t)
grid on,
title (' x1 = exp(-0.5*(t+2)).*u(t+2) ')
subplot (313)
plot (t,x2) % Plot x2(t)
grid on,
title (' x2 = exp(-0.5*(t-2)).*u(t-2)')
xlabel ('Time t (sec)')
The result is shown as Figure1.3;

Figure 1.3 the figure for the result of program 1-5

When running the above programs, we must create the following sub-
function of u(t) in the programs execution path
function y = u(t)
y = (t>=0); % y = 1 for t > 0, else y = 0
Save the above function as u.m
(5) Time reversal of signals
Time reversal of signals can be described as the following mathematical expression;
Time shift of a continuous signal x(t) which denoted as y(t) can be expressed as
y[n] = x[-n] 1.4
Implement of the time reversal in MATLAB is very simple. Many approaches can be used to
accomplish time reversal operation.
Method 1, modifying the time variable t and n to t and n in the drawing function plot(t,x)
and stem(n,x). And the final figure will look like as the time reversal version of the original signal.
Method 2, directly implementing the time reversal of signals by the mathematics relationship
between the time reversal signal and the original signal. This method is the best-fit method in the
practical significant of signals time reversal operation.
Method 3 Using the MATLAB inner function fliplr() to implement the time
reversal of signal. Its usage is as follows
y = fliplr(x),where x is the original signalx(t) or x[n], and y is the time reversal of x. It is
important to note that function fliplr(x) reverses the order of each member of the signal x to
accomplish the time reversal, this reversal is independent with time variable t or n. Therefore, if it
exists a mathematics function can be used to express the signal x and its time variable, we suggest
to restrict the range of the time variable t or n in a positive and negative symmetry.
Write programs to implement m=sin(t), n=sin(-t), x[n]=[1,2,3,4], x[-n], and analysis the
waveform of the above signal.
The implementation program are as follows:
% Program 1-6
t=0:0.01:4*pi;
n=0:1:3;
m=sin(t);
x=[1 2 3 4];
subplot(222);
plot(t,m);
title('sin(t) signal');
subplot(221);
plot(-t,m);
title('sin(-t) signal');
subplot(224);
stem(n,x);
title('x[n] signal');
subplot(223);
stem(-n,x);
title('x[-n] signal');
The result is shown as Figure1.4;

Figure 1.4 the figure for the result of program 1-6


(6) Time scale of signals
Time scale of signals can be described as the following mathematical expression;
Time shift of a continuous signal x(t) which denoted as y(t) can be expressed as
y(t) = x(at) 1.5
Where a is a constant. According to the different value of a, time scale of
signal x(t) have different influence.
When a=1, y(t)=x(t);
When a=-1, y(t)=x(-t), i.e., y(t) can be obtain by the time reversal of
signal x(t).
When a > 1y(t) = x(at)y(t) is obtained by the compression of signal
x(t) in time axis.
When 0 < a < 1 y(t) = x(at) y(t) is obtained by the extension of
signal x(t) in time axis.
When -1 < a < 0 y(t) = x(at) y(t) is obtained by the extension
and reversal of signal x(t) in time axis.
When a < -1 y(t) = x(at)y(t) is obtained by the compression and
reversal of signal x(t) in time axis.
Thus it can be seen that besides the compression or extension of
signals in time domain, the time scale of signals may involve the time
reversal operation.
Write programs to implement m=sin(t), n=sin(2t), x[n]=[1,2,3,4], x[(-1/2)n], and analysis the
waveform of the above signal.
The implementation program are as follows:
% Program 1-7
t=0:0.01:4*pi;
k=2*t;
n=0:1:3;
g=(-2)*n;
m=sin(t);s=sin(k);
x=[1 2 3 4];
subplot(222);
plot(t,m);
title('sin(t) signal');
subplot(221);
plot(t,s);
title('sin(2t) signal');
subplot(224);
stem(n,x);
title('x[n] signal');
subplot(223);
stem(g,x);
title('x[(-1/2)n] signal');
The result is shown as Figure1.5;
Figure 1.5 the figure for the result of program 1-7
(7) Periodic signals
Periodic signal are a kind of very important signal in signals and
systems course.
For a given signal x(t) or x[n],if it satisfies
x(t) = x(t+kT) 1.6
x[n] = x[n+kN] 1.7
Then signal x(t) of x[n] is a periodic signal, where k is a arbitrary integer, T
and N is constant, and they are often called as fundamental period or
minimum period.
Periodic signal can be regard as the result of periodic extension of a time
limit aperiodic signal. Periodic extension is a very important signal process
method in the digital signal process.

The following program is just to obtain a periodic signal by periodic


extension of aperiodic signal x1(t) = e-2t[u(t)-u(t-2)].
The implementation program are as follows:
% Program 1-8
clear, close all;
t = -4:0.001:4;
T = 2; x = 0;
y = exp(-2*t).*(u(t)-u(t-2));
for k = -2:2;
x = x+exp(-2*(t-k*T)).*(u(t-k*T)-u(t-(k+1)*T));
end;
subplot(211);
plot(t,y);
title('e-2t[u(t)-u(t-2)] signal');
subplot(212)
plot(t,x);
title('e-2t[u(t)-u(t-2)]');
The result is shown as Figure1.6;

Figure 1.6 the figure for the result of program 1-8

Reading program 1-8 carefully, we can find its algorithm is



x (t ) x
k
1 (t kT ) 1.8

(8) Convolution calculation.


Convolution calculation is often accomplished by five steps (take convolution integral for
example)
1. Replace the horizontal axis of the waveform of the two signals, t is changed to
becomes the independent variable
2. Reverse one of the two signals in time domain , for example h() is reverse to h(-
)
3. Shift the reversed signal, the shift value is t, and t is a parameter. In -axis, when t >
0right shift of the waveform of h(-), and when t < 0, left shift of the waveform of h(-)
4. Calculate the product of the overlap section x()h(t-)
5. Finish the intergral operation of x()h(t-)
Program convlution_demo can be used to demostrate the above five steps
of convolution. This program is very complex, it dont recommend readers to
master the program, only to execute this program. Through looking into the
execute process to help understand the above 5-steps.
The MATLAB inner funcion conv() can be used to easily implement the
convoltion operation of two signals. Its grammar is y = conv(x,h)Where x and
h are the two signals to convultion, y is the convolution result.
Actually, conv(x,h) is use to accomplish the product of two polynomials. For

examples, polynomial p1 and p2 are given as p1 s 3 2s 2 3s 4 and

p 2 4 s 3 3s 2 2s 1 . In MATLAB, these two polynomials are respectively


express as a row vector which consisted of their respective cofficient. If x and
h are respectively used to express polynomials p1 and p2, then
x = [1 2 3 4]
h = [4 3 2 1]
Type the follwing program in MATLAB command window
>> x = [1 2 3 4];
>> h = [4 3 2 1];
>> y=conv(x,h)
The result is
y = 4 11 20 30 20 11 4
It shows that, the product of polynomials p1 and p2 is

p3 4s 6 11s 5 20 s 4 30s 3 20s 2 11s 4

When we process the time continuous signals in MATLAB, the step-size of independent variable t
should be very small. Suppose the time step-size is denoted as dt, when we use function conv() to
implemet the comvoltion intergral of two time continuous signals, we should multiply the function
conv() by time step-size in its front. That is to say that the correct sentences is y =
dt*conv(x,h).

Given two time continuous signals x (t) = t[u(t)-u(t-1)] and h(t) = u(t)-u(t-1)write MATLAB
programs to accomplish the convolution opertaion of these two signals, and plot their waveform in
time domian.
The implementation program are as follows:
% Program 1-9
t0 = -2; t1 = 4; dt = 0.01;
t = t0:dt:t1;
x = u(t)-u(t-1);
h = t.*(u(t)-u(t-1));
y = dt*conv(x,h); % Compute the convolution of x(t) and h(t)
subplot(221)
plot(t,x), grid on, title('Signal x(t)'), axis([t0,t1,-0.2,1.2])
subplot(222)
plot(t,h), grid on, title('Signal h(t)'), axis([t0,t1,-0.2,1.2])
subplot(212)
t = 2*t0:dt:2*t1; % Again specify the time range to be suitable to the
% convolution of x and h.
plot(t,y), grid on, title('The convolution of x(t) and h(t)'), axis([2*t0,2*t1,-0.1,0.6]),
xlabel('Time t sec')
The result is shown as Figure1.7;
Figure 1.7 the figure for the result of program 1-9

Sometimes,there are one or both two of the two signals for convolution computaion are very
long, even infinite. For processing these signas with MATLAB, they are always regards as finte
length signals, and the specific length is determined by the programmers. Although there exist
inevitable errors in the truncation of signals, these kind of errors can be reduced to an acceptable
level by the reasonable selection of the signal length. For example, given a signal x[n] = 0.5 nu[n],
and specify the range of n is 0 n 100, i.e., the length of x[n] is 101 points. Although the wider
the range of n, the more consistent wiht the practice of x[n]. However for x[n] = 0.5 nu[n],when
n=7, x[7] equals to 0.0078, this value is very small.Therefore, to specify a more longer range of n
for siganl x[n] is not necessay.
(9) Supplemental material for MATLAB used in signal processing.
When we plot the waveform of signals, we often need to show more than one figure in a
same graphical window. In MATLAB, function suboplot() is used to breaks the graphical window
into many sub-windows. For example, subplot(n1,n2,n3) breaks the current graphical window into
n1n2 sub-windows, and plot the figure in the n3th sub-window.
axis([xmin,xmax,ymin,ymax]) is a often used graphic control function, where xmin, xmax is
the starting point and ending point of the horizontal axis to show the waveform, and ymin and
ymax is the starting point and ending point of the horizontal axis to show the waveform.
Sometimes, to improve the readability of the figure, to add some grid lines to reflect the
amplitude of signals is necessary.
In MATLAB, grid on/grid off can be used to add/delete the requisite grid lines to your figure.
3. The experiment contents and steps
Prior to the experiment, all the students should read the above experiment principle for
experiment 1, and understand all the sample programs. To run all the sample programs in the
computer at the beginning of the experiment. And observe the plotted waveform for signals.
Exercise 1:Write a program to implement a unit gate signal with length of 4, and plot the
waveform in time domain.
Exercise 2: Write programs to plot the waveform of m=sin(t), g=sin(2t-pi/2),
x[n]=[1 2 5 6 3 ], x[(1/2)n-1], and analysis the tranfrom progress of the
waveform.
Exercise 3: Write programs to accomplish the convolution opertaion of these two signals
x[n]=[1 3 4 2 6 7], y[n]=[4,3,2,6,7,6,5].
Experiment 2 Fourier Series Representation of Periodic Signals and Gibbs
Phenomenon
1. Experiment Objectives
(1) Understand the physical interpretation of continuous time Fourier series(CTFS)
representation for periodic signals and master the analysis methods.
(2) Observe the Gibbs phenomenon resulted from the truncation of Fourier series
analysis, and understand its characteristics and reasons.
(3) Understand the physical interpretation of the continuous time Fourier transform
(CTFT) for periodic signals and master the analysis methods.
2. The principle of experiment
(1) The continuous time Fourier series (CTFS) representation
If the Dirichlet conditions are satisfied, a periodic signal with period T1 can be
represented as Fourier series.
With Fourier series, a periodic signal is represented as the linear combination of
complex exponential signals. The Fourier series representation of the periodic signal
x(t) is shown as formula (2.1)

x (t ) a
k
k e jk0t (2.1)

Where a k are the Fourier series coefficients, and it can be calculated with the
following formula
T1 / 2
1
x(t )e
jk0t
ak dt (2.2)
T1 T1 / 2

Fourier series with complex exponential form tell us that as long as the Dirichlet
conditions are satisfied, any periodic signal can be represented by a series of
harmonically related periodic complex exponential signals. Periodic complex
exponential signals with different frequencies are called as fundamental frequency
components, and a k are their complex amplitude, and a k are usually complex
numbers.
The formula(2.1) indicates that we can use infinite complex exponential signals
with different frequencies to form any one periodic signal. However, it is impossible
to use infinite complex exponential signals to form a periodic signal by computer or
any other equipment. A periodic signal only can be approximated by a linear
combination of a finite number of complex exponential signals. Suppose the finite
number is N, then the formula can be rewritten as
N
x(t ) a k e jk0t
k N (2.3)
Obviously, the bigger of N, the more close of the synthesis result to the original
signal x(t). This experiment can help readers to understand the
the physical interpretation of (CTFS), and to observe the influences of the different frequency
components of the Fourier series to the waveform. Gibbs phenomenon, i.e., for the waveform of
the synthesis signal, there exists an overshoot of 9% of the height near the discontinuity point of
the original signal, and the bigger of N, the nearer of the overshoot point to the discontinuity. This
phenomenon can be seen clearly by the observation of the rectangular wave signal and the
sawtooth wave signal.
Example one, a periodic rectangular signal is shown in Fig.2.1, and its mathematic
expression is as follows:

1, 0 t 1
x1 (t)
0, 1 t 2

First, according to formula(2.2), Fourier series of this periodic rectangular signal


is calculated as
T1 / 2
1 1
1
1
1

x1 (t )e 0 dt
jk t
ak
2 0 e
jk 0 t
e jk 0 t dt d ( jk0t )
T1 T1 / 2
j 2k0 0

k k k
e jk 0 t
e jk 0 1
1
k
j e
j
2
e
j
2 sin( 0 ) j k 0
0 0

0
2
j 2k0 e
0

j 2k0
2
e 2
j 2k0 k0

k
sin( )
For 0 = 2/T1 = then a ( j ) k 2
k
k
Type the following program in MATLB command:
>> k = -10:10;
>> ak = ((-j).^k).* (sin((k+eps)*pi/2)./((k+eps)*pi)) % The expression
of ak
ak =
Columns 1 through 4
-0.0000 0 + 0.0354i -0.0000 0 + 0.0455i
Columns 5 through 8
-0.0000 0 + 0.0637i -0.0000 0 + 0.1061i
Columns 9 through 12
-0.0000 0 + 0.3183i 0.5000 0 - 0.3183i
Columns 13 through 16
-0.0000 0 - 0.1061i -0.0000 0 - 0.0637i
Columns 17 through 20
-0.0000 0 - 0.0455i -0.0000
0 - 0.0354i
Column 21
-0.0000
From the MATLAB command window, we can
get the Fourier series coefficients from a 10 a10 .
Then type the following program:
>> subplot(221)
>> stem(k,abs(ak),'k.')
>> title('The Fourier series
coefficients') Figure 2.2 The Fourier series coefficients
>> xlabel('Frequency index k')
Figure 2.2 can be obtained, and Figure 2.2 shows the relationship between a k and k
The above Fourier series coefficients and its frequency spectrum are calculated by hand. The
MALAB example to complete the calculation of Fourier series coefficient is given as program2_1
% Program2_1
% This program is used to evaluate the Fourier series coefficients ak of a periodic square wave
clear, close all
T = 2; dt = 0.00001; t = -2:dt:2;
x1 = u(t) - u(t-1-dt); x = 0;
for m = -1:1 % Periodically extend x1(t) to form a periodic signal
x = x + u(t-m*T) - u(t-1-m*T-dt);
end
w0 = 2*pi/T;
N = 10; % The number of the harmonic components
L = 2*N+1;
for k = -N: N; % Evaluate the Fourier series coefficients ak
ak(N+1+k) = (1/T)*x1*exp(-j*k*w0*t')*dt;
end
phi = angle(ak); % Evaluate the phase of ak

Running the program2_1, and type ak in command window, then the 21 coefficients will be
displayed :
ak =
Columns 1 through 4
0.0000 + 0.0000i 0.0000 + 0.0354i 0.0000 - 0.0000i 0.0000 +
0.0455i
Columns 5 through 8
0.0000 - 0.0000i 0.0000 + 0.0637i 0.0000 - 0.0000i 0.0000 +
0.1061i
Columns 9 through 12
0.0000 - 0.0000i 0.0000 + 0.3183i 0.5000 0.0000 - 0.3183i
Columns 13 through 16
0.0000 + 0.0000i 0.0000 - 0.1061i 0.0000 + 0.0000i 0.0000 -
0.0637i
Columns 17 through 20
0.0000 + 0.0000i 0.0000 - 0.0455i 0.0000 + 0.0000i 0.0000 -
0.0354i
Column 21
0.0000 - 0.0000i
We can see that ak obtained from program2_1 and ak from the previous hand calculation have
the same value.
Note: In program2_1, the value of dt can affect the calculation accuracy of the Fourier
coefficient. The smaller value of dt, the higher precision we get. So in Program2_1, the value of dt
is 0.00001. However, the higher precision we get, the more longer of compute time.

(2) Synthesizing the periodic signal and the Gibbs Phenomenon


From the formula(2.1), we know that a periodic signal can always be synthesized by a
linear combination of infinite complex exponential signals with different frequencies
and amplitudes. However, it is impossible to accomplish the synthesis of
infinite items, only the synthesis of limited items is feasible. In practice application,
the periodic signal is synthesized by limited items of complex exponential signals.
Therefore, the error becomes inevitable.
If a periodic signal have discontinuous points in one period, besides the crinkles
will be caused by the introduced error. And there will exists an overshoot of 9% of the
height near the discontinuity point of the original signal, this phenomenon are called
as Gibbs phenomenon.
To observe the differences between the synthesis signal and the original signal,
and the Gibbs phenomenon, we use the above Fourier series coefficients to compute
N
the truncated Fourier series coefficients: x(t ) a k e jk t .
0

k N

This calculation can be finished with L=2N+1 times of loops:


x 2 x 2 ak (r ) e j ( r 1 N ) 0 t

where r is the number of loops. The MATLAB programs are given as follows:
x2 = 0; L = 2*N+1;
for r = 1:L;
x2 = x2+ak(r)*exp(j*(r-1-N)*w0*t);
end;
The periodic rectangular signal shown in Figure 2.1 is the best example to observe
the Gibbs phenomenon. This periodic rectangular signal have two discontinuous
points in one period, use the limited items to synthesis this signal will arouse the
Gibbs phenomenon, and it is obvious to be observed.
Example two: revise the program2_1, use the limited items of complex exponential
signals to synthesis the periodic rectangular signal exhibited in Figure2.1, and plot the
waveform of the original signal and the synthesis signal, and the amplitude spectrum
and angle spectrum.
Program2_1 are revised as program2_2:
% Program2_2
% This program is used to compute the Fourier series coefficients ak of a periodic
square wave
clear,close all
T = 2; dt = 0.00001; t = -2:dt:2;
x1 = u(t)-u(t-1-dt); x = 0;
for m = -1:1
x = x + u(t-m*T) - u(t-1-m*T-dt); % Periodically extend x1(t) to form a
periodic signal
end
w0 = 2*pi/T;
N = input('Type in the number of the harmonic components N = :');
L = 2*N+1;
for k = -N:1:N;
ak(N+1+k) = (1/T)*x1*exp(-j*k*w0*t')*dt;
end
phi = angle(ak);
y=0;
for q = 1:L; % Synthesiz the periodic signal y(t) from the finite Fourier series
y = y+ak(q)*exp(j*(-(L-1)/2+q-1)*2*pi*t/T);
end;
subplot(221),
plot(t,x), title('The original signal x(t)'), axis([-2,2,-0.2,1.2]),
subplot(223),
plot(t,y), title('The synthesis signal y(t)'), axis([-2,2,-0.2,1.2]), xlabel('Time t'),
subplot(222)
k=-N:N; stem(k,abs(ak),'k.'), title('The amplitude |ak| of x(t)'), axis([-N,N,-
0.1,0.6])
subplot(224)
stem(k,phi,'r.'), title('The phase phi(k) of x(t)'), axis([-N,N,-2,2]), xlabel('Index
k')

Set N=12, the results are displayed in Figure2.3

Figure 2.3 the results of program2_2


3. The experiment contents and steps
Exercise : Input the different value of N (7,15,30) in program2_2 to observe the
waveform of the synthesis signal. Analyze the influence of N on the Gibbs phenomenon.
Requirement: plot all the waveform of the synthesis signal with N from 7 to 15.
Experiment 3. Sampling and Reconstruction of Signals
1. Experiment Objectives
(1) Understand the sampling process of the signals.
(2) Understand the sampling theorem.
(3) Master the frequency spectrum analysis of the sampled signals.
(4) Understand the reconstruction of Signals.
2. The principle of experiment
(1) Sampling of signals and the sampling theorem.
Sampling is to extract the samples from the continuous time signal, and thus
obtain a discrete-time sequence.
Figure3.1 gives the schematic diagram for the perfect sampling.
X ( j )
x(t ) xs (t )

p (t )
m m
(a) (b)
3-1 (a) (b)

In Figure3.1, suppose signal x(t) is a band-limited signal, and the range of its
frequencies is m ~ m , the signal p(t) is a unit impulse train whose
mathematics formula are as follows:

p (t ) (t nTs ) (3.1)

According to Figure3.1 and formula(3.1), the sampled signal can be


expressed as

x s (t ) x (t ) p (t ) = x( nTs ) (t nTs ) (3.2)

Obviously, the sampled signal x s (t ) is also a impulse train, merely this impulse
train are weighed by x(nTs).
Since the frequency spectrum of signal p(t) also a impulse train, and

F { p (t )} s ( n s ) (3.4)


1
According to the frequency convolution theorem, X s ( j )
Ts
X ( j ( n
n
s ))

.
Therefore, the frequency spectrum of the sampled signal is the periodic extension of
the frequency spectrum of the original signal with the sampling frequency of s,
which can be seen in Figure3.2.
x(t ) X ( j )

t
M M
p(t ) P ( j )
s
t
Ts s s

xs (t ) 1 / Ts X s ( j )

t
3-2

Example 1. A continuous time signal x(t) = cos(0.5t) and sampling period is Ts =


1/4s, please write the MATLAB program to complete the sampling process.
% Sampling
clear, close all,
t = 0:0.01:10;
Ts = 1/4; % Sampling period
n = 0:Ts:10; % Make the time variable to be discrete
x = cos(0.5*pi*t);
xn = cos(0.5*pi*n); % Sampling
subplot(221)
plot(t,x), title('A continuous-time signal x(t)'), xlabel('Time t')
subplot(222)
stem(n,xn,'.'), title('The sampled version x[n] of x(t)'), xlabel('Time index n')
The result of the above sampling are displayed as Fig3.3

Fig3.3 the waveform of the signal x(t) and its sampled signal xn
(2) The frequency alias in the sampling process
To observe whether the frequency alias are existed, or not, it is necessary to calculate
the Fourier transform of the sampled signal, and plot its frequency spectrum.
The following program3_2 is to calculate the Fourier transform of the sampled signal,
and plot its frequency spectrum.
% Program3_2
clear, close all,
tmax = 4; dt = 0.01;
t = 0:dt:tmax;
Ts = 1/10;
ws = 2*pi/Ts;
w0 = 20*pi; dw = 0.1;
w = -w0:dw:w0;
n = 0:1:tmax/Ts;
x = exp(-4*t).*u(t);
xn = exp(-4*n*Ts);
subplot(221)
plot(t,x), title('A continuous-time signal x(t)'),
xlabel('Time t'), axis([0,tmax,0,1]), grid on
subplot(223)
stem(n,xn,'.'), title('The sampled version x[n] of x(t)'),
xlabel('Time index n'), axis([0,tmax/Ts,0,1]), grid on
Xa = x*exp(-j*t'*w)*dt;
X = 0;
for k = -8:8;
X = X + x*exp(-j*t'*(w-k*ws))*dt;
end
subplot(222)
plot(w,abs(Xa))
title('Magnitude spectrum of x(t)'), grid on
axis([-60,60,0,1.8*max(abs(Xa))])
subplot(224)
plot(w,abs(X))
title('Magnitude spectrum of x[n]'), xlabel('Frequency in radians/s'),grid on
axis([-60,60,0,1.8*max(abs(Xa))])

The result are shown in Fig3.4

Fig3.4 The result of program3_2


The program3_2 can be used to observe the frequency alias degree of the sampled
signals under different sampling frequencies. To facilitate the comparison between X and Xa, 1/Ts
is not multiplied in the calculation of the frequency spectrum X in program3_2. Moreover, the
selection of dt should keep a certain proportion relationship with the sampling period Ts. It is
suggestion that Ts should not be less than 10dt, otherwise the frequency spectrum of the sampled
signal will be wrong.
(3) Reconstruction of Signals
If the sampling theorem is satisfied, the original signal x(t) can be uniquely reconstructed by the
sampled signal x[n]. The signal reconstruction principle is exhibited as Fig3.5.

x(t ) x p (t )

Ideal
Lowpass xr (t )
Filter
p (t )
Fig3.5

Where ideal lowpass filter is also called as reconstruction filter, and its impulse response is
c T sin( c t )
h(t ) (3.5)
c t

According to the convolution theorem, x r (t ) x p (t ) h(t ) , and for the mathematics formula of


the sampled signal is x p (t ) x(nT ) (t nT ) ,then


c T sin( c (t nT ))
x r (t ) x(nT )
n c (t nT )
(3.6)

The formula(3.6) is called as interpolation formula, it is based on that the reconstruction filter is
an ideal lowpass filter. Otherwise, the interpolation formula cant be used for the reconstruction of
signals.
Fig3.6 shows the idea lowpass filter and its impulse response.

H ( j ) h(t )
c
T T

t

c c
Fig3.6

The following program3_3 is the example program to complete the reconstruction of Signals:
% Program
% Signal sampling and reconstruction
% The original signal is the raised cosin signal: x(t) =
[1+cos(pi*t)].*[u(t+1)-u(t-1)].
clear; close all,
wm = 2*pi; % The highest frequency of x(t)
a = input('Type in the frequency rate ws/wm=:'); % ws is the
sampling frequency
wc = wm; % The cutoff frequency of the ideal lowpass
filter
t0 = 2; t = -t0:0.01:t0;
x = (1+cos(pi*t)).*(u(t+1)-u(t-1));
subplot(221); % Plot the original signal x(t)
plot(t,x); grid on, axis([-2,2,-0.5,2.5]);
title('Original signal x(t)');xlabel('Time t');
ws = a*wm; % Sampling frequency
Ts = 2*pi/ws; % Sampling period
N = fix(t0/Ts); % Determine the number of samplers
n = -N:N;
nTs = n*Ts; % The discrete time variable
xs = (1+cos(pi*nTs)).*(u(nTs+1)-u(nTs-1)); % The sampled version
of x(t)
subplot(2,2,2) % Plot xs
stem(n,xs,'.'); xlabel('Time index n'); grid on, title('Sampled version
x[n]');
xr = zeros(1,length(t)); % Specify a memory to save the
reconstructed signal
L = length(-N:N);
xa = xr;
figure(2); % Open a new figure window to see the demo of signal
reconstruction
stem(nTs,xs,'.'); xlabel('Time index n'); grid on;hold on
for i = 1:L
m = (L-1)/2+1-i;
xa = Ts*(wc)*xs(i)*sinc((wc)*(t+m*Ts)/pi)/pi;
plot(t,xa,'b:');axis([-2,2,-0.5,2.5]); hold on
pause
xr = xr+xa; % Interpolation
end
plot(t,xr,'r'); axis([-2,2,-0.5,2.5]); hold on
figure(1);
subplot(223)
plot(t,xr,'r');axis([-2,2,-0.5,2.5]);
xlabel('Time t');grid on
title('Reconstructed signal xr(t)');
% Compute the error between the reconstructed signal and the
original signal
error = abs(xr-x);
subplot(2,2,4)
plot(t,error);grid on
title('Error');xlabel('Time t')

when ws/wm= 3, the result of program3_3 are exhibited in Fig3.7 and


3.8
Fig3.7

Fig3.8

Note: according to the sampling theorem, ws/wm should be greater than or equal
to 2.

3.The experiment contents and steps


Exercise 1. Set ws/wm= 2 ws/wm= 1 ws/wm= 3 in the reconstruction
program and Analyze the different results under these three setting conditions
with the sampling theorem .
Experiment 4 Signal Simulation System
1. Experiment Objectives

(1) Master the signal analysis methods in time domain and frequency domain.

(2)Understand the effect of the system on the input signal.

(3)Understand the signals filtering.

2. The principle of experiment


There are always two methods to analyze the signals when they pass through the certain system,

i.e, the frequency domain analysis and time domain analysis. Fig4.1 is a simplified graphic for a

signal pass through the LTI system.

x (t ) y (t )
h(t )
LTIsystem
X ( j ) H ( j ) Y ( j )

Fig3.4 A simplified graphic for a signal pass through the LTI


system.

In Fig3.4, x(t) and y(t) are respectively the time domain excitation signal and response signal of
the LTI system. h(t) is the unit impulse response of the LTI system. The relationship between there
three is y (t ) x (t ) * h(t ) . Based on the convolution theorem in time domain of the Fourier
transform, there exists the following equation:

Y ( j ) X ( j ) H ( j ) (4.1)
Y ( j )
or H ( j ) (4.2)
X ( j )
H ( j ) is the frequency response of the LTI system, in effect, it just is the Fourier transform of

j t
h(t),i.e., H ( j ) h (t ) e dt . As long as the unit impulse response h(t) is absolutely

integrabel, H ( j ) is always existed, and is often complex. Therefore, H ( j ) is often


expressed as the following polar coordinate form:

H ( j ) H ( j ) e j ( ) (4.3)

Where H ( j ) is called as magnitude response, and it reflects the amplitude changes of the
signal components with different frequencies when a signal pass through the system. And ( )
is called as phase response, it reflects the phase changes of the signal components with different
frequencies when a signal pass through the system. Both H ( j ) and ( ) are the functions
of .
For a system, its frequency response is H(j), and the magnitude response and phase response

are H ( j ) and ( ) ,respectively. Suppose the input excitation signal x(t ) e j0t , then

the response signal is

y (t ) H ( j 0 )e j0t H ( j 0 ) e H ( j 0 ) e j (0t (0 ))
j ( 0 ) j 0 t
e
(4.4)
If the input excitation signal x(t) = sin(0t)then the response signal is

y (t ) H ( j 0 ) sin( 0 t ) | H ( j 0 ) | sin( 0 t ( 0 ))

(4.5)
Therefore, the influences of a system on a certain frequency component are reflected as two sides.
One side is the amplitude will be weighed by H ( j ) , another side is phase will be shifted by

( ) .

Both H ( j ) and ( ) are functions of , so the impacts on amplitude and


phase of the different frequency components are different

(3) Two examples will be introduced to illustrate the two analysis methods of signals when they
pass through a certain system.
Example 1. Write the MATLAB programs to complete a signal 6*sin(20*pi*t) pass through a
system, and the system is to multiply the signal 6*sin(20*pi*t) with signal sin(2*pi*t). plot the
waveform of the original signal and the response signal, and analyze the differences between these
two signals.
%program 4_1
t=0:0.01:2*pi;
m=6*sin(20*pi*t);
g=sin(2*pi*t);
y=m.*g;
subplot(311)
plot(t,m);
title('6*sin(20*pi*t) signal');
subplot(312)
plot(t,g);
title(' sin(2*pi*t) signal');
subplot(313);
plot(t,y);
title('The waveform of the response signal')

Fig4.1 the result of the program4_1

Example 2. Generate three sinusoidal signals, and its respective frequencies are 5Hz,15Hz, and
30Hz. And then design a filter system to filter the signals with the frequencies of 5Hz and 30Hz,
and retain the frequency of 15Hz. The programs are in the following.
%Program4_2
%generate a signal that contains three sinusoidal components
Fs=100;
t=(1:100)/Fs;
s1=sin(2*pi*t*5);
s2=sin(2*pi*t*15);
s3=sin(2*pi*t*30);
s=s1+s2+s3;
subplot(221);
plot(t,s);
xlabel('Time(second)');
ylabel('Time waveform');
title('The original signal ');
%generate a IIR filter with 8 orderthe pass frequecies are from 10Hz to 20, and the frequency
response are as follows:
[b,a]=ellip(4,0.1,40,[10 20]*2/Fs);
[H,w]=freqz(b,a,512);
subplot(222);
plot(w*Fs/(2*pi),abs(H));
title('the designed band pass filter ');
xlabel('Frequency(Hz)');ylabel('Mag.of frequency response');
grid on;
%to filter the original signal
sf=filter(b,a,s);
subplot(223);
plot(t,sf);
xlabel('Time(seconds)');
ylabel('Rime waveform');
title('the waveform of the filtered signal')
axis([0 1 -1 1]);
%plot the frequency spectrums of the original and filtered signal
S=fft(s,512);
SF=fft(sf,512);
w=(0:255)/256*(Fs/2);
subplot(224);
plot(w,abs(S(1:256)),'r--',w,abs(SF(1:256)),'g');
xlabel('Frequency(Hz)');ylabel('Mag.of Fourier transform');
title('the waveform of the original signal and the filered signal in frequency domian ')
grid on;legend('before','after')
3.The experiment contents and steps
Exercise 1. Please give the result figure of program 4_2.
Exercise 2. Write MALTAB program to simulate the following five signals:
u(t)=cos(2*pi*t); v(t)=4*cos(20*pi*t); y(t)=4*(1+2*cos(2*pi*t))*cos(20*pi*t);
y(t)=4*(1+0.5*cos(2*pi*t))*cos(20*pi*t) y(t)=4*(1+cos(2*pi*t))*cos(20*pi*t);
Analysis all the five signals in time domain and frequency domain,and plot the result figure. .

You might also like