Professional Documents
Culture Documents
Ayush Marasini LabReport Signals
Ayush Marasini LabReport Signals
Ayush Marasini LabReport Signals
School of Engineering
D EPARTMENT OF E LECTRICAL AND E LECTRONICS E NGINEERING
G ROUP :EE(C)
Y EAR : 2 ND YEAR
LAB 1: Understanding of MATLAB and signal processing in MATLAB
Objectives:
THEORY:
used for the technical computing and numeric computing. The commands in
MATLAB are executed line by line, as soon as a command is given the MATLAB
interpreter executes the statement. The variables used in MATLAB are either array
or matrix . There are predefined rules and syntax for declaration of variables. They
are:
There are user defined functions which is similar to variable, but that function does
the specific task as defined by the user when called. A user defined function in
MATLAB is saved as a function file, and can be used exactly like a built-in
function.
IF Condition Syntax:
if(condition)
Conditional command
end
Else condition Syntax:
if(conditon1)
Conditional command 1
else
Conditional command 2
end
if (condition 1)
Conditional Command 1
elseif (condition 2)
Conditional Command 2
else
Conditional Command 3
end
Loops are one of the most useful and important features of MATLAB. Using loops,
we can execute a block of code repeatedly. Generally, there are two types of loops
for x=1:100
commands
end
While loop syntax
while(condition)
Commands
end
Exercises:
Solution :
Output:
2. Y o u r l e a r n i n g t i m e c o n s t a n t o f M A T L A B i s 1 . 5 d a y s a n d t h e c l a s s l a s t s
−t . How well will you know MATLAB at end of the class? Using this
k =1−e τ
value display the phrase: At the end of 6.094, I will know X% of MATLAB.
Solution:
Output:
Solution:
Output:
4. C a l c u l a t e y o u r l e a r n i n g t r a j e c t o r y u s i n g t h e s a m
Solution:
Ouput:
Objective:
Theory:
The basic object used in MATLAB is a rectangular numerical matrix with possibly
c o m p l e x e l e m e n t s . G e n e r a t i o n o f s i g n a l s i n M A T L
However, for continuous time signals, only an approximation exists. To ensure that
t he a p pr ox im a t i on i s go od e no ug h t o re p re s e nt th e c on t i nu ou s t i m e s i gn a l , on ly a n
the continuous time signal, sampling interval must be chosen sufficiently small.
MATLAB. Hence, the length of sequence must be chosen such that the rang
t=0:0.001:1;
n=0:1000.
A * s a w t o o t h ( w 0 * t , W ) ; w h e r e A i s a m p l
frequency, W is width.
A*sin(w0*t+phi)
A*cos(w0*t+phi)
Ramp: ramp=n;
M-files:
MATLAB permits user to create their own subroutines called M-files. We can write
and add new functions using M-files. Function M-files begin wit
defining the function name, its input arguments, and its output arguments. M-files
Exercises:
1) U s e M A T L A B t o g e n e r a t e t
Solution:
Output:
2) Write MATLAB code to generate an exponentially decaying sinusoidal signal
(
x ( t )=20 sin 2 π∗1000 t−
3)
π −at . Show the plots for different values of a, such
e
as: 500, 750 and 1000. Consider t ranging from -2ms to 2ms in the interval of
1us.
Solution:
Output:
Output:
Solution:
Output:
5) A similar DT pulse x[n] is defined as:
{
x [n]= 10 , 0 ≤n ≤ 5
0 , otherwise
Write a user defined function M-file to generate and plot the pulse.
Solution:
Output:
LAB 3: Analysis of LTI Systems
Objective:
Theory:
i n p u t . T h i s i n v o l v e s e v a l u a t i o n o f c o n v o l u t i o n i n t
convolution sum for DT systems. It is well known that computers are digital device
and hence ideally suited for implementing DT systems. In contrast, CT systems can
that computers have finite memory and hence cannot store sequences of
l e n g t h . H o w e v e r , w e c a n s a t i s f a c t o r i l y a p p r o x i
convolution sum of two finite length sequences. If x and h are two sequences
y = conv(x,h);
o f h c o r r e s p o n d s t o t ihm
, et h ne =
n kt h e f i r s t e l e m e n t o f y c o r r e s p o n d s t o t i
n=k x +k h .
When input sequence and impulse response are of infinite duration, we can find the
output considering some particular conditions. For example, if input and imp
Imaginary and real part of any complex sequence can be obtained using bu
function as:
a=real(x); b=imag(x);
form:
N M
∑ ak y n−k=∑ bk xn −k
k=0 k=0
Solution of such difference equation with zero initial conditions can be obtained in
M A T L A B u s i n g t h e f uy n= cf it li ot en r ( b , aw, hxe)r;e a a n d b a r e t h e v e c t o r s
Exercises:
1) U s e M A T L A B t o f i n d t h e o u t p u t o f t h e s y s t e m w i t h i n p u t x [ n ] = 2 { u [ n + 2 ] -
Solution:
Output:
2) U s e M A T L A B c o d e s t o f i n d t h e c o n v o l u t i o n o f a n y t w o f i n i
sequences. Your program should take the following inputs: sequence x, lower
limit of x, upper limit of x, sequence y, lower limit y and upper limit of y.
Also show the results of program execution for the following case:
x = {1, 1, 0, 1, 1} and y = {-3, 4}
Solution:
Output:
3) Use MATLAB to find the first 20 values of step response for the system with
impulse response h[n] given as:
1 n
h [ n ] =( ) u [ n ]
2
Solution
Output:
4) Use MATLAB to find the first 20 values of step response for the system with
impulse response h[n] given as: h [ n ] =δ [ n ] −δ [n−1].
Solution:
Output:
5) Consider the moving average system:
{
1
h [ n ] = 2 , 0 ≤ n ≤5
0 , otherwise
Write MATLAB code to generate and plot 100 values of sinusoidal steady
state response at frequencies Ω=π/3.
Solution:
Output:
LAB 4: Transformation, Frequency response, Impulse response and Pole Zero plot
Objective:
To observe frequency response, impulse response and pole zero plot of any
Theory:
DTFS and DTFT are the Fourier representation that are discrete in both time an
frequency domain.
1
DTFS : ak = ∑
N n=¿ N >¿ x[ n] e
−jk Ωo n
¿
¿
N −1 − j 2 πkn
DFT : X [ k ] = ∑ x [n]e N
n=0
MATLAB uses commands fft and ifft to calculate both. The function fft dire
X=fft(x)/N;
N M
∑ ak y n−k=∑ bk xn −k
k=0 k=0
The poles and zeros of a system can be determined using the command roots. If the
coefficients are stored as vectors are b and a, command zplane can directly plot the
poles and zeros in z plane. Command impz finds the impulse response of the
system. Command freqz returns the frequency response of the digital system for the
provided system function
1) W r i t e a c o d e t o p l o t a s i n u s o i d a l s e q u e n c e o f s i n u s o i d a l s e q u e n c e o f p e r i o d
Solution:
Output:
2) Determine the DTFS coefficients of the following signal using fft command.
π 3π
x [ n ] =sin( n+ )
12 8
Solution:
Output:
Solution:
Output:
4) Write the MATLAB code to find the poles and zeros, show the pole-zero in z
plane, plot the magnitude and phase response of the system and finally the
impulse response. y[n] + 0.04860y[n-2] +0.0177y[n-4] = 0.094(x[n] + 4x[n-
Solution:
Output: