You are on page 1of 43

Thực hành Tín hiệu và Hệ thống 2022

ĐẠI HỌC ĐÀ NẴNG


TRƯỜNG ĐẠI HỌC BÁCH KHOA
KHOA ĐIỆN TỬ - VIỄN THÔNG

BÁO CÁO THỰC HÀNH


TÍN HIỆU VÀ HỆ THỐNG

Thành viên nhóm:


Lê Thanh Tâm
Lê Văn Tài
Tô Vũ Trong
Lớp:
20DTCLC2
Giáo viên hướng dẫn:

1
Đà Nẵng, năm 2022
Thực hành Tín hiệu và Hệ thống 2022

TÀI LIỆU HỌC TẬP

• Tài liệu hướng dẫn thực hành (Tham khảo các bài Lab từ Trường EASTERN
MEDITERRANEAN UNIVERSITY)

• Phần mềm MATLAB

• Sách tham khảo:

1. Sundararajan, D.: Practical approach to signals and systems. John Wiley


& Son, 2008.

2. Edward A. Lee, Pravin Varaiya: Structure and Interpretation of Signals


and Systems. Addison-Wesley, 2003.

3. Hwei P. Hsu: SCHAUM'S OUTLINES OF Theory and Problems of


Signals and Systems. McGraw-Hill, 1995.

2
Thực hành Tín hiệu và Hệ thống 2022

NỘI DUNG

Lab 1: Introduction to Matlab


Lab 2: Some Fundamental Properties of Signals
Lab 3: Some Fundamental Properties of Systems
Lab 4: The Convolution Sum and integral
Lab 5: Diferential Equations
Lab 6: Fourier Series and Fourier Transform Representation

3
EENG226 /INFE226 Labsheet#1

EENG/INFE 226 SIGNALS AND SYSTEMS


LAB 1
INTRODUCTION TO MATLAB

1. General View

MATLAB is a high-level programming language that has been used extensively to


solve complex engineering problems.
MATLAB works with three types of windows on your computer screen. These are
the Command window, the Figure window and the Editor window. The Figure window
only pops up whenever you plot something. The Editor window is used for writing and
editing MATLAB programs (called M-files) and can be invoked in Windows from the pull-
down menu after selecting File | New | M-file.
The command window is the main window in which you communicate with the
MATLAB interpreter. The MATLAB interpreter displays a command >> indicating that it
is ready to accept commands from you.
You can use the command window as a calculator, or you can use it to call other
MATLAB programs (M-files). Say you want to evaluate the expression c where a=1.2,
b=2.3, c=4.5 and d=4. Then in the command window, type:

>> a = 1.2;
>> b=2.3;
>> c=4.5;
>> d=4;
>> a^3+sqrt(b*d)-4*c

ans = -13.2388

Note the semicolon after each variable assignment. If you omit the semicolon, then
MATLAB echoes back on the screen the variable value.

2. Arithmetic Operations

There are four different arithmetic operators:


+ Addition
− Subtraction
* Multiplication
/ Division (for matrices it also means inversion)

There are also three other operators that operate on an element by element basis:
.* Multiplication of two vectors, element by element
./ Division of two vectors, element-wise
.^ Raise all the elements of a vector to a power.

>> X=[1,3,4]
>> Y=[4,5,6]
>> X+Y
ans= 5 8 10

1 Prepared By: Alaa Eleyan


EENG226 /INFE226 Labsheet#1

For the vectors X and Y the operator + adds the elements of the vectors, one by
one, assuming that the two vectors have the same dimension. In the above example, both
vectors had the dimension 1 × 3, i.e., one row with three columns. An error will occur if
you try to add a 1 × 3 vector to a 3 × 1 vector. The same applies for matrices.
To compute the dot product of two vectors, you can use the multiplication
operator *. For the above example, it is:

>> X*Y’

ans = 43

Note the single quote after Y. The single quote denotes the transpose of a matrix
or a vector. To compute an element by element multiplication of two vectors (or two
arrays), you can use the .* operator:

>> X.*Y

ans = 4 15 24

That is, X.*Y means [1×4, 3×5, 4×6] = [4 15 24]. The ‘.*’ operator is used very
often (and is highly recommended) because it is executed much faster compared to the
code that uses for loops.

3. Complex Numbers

