Signal Systems Lab Manual PDF
Signal Systems Lab Manual PDF
LAB MANUAL
FALL 2013
STUDENT NAME:
REGISTRATION NUMBER:
Table of Contents
Experiment # 1 ...............................................................................................................................4
Introduction to MATLAB .............................................................................................................4
MATLAB as a Calculator ...........................................................................................................5
Number and Formats ...................................................................................................................5
Variables ......................................................................................................................................6
General Information .....................................................................................................................7
Suppressing Output ......................................................................................................................7
Built-in functions..........................................................................................................................7
Vectors .........................................................................................................................................8
Keeping a record ........................................................................................................................11
Experiment # 2 .............................................................................................................................12
Plotting elementary functions.....................................................................................................12
Product, division and power of vectors.......................................................................................16
Matrices- 2D arrays.....................................................................................................................18
Experiment # 3 .............................................................................................................................25
Logical Operations ......................................................................................................................25
Loops...........................................................................................................................................27
M-files & Functions ....................................................................................................................29
Complex Numbers ......................................................................................................................30
Experiment # 4 .............................................................................................................................32
Generation of some basic signals ...............................................................................................32
Plotting of Signals .....................................................................................................................32
Signal Operations ........................................................................................................................35
Experiment # 5 .............................................................................................................................39
Combined Signals Operations ....................................................................................................39
Experiment # 6 .............................................................................................................................42
Trigonometric Fourier Series ......................................................................................................42
Experiment # 7 .............................................................................................................................45
Exponential Fourier Series ..........................................................................................................45
2
Experiment # 8 .............................................................................................................................47
Symbolic Expression ..................................................................................................................47
Integration in MATLAB ............................................................................................................47
Fourier Transform ......................................................................................................................48
Inverse Fourier Transform .........................................................................................................52
Laplace Transform .....................................................................................................................52
Experiment # 9 .............................................................................................................................55
Synthesis of periodic signals .......................................................................................................55
Experiment # 10 ...........................................................................................................................59
Properties of Fourier Transform (PART I) ................................................................................59
Linearity .............................................................................................................................59
Time Shifting .....................................................................................................................61
Frequency Shifting .............................................................................................................61
Experiment # 11 ...........................................................................................................................64
Properties of Fourier Transform (PART II) ...............................................................................64
Time Scaling ......................................................................................................................64
Duality................................................................................................................................66
Time differentiation ...........................................................................................................67
Experiment # 12 ...........................................................................................................................69
Even & odd components of a signal ..........................................................................................69
Convolution ................................................................................................................................70
EXPERIMENT # 1
OVERVIEW:
1.
2.
3.
4.
5.
6.
7.
8.
9.
Introduction to MATLAB
MATLAB as Calculator
Number and Formats
Variables
General Info
Suppressing output.
Built-In functions
Vectors
Keeping a record
4. Variables
>> 3-2^4
Write you answer here;
>> ans*5
Write your answer here;
The result of the first calculation is labeled ans by Matlab and is used in the second calculation
where its value is changed. We can use our own names to store numbers:
>> x =3-2^4
x = -13
>> y =x*5
y = -65
So that x has the value -13 and y = -65. These can be used in subsequent calculations. These are
examples of assignment statements: values are assigned to variables. Each variable must be
assigned a value before it may be used on the right of an assignment statement.
4.1 Variable Names
Legal names consist of any combination of letters and digits, starting with a letter.
These are allowable:
NetCost, Left2Pay, x3, X3, z25c5
These are not allowable:
Net-Cost, 2pay, %x, @sign
Use names that reflect the values they represent.
Special names: you should avoid using eps =2.2204e-16 (The largest number such that 1 + eps
is indistinguishable from 1) and pi =3.14159... = .
6
If you wish to do arithmetic with complex numbers, both i and j have the value -1 unless you
change them
>> i, j
>> i=3
>>i=j
5. General Information
Matlab is case sensitive so a and A are two different names. Comment statements are
preceded by a %.
6. Suppressing output
We often dont want to see the result of intermediate calculations---terminate assignment
statement or expression with semicolon (;)
>> x=-13; y =5*x, z =x^2+y
y =-65
z =104
The value of x is hidden. Note also we can place several statements on one line, separated by
commas or semicolons.
7. BuiltIn Functions
7.1 Trigonometric Functions
Those known to Matlab are sin, cos, tan and their arguments should be in radians. E.g. to work
out the coordinates of a point on a circle of radius 5 centered at the origin and having an
elevation 30o = /6 radians:
>> x =5*cos(pi/6), y = 5*sin(pi/6)
The inverse trig functions are called asin, acos, atan (as opposed to the usual arcsin or sin-1 etc.)
The result is in radians.
>> acos(x/5), asin(y/5)
>> pi/6
cosd is cosine of argument in degrees. Y = cosd(X) is the cosine of the elements of X, expressed
in degrees. For odd integers n, cosd(n*90) is exactly zero, whereas cos(n*pi/2) reflects the
accuracy of the floating point value of pi.
>> cosd(90)
>> cos(pi/2)
>> 5*cosd(30)
Notice the last command sorted the elements of cd into ascending order. We can also change or
look at the value of particular entries
>> w(2) =-2, w(3)
w =1 -2 3
ans =3
8.1 The Colon Notation
This is a shortcut for producing row vectors:
>> 1:4
ans =1 2 3 4
>> 3:7
ans =3 4 5 6 7
>> 1:-1
ans =[ ]
More generally a:b:c produces a vector of entries starting with the value a, incrementing by the
value b until it gets to c (it will not produce a value beyond c). This is why 1:-1 produced the
empty vector [ ].
>> 0.32:0.1:0.6
>> -1.4:-0.3:-2
8.2 Extracting Bits of a Vector
>> r5 =[1:2:6, -1:-2:-7]
r5 =1 3 5 -1 -3 -5 -7
To get the 3rd to 6th entries:
>> r5(3:6)
ans =5 -1 -3 -5
>> t =w + 2*c
t =3.0000 4.0000 7.4721
>> T =5*w-2*c
>> x.
ans =
1.0000 + 3.0000i
2.0000 - 2.0000i
9 Keeping a record
Issuing the command
>>diary mysession
will cause all subsequent text that appears on the screen to be saved to the file mysession located
in the directory in which Matlab was invoked. You may use any legal filename except the names
on and off. The record may be terminated by
>>diary off
If you wish to quit Matlab midway through a calculation so as to continue at a later stage:
>> save thissession
will save the current values of all variables to a file called thissession.mat. This file cannot be
edited. When you next startup Matlab, type
>> load thissession
and the computation can be resumed where you left off.
A list of variables used in the current session may be seen with
>> who
See help who, help whos and help save.
>> whos
Exercise 1.1
Find the absolute value and phase of y = 2 cos(exp(1-4j))
Exercise 1.2
If
Exercise 1.3
If v= [2+ 3 4], v1= [2 +3 4]
v+v1 =?
11
EXPERIMENT # 2
OVERVIEW:
1. Plotting elementary functions
2. Product, division and power of vectors
3. Matrices- 2D arrays
1. Plotting Elementary Functions
Suppose we wish to plot a graph of y = sin3x for 0 x 1. We do this by sampling the
function at a sufficiently large number of points and then joining up the points (x, y) by straight
lines. Suppose we take N+1 points equally spaced a distance h apart:
>> N =10; h =1/N; x =0:h:1;
defines the set of points x = 0, h, 2h, . . ., 9h, 1.The corresponding y values are computed by
>> y =sin(3*pi*x);
and finally, we can plot the points with
>> plot(x,y)
The result is shown in Figure 1, where it is clear that the value of N is too small.
12
13
1.4 Multiplots
Several graphs can be drawn on the same figure as:
>> plot(x,y,w-,x,cos(2*pi*x),g--)
A descriptive legend may be included with
>> legend(Sin curve,Cos curve)
which will give a list of linestyles, as they appeared in the plot command, followed by a brief
description.
Matlab fits the legend in a suitable position, so as not to conceal the graphs whenever possible.
For further information do help plot etc.
The result of the commands
>> plot(x,y,w-,x,cos(2*pi*x),g--)
>> legend(Sin curve,Cos curve)
>> title(Multi-plot )
>> xlabel(x axis), ylabel(y axis)
>>grid
1.5 Hold
A call to plot clears the graphics window before plotting the current graph. This is not
convenient if we wish to add further graphics to the figure at some later stage. To stop the
window being cleared:
>> plot(x,y,w-), hold
>> plot(x,y,gx), hold off
hold on holds the current picture; hold off releases it (but does not clear the window, which
can be done with clf). hold on its own toggles the hold state.
1.6 Subplot
The graphics window may be split into an m n array of smaller windows into which
we may plot one or more graphs. The windows are counted 1to mn rowwise, starting from the
top left. Both hold and grid work on the current subplot.
14
1.7 Zooming
We often need to zoom in on some portion of a plot in order to see more detail. This is
easily achieved using the command
>> zoom
Left-Click on plot = Zoom in
Right-Click on plot = Zoom out
Selecting a specific portion of the plot using the mouse will zoom in to the selected portion of the
plot.
1.8 Controlling Axes
Once a plot has been created in the graphics window you may wish to change the
range of x and y values shown on the picture.
>> clf, N =100; h =1/N; x =0:h:1;
>> y =sin(3*pi*x); plot(x,y)
>> axis([-0.5 1.5 -1.2 1.2]), grid
The axis command has four parameters, the first two are the minimum and maximum values of x
to use on the axis and the last two are the minimum and maximum values of y.
Note the square brackets. The result of these commands is shown in Figure 4. For more info,
check out help axis.
15
>> u*u
% u is a row vector
>> v*z
The result is a vector of the same length and type as u and v. Thus, we simply multiply the
corresponding elements of two vectors. In Matlab, the product is computed with the operator .*
and, using the vectors u, v, w, z defined previously,
>> u.*w
>> u.*v
>> v.*z, u.*v
Example 2.1 Tabulate the function y = x sinx for x = 0, 0.25, . . ., 1.
It is easier to deal with column vectors so we first define a vector of x-values: (see Transposing)
>> x =(0:0.25:1);
To evaluate y we have to multiply each element of the vector x by the corresponding element of
the vector sin x:
x sin x = x sin x
00=0
0.2500 0.7071 = 0.1768
0.5000 1.0000 = 0.5000
0.7500 0.7071 = 0.5303
1.0000 0.0000 = 0.0000
To carry this out in Matlab:
>> y =x.*sin(pi*x)
Note: a) the use of pi, b) x and sin(pi*x) are both column vectors (the sin function is applied to
each element of the vector). Thus, the dot product of these is also a column vector.
17
The previous calculation required division by 0 --- notice the Inf, denoting infinity, in the
answer.
>> a.*b -24, ans./c
The second command illustrates how we can construct a matrix based on the size of an existing
one. Try ones(size(D))
19
An nn matrix that has the same number of rows and columns is called a square matrix.
A matrix is said to be symmetric if it is equal to its transpose (i.e. it is unchanged by
transposition):
>> S =[2 -1 0; -1 2 -1; 0 -1 2],
>> St =S
>> S-St
Notice that multiplying the 3 1 vector x by the 3 3 identity I has no effect (it is like
multiplying a number by 1).
3.5 Diagonal Matrices
A diagonal matrix is similar to the identity matrix except that its diagonal entries are not
necessarily equal to 1.
D=
300
040
002
is a 3 3 diagonal matrix. To construct this in Matlab, we could either type it in directly
>> D = [-3 0 0; 0 4 0; 0 0 2]
But this becomes impractical when the dimension is large (e.g. a 100 100 diagonal matrix). We
then use the diag function. We first define a vector d, say, containing the values of the diagonal
entries (in order) then diag(d) gives the required matrix.
>> d =[-3 4 2], D =diag(d)
20
On the other hand, if A is any matrix, the command diag(A) extracts its diagonal entries:
>> F = [0 1 8 7; 3 -2 -4 2; 4 2 1 1]
>> diag(F)
>> A, B, H =[A; B]
so we have added an extra column (x) to C in order to form G and have stacked A and B on top
of each other to form H.
>> J =[1:4; 5:8; 9:12; 20 0 5 4]
The command spy(K) will produce a graphical display of the location of the nonzero entries in K
(it will also give a value for nzthe number of nonzero entries):
>> spy(K), grid
>> J(2,3)
>> J(4,3)
>> J(4,5)
>> J(4,1) =J(1,1) + 6
>> J(1,1) =J(1,1) - 3*J(1,2)
Thus, : on its own refers to the entire column or row depending on whether it is the first or the
second index.
3.8 Dot product of matrices (.*)
The dot product works as for vectors: corresponding elements are multiplied togetherso the
matrices involved must have the same size.
>> A, B
A=
579
1 -3 -7
B=
-1 2 5
905
22
>> A.*B
>> A.*C
>> A.*C
>> D =B*A
>> E =B*A
23
3. Draw graphs of the functions for x =0:0.1:10 and label your graph properly.
i.
y = sin(x)/x
ii.
u = (1/(x-1)2)+x
iii.
v = (x2+1)/(x2-4)
iv.
z = ((10-x)1/3-1)/(4 - x2)1/2
24
EXPERIMENT # 3
OVERVIEW:
1.
2.
3.
4.
Logical Operations
Loops
M-Files
Complex Numbers
1.
LOGICAL OPERATIONS
25
As one might expect, & represents and, the vertical bar | means or; also ~ means not as in ~=
(not equal).
>> x > 3 | x ==-3 | x <=-5
One of the uses of logical tests is to mask out certain elements of a matrix.
>> x, L =x >= 0
>> pos =x.*L
So the matrix pos contains just those elements of x that are nonnegative.
>> x =0:0.05:6; y =sin(pi*x); Y =(y>= 0).*y;
>> plot(x,y,:,x,Y,- )
26
2.
LOOPS
There are occasions that we want to repeat a segment of code a number of different times (such
occasions are less frequent than other programming languages because of the : notation).
2.1 For Loops
Example 2.1.1 Draw graphs of sin(nx) on the interval
-1 x 1 for n = 1, 2, . . ., 8.
We could do this by giving 8 separate plot commands but it is much easier to use a loop. The
simplest form would be
>> x =-1:.05:1;
>> for n =1:8
subplot(4,2,n), plot(x,sin(n*pi*x))
end
All the commands between the lines starting for and end are repeated with n being given the
value 1 the first time through, 2 the second time, and so forth, until n = 8. The subplot constructs
a 4 2 array of sub-windows and, on the nth time through the loop, a picture is drawn in the nth
sub-window.
The commands
>> x =-1:.05:1;
>> for n =1:2:8
subplot(4,2,n), plot(x,sin(n*pi*x))
subplot(4,2,n+1), plot(x,cos(n*pi*x))
end
Draw sin nx and cos nx for n = 1, 3, 5, 7 alongside each other. We may use any legal variable
name as the loop counter (n in the above examples) and it can be made to run through all of the
values in a given vector (1:8 and 1:2:8 in the examples).
(Keep in mind that using a for loop in Matlab is very much discouraged because they are
computationally inefficient.)
Example 2.1.2 The Fibonnaci sequence starts off with the numbers 0 and 1, then succeeding
terms are the sum of its two immediate predecessors.
Mathematically,
f1 = 0, f2 = 1
and
fn = fn-1 + fn-2, n= 3, 4, 5, . . ..
27
Test the assertion that the ratio fn/fn-1 of two successive values approaches the golden ratio
which is = (5 + 1)/2 = 1.6180.
There are a total of 81 sums. The first can be computed using sum (1./(1:20).^2). A suitable
piece of Matlab code might be
>> S =zeros(100,1);
>> S(20) =sum(1./(1:20).^2);
>> for n =21:100
>> S(n) =S(n-1) + 1/n^2;
>> end
>> [ (98:100) S(98:100)]
Where a column vector S was created to hold the answers. The first sum was computed directly
using the sum command then each succeeding sum was found by adding 1/n2 to its predecessor.
The little table at the end shows the values of the last three sums.
2.2 While Loops
There are some occasions when we want to repeat a section of Matlab code until some
logical condition is satisfied, but we cannot tell in advance how many times we have to go
around the loop. This we can do with a while...end construct. The general form of a while
statement is:
28
Example 2.2.1 What is the greatest value of n that can be used in the sum
and get a value of less than 100?
>> S =1; n = 1;
>> while S+ (n+1)^2 < 100
n =n+1; S = S + n^2;
end
>> [n, S]
The lines of code between while and end will only be executed if the condition S+ (n+1)^2 <
100 is true.
3. M-FILES
M-files are macros of Matlab command that are stored as ordinary text files with the
extension m, that is filename.m. An M-file can be either a function with input and output
variables or a list of commands (Script File).
For example, consider using Matlab on a PC with a user-defined M-file stored in a directory
called \Matlab6p5\work. Then to access that M-file, either change the working directory by
typing cd \matlab6p5\work from within the Matlab command window or by adding the
directory to path which can be accomplished using the command addpath c:\matlab\work from
within Matlab.
As example of an M-file(FileNewM-File) that defines a function, create a file in your
working directory named yplusx.m that contains the following commands:
function z = yplusx(y,x)
z=y+x;
The following commands typed from within Matlab command window demonstrate how this Mfile is used:
x=2;
y=3;
z=yplusx(y,x);
or simply,
z=yplusx(3,2);
29
Matlab M-files are most efficient when written in a way that utilizes matrix or vector operations.
Loops are available but should be used sparingly since they are computationally inefficient. An
example of the use of the command for is:
for k=1:10
x(k)=cos(k);
end
This creates a 1x10 vector x containing the cosine of the positive integers from 1 to 10. This
operation is performed more efficiently with the commands
k=1:10;
x=cos(k);
which utilizes a function of a vector instead of a for loop.
An if statement can be used to define conditional statements. An example is
if(a<=2)
b=1;
elseif(a>=4)
b=2;
else
b=3;
end
4. COMPLEX NUMBERS
4.1 Operations on Complex Numbers
Plots in MATLAB are generated using the plot function. Since the complex values have two
components corresponding to
A + jB
MATLAB provides the real and imag functions to separate the real and imaginary parts of an
imaginary number.
>>z=3+4j;
>>zr=real(z)
>>zi=imag(z)
zr and zi here will be the real and imaginary value of the complex number z. To plot these
values use the following command:
>>plot(zr,zi,x)
30
>>t=0:0.005:1
>>f=3*exp(j*3*pi*t)
>>plot(t,f)
Exercise 4.2.1
Repeat Example 2.2.1 to include 181 sums (i.e. the final sum should include the term 1/2002.)
31
EXPERIMENT # 4
OVERVIEW:
1.
2.
2.1.
2.2.
2.3.
2.4.
3.
3.1.
3.2.
3.3.
3.4.
1. GENERATION OF SOME BASIC SIGNALS
Unit Step Function
%%%%%%%%% cfstep.m %%%%%%%%%
function u = cfstep(t,to)
inc=0.01;
n=-t:inc:t;
u=[zeros(1,(t+to)/inc) 1 ones(1,(t-to)/inc)];
plot(n,u);
>>cfstep(5,0)
Will generate a unit step function starting at t=0 ranging from
SINUSOIDAL SIGNAL
Where
A = amplitude of sinusoid
32
Example:
Suppose A=1, f=1Hz, t=0:0.01:1:
y(t)=cos(2t)
y(t)=cos(2t+/2)
y(t)=cos(2t-/2)
y(t)=sin(2t)
2.2.
PIECEWISE SIGNALS
(i)
(ii)
Define a piecewise
continuous function x(t)
x(t) =
(iii)
33
(iv)
2.3.
2.4.
34
3.
SIGNAL OPERATIONS
3.1. TIME SHIFTING
Exercise 3.1.2:
35
Exercise 3.1.3:
Shift the piecewise signal shown in the fig below, 2 units to the right
Similarly,
If
,
Find:
is given by
for t = -0.5:0.01:0.5;
36
Assignment
Write MATLAB code to plot the signals in the given problems. Scale your time axis so that a
sufficient amount of the signal is being plotted. Use subplot to give two plots per page (fig
window); label your plots with Time(sec) on the x-axis. The y-axis should be labeled x(t); the
title should be the problem number , for example 1_a)
37
Exercise
a) Sketch the signal defined below in MATLAB:
38
EXPERIMENT # 5
OVERVIEW:
1.
1.1.
1.2.
1.3.
1.4.
1.
SHIFTING + SCALING
can be achieved by the following two procedures:
i. Time shift
by b to obtain
. Now scale the shifted signal
by a (i.e. replace t with at) to obtain
ii. Time-scale
by a to obtain
. Now time-shift
by b/a (i.e.
replace t by t-b/a) to obtain:
Similarly
i. Time shift
by b to obtain
. Now scale the shifted signal
by a (i.e. replace t with t/a) to obtain
ii.
Time-scale
by a to obtain
replace t by t-ab) to obtain:
For
2.
. Now time-shift
by ab (i.e.
INVERSION + SCALING
Combined operations of inversion and scaling,
and
, can be achieved
by either first time scaling the function by a and then performing time inversion (i.e.
replace t by -t) or by first time inverting the signal and then time scaling by a.
39
3.
, plot
SHIFTING + INVERSION
can be achieved by the following two procedures:
i. Time invert
to obtain
to obtain
by a to obtain
ii. Shift
resulting signal to obtain
4.
To understand the overall effect, it is usually best to break this transformation down
into successive simple transformations,
Observe here that the order of transformations is important. If we change the order of
time-scaling and time-shifting operations, we get
The result of this sequence of transformations is different from the preceding result.
Similarly you should note the order of individual transformations for this combined
transformation,
40
For
Assignment
Write MATLAB code to plot the signals in the given problems.
1.
41
EXPERIMENT # 6
Find the Trigonometric Fourier series coefficients and plot the magnitude and phase
spectra for the periodic signals shown below in MATLAB:
Q.1
Fourier series coefficients for the periodic signal shown above are:
42
The code for plotting the magnitude and phase spectra for the given co-efficients is given
below using for loop:
n=1:7;
a0=0.504;
b0=0.504*(8*0/(1+16*0^2));
% b0=0;
Cn=a0;
theta0=atan(-b0/a0);
thetan=theta0;
den=(1+16*n.^2);
N=length(den);
for i=1:N
an(i)=0.504*2/den(i);
bn(i)=0.504*8*n(i)/den(i);
cn=sqrt(an(i)^2+bn(i)^2);
Cn=[Cn cn];
theta=atan(-bn(i)/an(i));
thetan=[thetan theta];
end
n=0:7;
subplot(211),plot(n, ,'o'),grid,
xlabel('n'),ylabel(
),title(
)
subplot(212),plot(n,thetan,'o'),grid,xlabel('n'),ylabel('\theta_
n (rad)')
Q2. If
is as defined below:
=
Find the trigonometric Fourier series coefficients for the periodic signal shown below and use
them to plot the magnitude and phase spectra.
43
Q3. Find the trigonometric Fourier series coefficients for the periodic signal shown below and
use them to plot the magnitude and phase spectra.
ASSIGNMENT:
For the periodic signal given below, find the trigonometric Fourier series coefficients and plot
the amplitude and phase spectra (in degrees).
44
EXPERIMENT # 7
EXPONENTIAL FOURIER SERIES
Q.1 Write Matlab code to plot the exponential Fourier spectra of given exponential coefficients
for
Q.2 Write Matlab code to plot the exponential Fourier spectra of given exponential coefficients
for
45
Q.3 Write Matlab code to plot the exponential Fourier spectra of given signal for
.
46
EXPERIMENT # 8
OVERVIEW:
1.
2.
3.
4.
5.
Symbolic expression
Integration in MATLAB
Fourier Transform
Inverse Fourier Transform
Laplace Transform
SYMBOLIC EXPRESSION:
The sym function can be used to create 'symbolic objects' in MATLAB. For example,
typing >>x=sym('x') creates the symbolic variable with name x.
The syms function enables you to combine more than one such statement into a single
statement. For example, typing syms x is equivalent to typing x=sym('x'), and typing syms x y u v
creates the four variables x, y, u and v.
You can use sym function to create symbolic constants by single numerical value for the
argument. For example, typing pi=sym('pi'), fraction=sym('1/3') and sqroot2=sym('sqrt(2)')
create symbolic constants that avoid the floating point approximations inherent in the values of
pi, 1/3 and sqrt(2). If you create a symbolic constant pi this way, it temporarily replaces the
built-in numeric constant, and you no longer obtain a numeric value when you type its name.
The advantage of using symbolic constants is that they need not be evaluated (with the
accompanying round-off error) until a numeric answer is required.
INTEGRATION IN MATLAB
47
int(S)
int(S,a,b)
int(S) returns the indefinite integral of S with respect to its symbolic variable.
int(S,a,b) returns the definite integral from a to b of each element of S with respect to each
element's default symbolic variable. a and b are symbolic or double scalars.
Write following code in MATLAB and write your results in space provided
>> syms x t n
>> int(x)
>> int(cos(x))
>> int(sin(x))
>> int(exp(-2*x))
>> int(exp(-2*j*x))
>> int(t*exp(-t))
>> int(cos(x),0,2*pi)
>> int(sin(x),0,2*pi)
>>int(exp(-t/2)*cos(n*t),0,pi)
>> a0=int(exp(-t/2),0,pi)
48
F = fourier(f) is the Fourier transform of the symbolic scalar f with default independent variable
x. The default return is a function of w. The Fourier transform is applied to a function of x and
returns a function of w.
Write following code in MATLAB
syms t;
fourier(cos(t))
Write your result in space provided below and also explain what is dirac() function in
MATLAB.
Find the Fourier transform of (t) in MATLAB. Write your code and answer provided by
MATALB in the space below:
Unit step Function is defined as heaviside(t) in MATLAB. Find Fourier transform of u(t) in
MATLAB and write your code and result provided by MATALB in the space below:
t
Define rect( ) in MATLAB as sum of shifted heaviside() functions. Find its Fourier
4
transform. Write your code and answer given by MATLAB in the space below:
Define e-2tu(t) in MATLAB. Find its Fourier transform and write your code and answer
given by MATLAB in the space below:
49
fourier() function takes in a symbolic variable and cannot plot the function as long as its
variable is a symbol. So after you have derived Fourier transform of a function, define t for
some fixed value e.g. t=[-10:0.01:10] and w=[-3:0.1:3], and rewrite the equations to plot the
graphs.
Example
syms t
x=heaviside(t+2)-heaviside(t-2);
f=fourier(x)
t=[-10:0.01:10];
w=[-3*pi:.1:3*pi];
x=heaviside(t+2)-heaviside(t-2);
f=2./w.*sin(2.*w);
subplot(3,1,1)
plot(t,x)
subplot(3,1,2)
plot(w,abs(f))
subplot(3,1,3)
plot(w,angle(f))
The final graph should look like this:
50
But when you plot the absolute value of the transform, then it takes all the positive values in
place of negative values and gives a phase of pi in the phase graph.
51
LAPLACE TRANSFORM
Like the Fourier transform, Laplace transform is used for solving differential and integral
equations. The Laplace transform is often interpreted as a transformation from the time-domain,
in which inputs and outputs are functions of time, to the frequency-domain. The Laplace
transform of a function f(t), defined for all real numbers t 0, is the function F(s), defined by:
52
L = laplace(f) is the Laplace transform of the scalar symbol f with default independent variable t.
The default return is a function of s. The Laplace transform is applied to a function of t and
returns a function of s.
Write laplace(cos(t)) in MATLAB and give the answer provided by MATLAB in the space
below.
Find the Laplace transform of (t) in MATLAB. Write your code and answer provided by
MATALB in the space below:
53
Find Laplace transform of u(t) in MATLAB and write your code and result provided by
MATALB in the space below:
Find Laplace transform of e-2t u(t) in MATLAB. Write your code and answer given by
MATLAB in the space provided below:
54
EXPERIMENT # 9
OVERVIEW:
Synthesis of periodic signals
EXERCISE 1:
The trigonometric Fourier series expression for periodic signal x(t) shown above is:
1
2
+
sin (2nt)
x(t) =
2 n =0 n
Write the code given in MATLAB and run it for different inputs e.g. plotfo(5,12,120,700),
plotfo(5,10,20,50) etc.
Carefully read the code and describe what the code is doing in the space below:
After observing the graphs for various values of n, note that as you increase the value of n,
the response gets closer to the square wave but at the points of discontinuity, there is a persistent
overshoot of about 9% of the value of signal at the point of discontinuity. This constant
overshoot at points of discontinuity is called Gibbs Phenomenon.
55
plotfo(5,12,120,700)
plotfo(5,10,20,50)
56
function plotfo(n1,n2,n3,n4)
figure
t=[-2:0.0001:2];
n=1;
y = 0.5+(2/pi)* (1/n)*sin(n*2*pi*t);
x1=0;
x2=0;
x3=0;
x4=0;
for n = 3:2:n1
x1 = x1 + (2/pi)*(1/n)*sin(n*2*pi*t);
end
x1=x1+y;
subplot(2,2,1)
plot(t,x1)
for n = 3:2:n2
x2 = x2 + (2/pi)*(1/n)*sin(n*2*pi*t);
end
x2=x2+y;
subplot(2,2,2)
plot(t,x2)
for n = 3:2:n3
x3 = x3 + (2/pi)*(1/n)*sin(n*2*pi*t);
end
x3=x3+y;
subplot(2,2,3)
plot(t,x3)
for n = 3:2:n4
x4 = x4 + (2/pi)*(1/n)*sin(n*2*pi*t);
end
x4=x4+y;
subplot(2,2,4)
plot(t,x4)
57
EXERCISE 2:
The trigonometric Fourier series expression for periodic signal x(t) shown above is:
n
1
x(t) = 2 sin(
) sin(nt)
2
n =0 n
Write code in MATLAB to synthesize the above signal, and run it for different inputs e.g.
plottrian(5,12,120,700), plottrian(5,10,20,50) etc.
58
EXPERIMENT # 10
PROPERTIES OF FOURIER TRANSFORM (PART I)
LINEARITY:
The Fourier transform is linear; that is, if
and
then
t
Define x1(t)=rect( ) as sum of shifted heaviside() functions and x2(t)= e-2tu(t) in MATLAB.
4
Apply linearity property on these two signals. Suppose
After you have derived Fourier transform of functions, definet for some fixed value e.g. t=[5:0.01:5] and w=[-2:0.1:2], and rewrite the equations to plot the graphs.
syms t
x1=heaviside(t+2)-heaviside(t-2);
x2=exp(-t*2)*heaviside(t);
x=2*x1+3*x2;
X1 =fourier(x1);
X2 =fourier(x2);
X =fourier(x);
t=[-5:0.01:5];
w=[-2*pi:.1:2*pi];
x1=heaviside(t+2)-heaviside(t-2);
x2=exp(-t*2).*heaviside(t);
x=2*x1+3*x2;
X1 =2./w.*sin(2*w);
X2 =1./(2+i*w);
X =4./w.*sin(2*w)+3./(2+i*w);
subplot(311),plot(t,x,'linewidth',2),grid,title('plot of x(t)=2*x_1 (t)+
3*x_2 (t)'subplot(312),plot(w,(2*X1+3*X2),'linewidth',2),grid,title('plot of
2*X_1 (w)+ 3*X_2 (w)'
subplot(313),plot(w,(X),'linewidth',2),grid,title('plot of X(w)')
59
Also, write MATLAB code to compare the magnitude and phase spectra of the right side of the
equation i.e.
to the Fourier transform of the left side i.e.
.
The output should be as follows:
60
SHIFTING PROPERTIES:
TIME SHIFTING
The above equation shows that delaying a signal by to seconds does not change its amplitude
spectrum. The phase spectrum, however, is changed by wto.
Prove the time shifting property for given x(t)
FREQUENCY SHIFTING
Figure 2
62
Figure 3
x(t) e(j2t)
1
0
-1
-6
-2
-4
|F(x(t) e(j2t))|
4
2
0
-4
-3
-2
-1
-3
-2
-1
63
EXPERIMENT # 11
PROPERTIES OF FOURIER TRANSFORM (Part-II)
THE SCALING PROPERTY:
The function
represents the function
compressed by factor a. Similarly, a function
represents the function X(w) expanded in frequency by same factor a. The scaling
property states that time compression of a signal results in its spectral expansion, and time
expansion of the signal results in its spectral compression.
TIME SCALING
64
Figure 2
Figure 3
65
DUALITIY:
66
b)
Output of your code should be as follows:
X(w)
x(t)
0.8
0.6
0.4
0.5
0.2
0
-5
0
-10
-5
10
X2(W)
x 2(t)=1/(2+j*t)
0.8
6
0.6
4
0.4
0.2
0
-10
-5
10
-5
TIME DIFFERRNTIATION
67
68
EXPERIMENT # 12
Overview
1. Even & Odd Components of a Signal
2. CONVOLUTION
EVEN & ODD Components of a Signal
EXAMPLE 1
a) Define the signal x(t) shown below in MATLAB.
Note: Since we require to flip the function in time domain and then add the two functions, so the
time duration defined for x(t) should span the complete duration required to plot x(t) and x(-t).
For example, in this case x(t) is non zero for 0 t 2 and so x(-t) will be non zero for -2 t 0.
So the time duration you define in MATLAB should at least be -2 t 2 as shown below to
properly execute the rest of operations.
EXAMPLE 2
Perform the same steps of determining and plotting even and odd components of a function as
done before for the signal f (t) shown below:
Observe that the given function g(t) is an odd function so its even component should be equal to
zero.
Write your complete code in the space provided below:
70
2.
3.
4.
Use conv() function in MATLAB to convolve the two functions defined above.
Plot x(t), h(t) and convolution result y(t) in MATLAB on a single figure.
Note that the result of convolution spans from (Tx1+Th1) t (Tx2+Th2), so plot the
graph of y (t) against this time.
5.
Your final result should look like the figure below:
EXERCISE 1 :
For the two functions x(t) and h(t) shown below
1. Define the functions x(t) and h(t) in MATLAB.
2. Use conv() function in MATLAB to convolve x(t) and h(t).
3. Plot x, h and y on a single figure window using subplot() function.
71
EXERCISE 2:
For the two functions x(t) and h(t) shown below
1. Define the functions x(t) and h(t) in MATLAB.
2. Use conv() function in MATLAB to convolve x(t) and h(t).
3. Plot x, h and y on a single figure window using subplot() function.
72