LAB 1 (Signal Analysis Using MATLAB)
LAB 1 (Signal Analysis Using MATLAB)
1) Introduction
A user can access help either from the command line or by clicking on the graphical
“Help” menu.
On the command line, the format for obtaining help on a particular MATLAB
function is to type “help” followed by the name of the function.
Example: To learn more about the plot function, type the following instruction in the
MATLAB command window:
If the name of the function is not known beforehand, you can use the “lookfor”
command followed by a keyword that identifies the function being searched, to enlist
the available MATLAB functions with the specified keyword.
Example: All MATLAB functions with the keyword “Fourier” can be listed by typing
the following command:
3) M-files in MATLAB
M-files are macros of MATLAB commands that are stored as ordinary text files with
the extension “.m” and can be executed over and over again. An M-file can be either
a function with input and output variables or a list of commands. MATLAB requires
that the M-file be stored either in the working directory or in a directory that is
specified in the MATLAB path list.
Note: MATLAB M-files are most efficient when written in a way that utilizes
matrix or vector operations. Loops and “if” statements should not be used,
because they are computationally inefficient.
Example: Variable (a) can be assigned the value (6 + j8) by typing the following
command:
a = 6 + 8j;
Example: Vector (d) containing the values 1 through 9 can be entered by typing the
following command:
d = [1 2 3 4 5 6 7 8 9];
g = 0:2:10;
A = [1 2 3; 4 5 6; 7 8 9];
5) Control Statements
MATLAB supports several loop statement (for, while, switch, etc.) as well as the if-
else statement. Functionally, these statements are similar to their counterparts in C but
the syntax is slightly different.
a) Write down the equivalent MATLAB code for the above instructions using
“for” loop and print the output.
b) Write down the equivalent MATLAB code for the above instructions using
“while” loop and print the output.
c) Write down a MATLAB code without using loops by performing a direct sum
of matrices X and Y and print the output.
int a = 15;
int x;
if (a > 0)
{
x = 5;
}
else
{
x = 100;
}
a) Write down the equivalent MATLAB code and print the output.
"
!" #$%&'($%)*$+,-.'/$%)012,32)14,#56758,
"
A) Consider the following function:
Write down MATLAB code and print the result for the following operations:
! !
!!
! !
! !
!!
! !!
Write down MATLAB code and print the result for the following operations:
! ! !!! !! !!! ! ! !! !
! ! !!!! !! ! !!!! !! !!
a) Addition r1 = f + g
b) Dot product r2 = f g .
! !
c) Mean r3 =
! !!! !!!!
! ! !
d) Average energy r4 = ! !!! !!!!
A) Generate and plot the following Continuous Time (CT) signals, using MATLAB.
Do not use any loops in your code. The horizontal axis should extend only for
the range over which the signal is defined. Label your figures with the appropriate
title, x-axis units, and y-axis units.
B) Generate and plot the following Discrete Time (DT) signals, using MATLAB. Do
not use any loops in your code. The horizontal axis should extend only for the
range over which the signal is defined. Label your figure with the appropriate
title, x-axis units, and y-axis units. (Note: K can only be an integer value)
!!
! ! ! !!!!"!!"#! !!!!" ! !!!!!!!!!!!!!"# ! !" ! ! ! !"
!
!"#
! ! ! !!!!!"!! ! !"# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"#!! ! ! ! !"
A) Compute the graphical solution for the following differential equation using
MATLAB and the “ode23” function found in MATLAB. Label your figure with
the appropriate title, x-axis units, and y-axis units.
!"
! !! ! ! !!"#!!!!!
!"
Frequency = 1 Hz
Amplitude = 5 Volts
DC-bias = -3 Volts
Time Interval = -3 ! t ! 3 Seconds
Label your figure with the appropriate title, x-axis units, and y-axis units.
Now, write MATLAB code to approximate the square wave as a Fourier series
and plot it using m = 1, 5, 10, and 20.
!
!!
! ! !! ! !! !"#!!!!!"#! ! !! !"#!!!!!"#!
!
!!!
!
!
!! ! ! !!!! !"#!!!!"#!!"
!
!
!
!
!! ! ! !!!! !"#!!!!"#!!"
!
!
Label your figure with the appropriate title, x-axis units, and y-axis units.
B) Write MATLAB code to generate and plot the following function in the time
interval -L ! t ! L seconds, where L = 5.
! ! ! !! ! ! !"! ! ! ! ! ! !"
Label your figure with the appropriate title, x-axis units, and y-axis units.
Now, write MATLAB code to approximate the above function as a Fourier series
and plot it using m = 1, 5, 10, and 20.
!
!! !"# !"#
! ! !! ! !! !"#! ! !! !"#!
! ! !
!!!
!
! !"#
!! ! ! !!!! !"# !"
! !
!!
!
! !"#
!! ! ! !!!! !"# !"
! !
!!
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
10) Fourier Transform and Inverse Fourier Transform using MATLAB
"
A) Write MATLAB code to generate and plot a Cosine wave g (t) having the
following characteristics:
Frequency = 5 Hz
Amplitude = 19 Volts
Time Interval = 0 ! t ! 3 Seconds
"
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
)* +,-./-0")"1/2-3,-"4-)56./-0"/5"78,")9/:,"63;5)<"2635;"78,"=/00)5>"
?114*")5>"@</7"78,"-,62<7"35"78,".-,A2,5=B">/0)35C"
"
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
9* E-37,"FG4HGI"=/>,"7/"@,-./-0")5"35:,-6,"1/2-3,-"4-)56./-0"/."78,"
63;5)<"/97)35,>"35"@)-7"?)*"2635;"78,"=/00)5>"?J114*")5>"@</7"78,"-,62<7"
35"78,"730,">/0)35C"
"
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
B) Write MATLAB code to generate and plot a Square wave g (t) having the
following characteristics:
Frequency = 5 Hz
Amplitude = 19 Volts
Time Interval = 0 ! t ! 3 Seconds
"
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
)* +,-./-0")"1/2-3,-"4-)56./-0"/5"78,")9/:,"63;5)<"2635;"78,"=/00)5>"
?114*")5>"@</7"78,"-,62<7"35"78,".-,A2,5=B">/0)35C"
"
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
9* E-37,"FG4HGI"=/>,"7/"@,-./-0")5"35:,-6,"1/2-3,-"4-)56./-0"/."78,"
63;5)<"/97)35,>"35"@)-7"?)*"2635;"78,"=/00)5>"?J114*")5>"@</7"78,"-,62<7"
35"78,"730,">/0)35C"
"
Label your figure with the appropriate title, x-axis units, and y-axis units.
"
"