MATLAB also supports complex numbers. The imaginary number is denoted


with the symbol i or j, assuming that you did not use these symbols anywhere in your
program (that is very important!). Try the following:

>> z=3 + 4i
>> conj(z) % computes the conjugate of z
>> angle(z) % computes the phase of z
>> real(z) % computes the real part of z
>> imag(z) % computes the imaginary part of z
>> abs(z) % computes the magnitude of z

You can also define the imaginary number with any other variables you like. Try
the following:

>> img=sqrt(-1)
>> z=3+4*img
>> exp(pi*img)

4. Array Indexing

In MATLAB, all arrays (vectors) are indexed starting with 1, i.e., y(1) is the first
element of the array y. Note that the arrays are indexed using parenthesis (.) and not
square brackets [.] as in C/C++. To create an array having as elements the integers 1
through 6, just enter:

2 Prepared By: Alaa Eleyan


EENG226 /INFE226 Labsheet#1

>> x=[1,2,3,4,5,6]

Alternatively, you can use the : notation,

>> x=1:6

The : notation above creates a vector starting from 1 to 6, in steps of 1. If you


want to create a vector from 1 to 6 in steps of say 2, then type:

>> x=1:2:6

Ans = 1 3 5

Extracting or inserting numbers in a vector can be done very easily. To


concatenate an array, you can use the [] operator, as shown in the example below:

>> x=[1:3 4 6 100:110]

To access a subset of the array, try the following:

>> x(3:7)
>> length(x) % gives the size of the array or vector
>> x(2:2:length(x))

5. Allocating Memory

You can allocate memory for one-dimensional arrays (vectors) using the zeros
command. The following command allocates memory for a 100-dimensional array:

>> Y=zeros(100,1);
>> Y(30)

ans = 0

Similarly, you can allocate memory for two-dimensional arrays (matrices). The
command

>> Y=zeros(4,5)

defines a 4 X 5 matrix. Similar to the zeros command, you can use the command ones to
define a vector containing all ones,

>> Y=ones(1,5)

ans= 1 1 1 1 1

3 Prepared By: Alaa Eleyan


EENG226 /INFE226 Labsheet#1

6. Special Characters and Functions

Some common special characters used in MATLAB are given below:

Symbol Meaning
pi π(3.14...)
sqrt indicates square root e.g., sqrt(4)=2
ˆ indicates power(e.g., 3ˆ2=9)
abs Absolute value | .| e.g., abs(-3)=3
NaN Not-a-number, obtained when comparing mathematically undefined operations,
such as 0/0
Inf Represents +∞
; Indicates the end of a row in a matrix. It is also used to suppress
printing on the screen (echo off)
% Denotes a comment. Anything to the right of % is ignored by the
MATLAB interpreter and is considered as comments
’ Denotes transpose of a vector or matrix. It’s also used to define strings,
e.g.,str1=’DSP’;

Some special functions are given below:

length(x) - gives the dimension of the array x


find - Finds indices of nonzero elements.

>> x=1:10;
>> length(x)

ans = 10

The function find returns the indices of the vector X that are non-zero. For example,
I= find(X>100), finds all the indices of X when X is greater than 100. So for the
above

>> find(x> 4)

ans = 5 6 7 8 9 10

7. Plotting
You can plot arrays using MATLAB’s function plot. The function plot(.) is
used to generate line plots. The function stem(.) is used to generate “picket-fence” type
of plots.

>> x=1:20;

4 Prepared By: Alaa Eleyan


EENG226 /INFE226 Labsheet#1

>> plot(x)
>> stem(x)

More generally, plot(X,Y) plots vector Y versus vector X. Various line types,
plot symbols and colors may be obtained using plot(X,Y,S) where S is a character
string indicating the color of the line, and the type of line (e.g., dashed, solid, dotted,
etc.). Examples for the string S include:

r Red + Plus -- Dashed


g Green * Star
b Blue S Square

You can insert x-labels, y-labels and title to the plots, using the functions
xlabel(.), ylabel(.) and title(.) respectively. To plot two or more graphs on the
same figure, use the command subplot. For instance, to show the above two plots in the
same figure, type:

>> subplot(2,1,1), plot(x)


>> subplot(2,1,2), stem(x)

The (m,n,p) argument in the subplot command indicates that the figure will be
split in m rows and n columns. The ‘p’ argument takes the values 1, 2 . . . m×n. In the
example above, m = 2, n = 1,and, p = 1 for the top figure and p = 2 for the bottom figure.

**** To get more help on plotting, type: help plot or help subplot.

5 Prepared By: Alaa Eleyan


EENG226 /INFE226 Labsheet#2

EENG/INFE 226 SIGNALS AND SYSTEMS


LAB 2
SOME FUNDAMENTAL PROPERTIES OF SIGNALS

n = sin 2Mn 


1) Consider the discrete-time signal
x
M  
 N 
and assume N=12. For M=4, 5, 7 and 10, plot xM n on the interval 0  n  2N − 1. Use
stem to create your plots, and
be sure to appropriately label
your axes. What is the
fundamental period of each
signal?
Answer:

N=12;
n=0:2*N-1;
M=4; %M=5,7,10
x_M=sin((2*pi*M*n)/N);
figure(1)
stem(n,x_M,'filled')
title('x[n]=sin((2*pi*M*n)/N)')
xlabel('Time')
ylabel('Amplitude')

1 Prepared by: Alaa Eleyan


EENG226 /INFE226 Labsheet#2

2) Now consider the following signals:


x2 n =  2n cos  3n 

 + N
2 cos
 N
   
x n =  2n  + 3sin 5n 
3 cos   
 N   2N 
Assume N=6 for each signal. Determine whether or not each signal periodic. If a signal is
periodic, plot the signal for two periods, starting at n=0. Plot the signal for 0  n  7N and
explain why it is periodic or not. Remember to use stem and to appropriately label your
axes.
Answer:
N=6;
n=0:7*N;
x2=2*cos(2*n/N)+cos(3*n/N);
x3=cos(2*pi*n/N)+3*sin(5*(pi/2)*n/N);
subplot(2,1,1),stem(n,x2)
title('x2[n]')
subplot(2,1,2),stem(n,x3)
title('x3[n]')

2 Prepared by: Alaa Eleyan


EENG226 /INFE226 Labsheet#2

3) a) Define a MATLAB vector nx to be the time indices − 3  n  7 and the MATLAB


vector x to be the values of the signal x[n] is given by
2,Kn = 0,
1,Kn = 2,

xn = −1,Kn = 3,
3,Kn = 4,

0,Kotherwe
If you have defined these vectors correctly, you should be able to plot this discrete time
sequence by typing stem(nx,x).
Answer:

3 Prepared by: Alaa Eleyan


EENG226 /INFE226 Labsheet#2
nx=-3:7;
x=[0 0 0 2 0 1 -1 3 0 0 0];
stem(nx,x,'filled')
title('x[n]')
xlabel('n')
ylabel('x[n]')

b) For this part, you will define MATLAB vectors y1 through y4 to represent the
following discrete-time signals:
y 1 n  = x n − 2  ,
y 2 [ n ] = x n − 1  ,
y 3 n  = x − n ,
y 4 [ n ] = x − n + 1 
to do this, you should define y1 through y4 to be equal to x. The key is to define
correctly the corresponding index vectors ny1 through ny4. First, you should figure out
how the index of a given sample of x[n] changes when transforming to yi n. The index
vectors need not span the same of indices as nx, but they should all be at least 11
samples long and include the indices of all nonzero samples of associated signal.

4 Prepared by: Alaa Eleyan


EENG226 /INFE226 Labsheet#2

Answer:

n=-3:7;
x= [2 0 1 -1 3 0];
nx=[0 0 0 x 0 0];
ny1=n+2; ny2=n-1;
ny3=-n; ny4=-n+1;
figure(1)
subplot(2,1,1),stem(ny1,nx,'filled')
xlabel('time')
ylabel('x[n-2]')
title('x[n-2]')
subplot(2,1,2),stem(ny2,nx,'filled')
xlabel('time')
ylabel('x[n+1]')
title('x[n+1]')
figure(2)
subplot(2,1,1),stem(ny3,nx,'filled')
xlabel('time')
ylabel('x[-n]')
title('x[-n]')
subplot(2,1,2),stem(ny4,nx,'filled')
xlabel('time')
ylabel('x[-n+1]')
title('x[-n+1]')

5 Prepared by: Alaa Eleyan


EENG226 /INFE226 Labsheet#2

6 Prepared by: Alaa Eleyan


Name: ……………................................................................................. ID No.:…………………

EENG/INFE 226 SIGNALS AND SYSTEMS


LAB 3
SOME FUNDAMENTAL PROPERTIES OF SYSTEMS
Objective

The objective of this experiment is to introduce using MATLAB to define an LTI system and
determine on its main features, such as; linearity, causality stability invertibility and time
variance. This is achieved by examining the performance of the system for particular inputs that
will show those characteristics.

1. Linearity:

A system is linear if superposition holds. Specifically, a linear system must satisfy the two
properties:

• 1 Additive: the response to x1(t)+x2(t) is y1(t) +


y2(t)

• 2 Scaling: the response to ax1(t) is ay1(t) where


aC

• Combined: ax1(t)+bx2(t) ay1(t) + by2(t)


Exercise 1

The system is [ ] n( [ ]) is not linear. Show


that it violates linearity by giving a counter example. A
good example is the set of signals Figure 1 Exercise 1 Result

[][ ]

[][]

Write a MATLAB code to demonstrate this example. This can be done as follows:

• Define the domain of the two signals to be from -3 to 3 and save it as a vector n
• Define the signal x1 as a vector of the values [0 0 0 1 0 0 0]
• Define the signal x2 =2x1
• Evaluate the output corresponding to the x1 input, and label it as y1
• Evaluate the output corresponding to the x2 input, and label it as y2

On the same graph window, plot the signals x1, x2, y1 and y2 using the commands (subplot) and
(stem). Your results should be as depicted in Figure 1.
Answer:
n=-3:3;
x1=[0 0 0 1 0 0 0];
x2=2*x1;
y1=sin((pi/2)*x1);
y2=sin((pi/2)*x2);

figure(1)
subplot(4,1,1),stem(n,x1,'filled')
title('x1[n]')
subplot(4,1,2),stem(n,y1,'filled')
title('y[n]')
subplot(4,1,3),stem(n,x2,'filled')
title('x2[n]')
subplot(4,1,4),stem(n,y2,'filled')
title('y[n]')
Q: Is y2 equal to 2y1, what is your coment?

…………………………………………………………………………………………………………………………

2. Causality

A causal system is a system where the current


output depends on past/current inputs but not
future inputs.

Exercise 2

The system [ ] [ ] [ ] is not


causal. Use the input signal [ ] [ ] to
show this, as follows:

• Define the time (sample) interval to be


between -6 and 9, and label it as n.
• Define the signal x[n]=U[n] as an array
with the values 0 for n<0 and 1 for n>=0 Figure 2 Exercise 2 Result
and label it as x.
• Define the signal x[n+1] =U[n+1] as an array of zeros for n<-1 and 1 for n>=-1 and label
it as x_shift.
• Define the output signal y[n] as x[n]+x[n+1] .
• On the same window, plot the signals x[n], x[n+1] and y[n] using the commands
(subplot) and (stem).You should have a plot identical to the one shown in Figure 2.
Answer:
n=-6:9;
x1=[0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1];
x2=[0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0];
y=x1+x2;

figure(1)
subplot(3,1,1),stem(n,x1,'filled')
title('x[n]')
subplot(3,1,2),stem(n,x2,'filled')
title('x[n+1]')
subplot(3,1,3),stem(n,y,'filled')
title('y[n]')

2
Q: What is your comment about the system causality?

…………………………………………………………………………………………………………………………

3. Stability

For a stable system, if an input signal is bounded, then the output signal must also be bounded.

Exercise 3

The system y[n]=log(x[n]) is not stable because the (log) function goes to minus infinity at the 0
input. Write a MATLAB code to illustrate this. Proceed as follows:

• Define the domain vector as n ranging between -2 and 3.


• Define the input signal x as a vector of the values: 1, 2, 0, 3, 4 and 5.

3
• Declare the output vector as y= log(x). using the(log) function.
• Using stem and subplot commands, plot the input signal x[n] and the corresponding
output signal y[n]. The result should appear as shown in Figure 3.
Answer:
n=-2:3;
x=[1 2 0 3 4 5];
y=log(x);

figure(1)
subplot(2,1,1),stem(n,x,'filled')
title('x[n]')
subplot(2,1,2),stem(n,y,'filled')
title('y[n]')

Q: Comment on your result. How does this result indicate that the system is unstable?

…………………………………………………………………………………………………………………………

3
4. Invertible and Inverse Systems

Invertible System A system is invertible if the input signal can be uniquely determined from
knowledge of the output signal. Therefore, invertibility requires the system to be one-to-one and
generate a distinct output for each input.

Exercise 4

The system y[n] = sin(2πx[n]) where x[n]=[0 1 2 3 4 0] is not invertible. Illustrate this by
showing that the system is not one-to-one. As follows:

• Define a vector of n values of 0,1,2,3,4 and 5 and label it as n.


• Define x[n] as a vector of the values 0,1,2,3,4 and 5.
• Define the output as y[n] = sin(2πx[n]).
• Plot x[n] and y[n] using the commands (stem) and (subplot). Your result should be as
shown in Figure4.
Answer:
n=0:5;
x=[0 1 2 3 4 0];
y=sin(2*pi*x);

figure(1)
subplot(2,1,1),stem(n,x,'filled')
title('x[n]')
subplot(2,1,2),stem(n,y,'filled')
title('y[n]')

4
Q: Comment on the result justifying the claim that the system in not invertible

………………………………………………………………………………………………………
……………………………………………………………………………………………………

Figure 3 Exercise 3 Result Figure 4 Exercise 4 Result


5
Students name: ………............................................................ ID No.:……………

EENG/INFE 226 SIGNALS AND SYSTEMS


LAB 4
The Convolution Sum and Integral
Objective

The objective of this experiment is to introduce using MATLAB to perform discrete time
convolution, and to simulate continuous time convolution for some common signals.

Convolution:

The convolution of the signals x(t) and h(t) is mathematically defined as:

() () ( ) ∫ () ( )

And for the discrete time signals x[n] and h[n], it is defined as:

[][][]∑ [][]

Exercise 1

Use MATLAB to evaluate the convolution of x[n] with itself, where

[ ] { }

Procedure:

• Define the signal x as a vector of values [ 1 1 1 1 1 1], using the (ones) command.
• Use the (conv) function to evaluate the convolution of x with itself, and name it as y.
• Define the index vector n to range from 0 to 10.
• Using the function (stem), plot y versus n.
• Label the vertical and horizontal axes as (Amplitude) and (Time), respectively.
• Title the figure as (y[n]).
Answer:
x=ones(1,6);
y=conv(x,x);
n=0:10;
figure(1)
stem(n,y,'filled')
xlabel('Time')
ylabel('Amplitude')
title('y[n]')
Prepared by: Mahmoud Nazzal & Qadri Mayyala 1
Q: Comment on the relationship between the length of y[n] and x[n]

…………………………………………………………………………………………………………………………

Prepared by: Mahmoud Nazzal & Qadri Mayyala 2


Exercise 2

I. Consider the discrete time signals:

[ ] { }

[ ] { }

• Define the signal x as a vector of values [0 1 2 3 4 5].


• Define the signal u as a vector of values [ 1 1 1 1 1 1], using the (ones) command.

• Use the function (conv) function to evaluate the convolution of x with u, and name it as
y.
• Define the index vector n to range from 0 to 10.
• Using the function (stem), plot y versus n.
• Label the vertical and horizontal axes as (Amplitude) and (Time), respectively.
• Title the figure as (y[n]).
Answer:
x=[0 1 2 3 4 5];
u=ones(1,6);
y=conv(x,u);
n=0:10;
figure(2)
stem(n,y,'filled')
xlabel('Time')
ylabel('Amplitude')
title('y[n]')

Prepared by: Mahmoud Nazzal & Qadri Mayyala 2


II. Repeat part I using u[n+5] instead of u[n].
Answer:
x=[0 1 2 3 4 5];
u=ones(1,6);
y=conv(x,u);
n=-5:5;
figure(3)
stem(n,y,'filled')
xlabel('Time')
ylabel('Amplitude')
title('y[n]=x[n]*u[n+5]')

Prepared by: Mahmoud Nazzal & Qadri Mayyala 3


Q: Comment on the relationship between y[n] in part I, and y[n] of part II.

……………………………………………………………………………………………………………………

Exercise 3

In this part, continuous time convolution will be simulated in the discrete case. Consider the
continuous time signals x(t) and h(t). Generate these functions using a time step of 0.1.

( ) { }

( ) { }

Procedure:

• Define the domain of x as a vector ranging from 1 to 5, with a time step of 0.1. Name it
as tx.
• Define the domain of h as a vector ranging from 2 to 7, with a time step of 0.1. Name it

Prepared by: Mahmoud Nazzal & Qadri Mayyala 4


as th.
• Define the signal x as a vector of ones over the index vector tx, using the (ones),(length)
command,

Prepared by: Mahmoud Nazzal & Qadri Mayyala 5


• Define the signal h as a vector of ones of the index vector th, using the (ones) ),(length)
command
• Declare the total time length of the convolution to range from 3 to 12, with a 0.1 step.
Name it as ty.
• Use the function (conv) function to evaluate the convolution of x(t) with h(t), and name it
as y. Hint: Don’t forget to multiply the conv. by Ts=0.1 (Ts step time)
• Using the function (stem), plot y versus ny.
• Label the vertical and horizontal axes as (Amplitude) and (Time), respectively.
• Title the figure as (y(t)).
Answer:
tx=1:0.1:5;
th=2:0.1:7;
x=ones(1,length(tx));
h=ones(1,length(th));
ty=3:0.1:12;
Ts=0.1;
y=conv2(x,h)*Ts;
figure(4)
stem(ty,y,'filled')
xlabel('Time')
ylabel('Amplitude')
title('y[t]')

Prepared by: Mahmoud Nazzal & Qadri Mayyala 3


Q: Comment on the relationship between the time length of y(t)and that of x(t) and h(t)

…………………………………………………………………………………………………………………………

Prepared by: Mahmoud Nazzal & Qadri Mayyala 4


The RESULTS:
y[n] y[n]
6 15

4 10
Amplitude

Amp.
3

2 5

0
0 1 2 3 4 5 6 7 8 9 10 0
0 1 2 3 4 5 6 7 8 9 10
Time
Time

Exercise 1 Exercise 2
Part -1

y[n]=x[n] * u[n+5] y(t)


15 4.5

3.5

10 3

2.5
Amp.

Amp

5 1.5

0.5

0 0
-5 -4 -3 -2 -1 0 1 2 3 4 5 3 4 5 6 7 8 9 10 11 12
Time Time

Exercise 2 Exercise 3
Part -2

Prepared by: Mahmoud Nazzal & Qadri Mayyala 5


Name: ……........................................................................... ID No.:………………

EENG/INFE 226 SIGNALS AND SYSTEMS


LAB 5
DIFFERENTIAL EQUATIONS
Objective

The objective of this experiment is to introduce using MATLAB to evaluate the response of an
LTI system, characterized by a linear constant-coefficient differential equation, to a certain input.
As well as using MATLAB functions to calculate the step and impulse responses of such
systems.

1. LTI Systems Described by Differential Equations:

MATLAB function (lsim) can be used to simulate the output of an LTI system characterized by a
linear constant-coefficient differential equation of the form described in equation1.
∑ ∑ …………………………………………….. (1)
The latter equation can be programmed using the function (lsim), as
y=lsim(a,b,x,t)

We need to specify the following:

• The LTI system: is specified by providing the coefficients of y and x as row vectors (a)
and (b), respectively.
• The input signal: specified as a row vector (x).
• The time interval: as a row vector (t) of equally-spaced time values.

Exercise 1

Consider the causal LTI system described by the first order differential equation:

The latter equation can be rewritten as

Write a MATLAB code to simulate the step response of this system. This can be done as
follows:

• Define the system coefficient vectors(a) and (b)


• Define the time vector t ranging from 0 to 10, with a 1 time increment.
• Define input as a row vector x of ones with the same length of t.
• Use the function (lsim) to evaluate the output y.
• Plot the output vector y versus time vector t with dashed lies (- -).
1
By: Mahmoun Nazzal & Qadri Mayyala
• Label the axes as the (output), (time), respectively.
• Title the figure as (Simulated Output).

To compare the simulated output to the actual one, plot the solution of the differential equation
versus time as follows:

• Define the time vector t ranging from 0 to 10, with a 1 time increment.
• Plot the function 2(1- ), versus time.
• Label the axes and title the figure as( Exact Output)
• Your answer should be as indicated in Fig1 .
Answer:
a=[1 1/2];
b=1;
t=0:10;
x=ones(1,length(t));
y=lsim(b,a,x,t);

figure(1)
plot(t,y,'--')
title('S(t)')
xlabel('t')
ylabel('S')

By: Mahmoun Nazzal & Qadri Mayyala


Exercise 2

Following a similar procedure to that of exercise 1, use (lsim) to compute the response of the
system:

To the input:

Your answer should be as indicated in Fig2.


Answer:
a=[1 2];
b=1;
t=0:10;
x=[0 0 ones(1,9)];
y=lsim(b,a,x,t);

figure(1)
plot(t,y)
title('S(t)')
xlabel('t')
ylabel('S')

By: Mahmoun Nazzal & Qadri Mayyala


2. Step Response:

The MATLAB function (step) can be used to evaluate the step function of a causal LTI system
characterized by equation 1. This function can be called as follows:

y=step(b,a,t)

, where;
a: is the coefficient vector of y
b: is the coefficient vector of x
t: is the time vector
Similarly,
y=impulse(b,a,t)

generates the impulse response of the system characterized by coefficient vectors a and b, on
time interval t.

Exercise 3

Plot the step and impulse responses of the system described by:

By: Mahmoun Nazzal & Qadri Mayyala


Proceed as follows:

• Define the system coefficient vectors(a) and (b)


• Define the time vector t ranging from 0 to 10, with a 0.1 time increment.
• Define input as a row vector x of ones with the same length of t.
• Use the function (step) to evaluate the step response of the system, and name it as s.
• Use the function (impulse) to evaluate the step response of the system, and name it as i.
• Use the command (subplot) to plot the step impulse response(s) on the top, and impulse
response (i) in the bottom of the same graph window.
• Label the axes and title the figures.
• Your answer should be as indicated in Fig2.
Answer:
a=[1 1/2];
b=1;
t=0:10;
x=ones(1,length(t));
s=step(b,a,t);
i=impulse(b,a,t);

figure(1)
subplot(2,1,1), plot(t,s)
title('S(t)')
xlabel('t')
ylabel('S')
subplot(2,1,2), plot(t,i)
title('i(t)')
xlabel('t')
ylabel('i')

By: Mahmoun Nazzal & Qadri Mayyala


By: Mahmoun Nazzal & Qadri Mayyala
Results

The following four figures show the expected results of excersises 1,2,3 and4,
respectively.
s(t)
2
2
1.8
1.8
1.6
1.6

1.4
1.4

1.2 1.2

1 1

s
0.8 0.8

0.6 0.6

0.4
0.4

0.2
0.2

0
0 1 2 3 4 5 6 7 8 9 10 0
0 1 2 3 4 5 6 7 8 9 10
t
Fig 1: Exercise 1 Output Fig2: Exercise 2 Output

s(t)
s(t) 2
0.5
1.5
0.45

1
s

0.4

0.5
0.35
0
0.3 0 1 2 3 4 5 6 7 8 9 10
t
0.25
s

i(t)
1
0.2

0.15
0.5
i

0.1

0.05
0
0 0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10 t
t

Fig 3: Exercise 3 Output Fig 4: Exercise 4 Output

By: Mahmoun Nazzal & Qadri Mayyala


Students name: ………............................................................ ID No.:……………

EENG/INFE 226 SIGNALS AND SYSTEMS


LAB 6
FOURIER SERIES and FOURIER TRANSFORM REPRESENTATION
Objective

The objective of this experiment is to introduce using MATLAB to perform Discrete-Time


Fourier Series (DTFS), Continuous-Time Fourier Series (CTFS), and to compute the frequency
response of a causal LTI-system.

6.1 Compute the DTFS with fft:

The discrete-time Fourier series (DTFS) is a frequency-domain representation for periodic


discrete-time sequences. For a signal x[n] with fundamental period N, the DTFS synthesis and
analysis equations are given by:

∑ ( ⁄ ) ................. synthesis

∑ ( ⁄ ) .................. analysis
x: represent one period of an N periodic signal.
X: gives DTFS coefficient as a vector.

MATLAB contains two very efficient routines for computing Analysis and synthesis:
• If x is an N-point vector containing x[n] for the period 0 ≤ n ≤ N −1, then the DTFS of
x[n] can be computed by:
>> ( ⁄ ) .
• If X is an N-point vector containing X[k] for the period 0 ≤ k ≤ N −1, then the synthesis
of DTFS of X[k] can be computed by:
>> .

Exercise 1:

Consider using MATLAB to solve Problem 3.3(a) in (Simon Haykin 2nd Edition) book. For the
DTFS coefficient, the signal:

Prepared by: Mahmoud Nazzal & Qadri Mayyala 1


This signal has period N=24.

Procedure:

• Define the signal period N.


• Define the index vector n to range from 0 to 23.
• Define the signal x as a vector of ones using the (ones) command plus sin valus. Also
plot the signal in figure 1 using stem.
• Use the function (fft) function to evaluate the DTFS coefficients. and store it in X.
• Plot the real and imaginary parts of fourier series coefficient x using subplot and stem on
figure 2.
• Plot the absolute value and angles of fourier series coefficient x using subplot and stem
on figure 3.
• Use the function (ifft) function to reconstruct the orginal time domain signal x . and
store it in x_recon. Plot it on figure 4 as real and imaginary part using subplot.
Answer:
N=24;n=0:N-1;
x=ones(1,24);
x1=1+sin(((n*pi)/12)+((3*pi)/8));
figure(1)
stem(n,x1,'filled')
title('x[n]')
x2=(1/N)*fft(x1);
X1=real(x2);
X2=imag(x2);
figure(2)
subplot(2,1,1),stem(n,X1,'filled')
subplot(2,1,2),stem(n,X2,'filled')
figure(3)
X3=abs(x2);
X4=angle(x2);
subplot(2,1,1),stem(n,X3,'filled')
subplot(2,1,2),stem(n,X4,'filled')
x_recon=N*ifft(x2);
figure(4)
X5=real(x_recon);
X6=imag(x_recon);
subplot(2,1,1),stem(n,X5,'filled')
subplot(2,1,2),stem(n,X6,'filled')

Prepared by: Mahmoud Nazzal & Qadri Mayyala 2


Prepared by: Mahmoud Nazzal & Qadri Mayyala 3
Prepared by: Mahmoud Nazzal & Qadri Mayyala 4
Q: Comment on the relationship between figures of x[n] and x_recon?

…………………………………………………………………………………………………………………………
1
2
fig 1
1.8

1.6
0.5
1.4

1.2

1 0
0 5 10 15 20 25
0.8

0.6 fig 3
4
0.4

0.2 2

0
0 5 10 15 20 25 0
Figure 1
-2
1

-4
0 5 10 15 20 25
0.5

1.5
0
0 5 10 15 20 25
1

fig 2 0.5
0.2
0
0 5 10 15 20 25
0.1
fig 4
1
0
0.5
-0.1
0

-0.5

-1
0 5 10 15 20 25

Figure 4

Figure 2

-0.2
0 5 10 15 20 25
Figure 3

Prepared by: Mahmoud Nazzal & Qadri Mayyala 5


6.1 Frequency Response Of LTI System From Impulse Response:

For a causal LTI system described by a difference equation,


• the command [H omega]=freqz (b,a,N) computes the frequency response at N
evenly spaced frequencies between 0 and π , i.e., ( ⁄ ) for 0 ≤ k ≤ N −1 .
• the command [H omega]=freqz (b,a,N,’whole’) computes the frequency response
at N evenly spaced frequencies between 0 and 2π , i.e., ( ⁄ ) for 0 ≤ k ≤ N −1 .

◼ the coefficient vectors a and b specify the difference equation using the same format
in lab 5.
◼ Freqz returns in H and the frequencies in omega.

Exercise 2:

Consider the following difference equation:

1) Evaluate the Frequency Response at 4 evenly spaced between 0 and ?

Procedure:

• Define a and b to describe the previous causal LTI system as a vectors.


• Use freqz with the coefficients a and b define H1 to be the value of the frequency
response at 4 evenly spaced frequencies between 0 and π and omega1 to be those
frequencies.

2) Evaluate the Frequency Response at 4 evenly spaced between 0 and 2 ?

Prepared by: Mahmoud Nazzal & Qadri Mayyala 3

You might also like