Ayush Marasini LabReport Signals

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

KATHMANDU UNIVERSITY

School of Engineering
D EPARTMENT OF E LECTRICAL AND E LECTRONICS E NGINEERING

L AB R EPORT EEEG 222

S UBMITTED B Y : A YUSH M ARASINI S UBMITTED T O : M ADHAV P RASAD P ANDEY

E XAM R OLL N UMBER :22014

G ROUP :EE(C)

Y EAR : 2 ND YEAR
LAB 1: Understanding of MATLAB and signal processing in MATLAB

Objectives:

 To understand the basics of MATLAB

 To understand the representation of signals in MATLAB

THEORY:

MATLAB is a programming language developed by MathWorks which in general is

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:

 Variable names should not be a keyboard.

 Variable name should always start with a letter.

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.

Conditional Statements(if,if-else,elseif)can be used in MATLAB ,they can be used

in defining the logics.

 IF Condition Syntax:

if(condition)

Conditional command

end
 Else condition Syntax:

if(conditon1)

Conditional command 1

else

Conditional command 2

end

 Else if condition Syntax:

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

which are described as follows

 for loop syntax:

for x=1:100

commands

end
 While loop syntax

while(condition)

Commands

end

Exercises:

1. Get and save the current date and time

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

days. The equation used to describe your knowledge as a function of time t is

−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:

3. Calculate how many seconds elapsed since the start of class.

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

−t . Use vector functions.


τ
k =1−e

Solution:

Ouput:

5. Plot the learning trajectory.


LAB 2: Generation of some continuous-time and discrete-time Signals

Objective:

 To understand the representation of signals in MATLAB.

 To plot and understand common signals using inbuilt MATLAB functions.

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

representation of time t or n. The signals are represented by another vect

contains the sample values of the signal at respective point of times.


In MALTAB, a discrete time signal may be represented exactly, as explained above.

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

approximation exists. To ensure that the approximation is good enough to represent

the continuous time signal, sampling interval must be chosen sufficiently small.

Another point to be noted is that sequences of infinite duration cannot be stored in

MATLAB. Hence, the length of sequence must be chosen such that the rang

interest is completely represented.

To generate a vector t of time values in the interval 0 to 1with a sampling interval of

0.001 seconds, we can use the command as:

t=0:0.001:1;

For discrete time signals, vector n can be generated as:

n=0:1000.

Built in MATLAB functions for some common signals:

i. Periodic Square wave:

A*square(w0*t,rho); where A is amplitude, w0 is fundamental frequency,

rho is duty cycle.

ii. Periodic Triangular wave:

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.

iii. Exponential signals:

Growing exponential: B*exp(-a*t);

Decaying exponential: B*exp(a*t);


Discrete exponential: B*r.^n;

iv. Sinusoidal Signals

A*sin(w0*t+phi)

A*cos(w0*t+phi)

v. Step, impulse and ramp:

Unit step: u=[zeros(1,50), ones(1,50)]

Unit impulse: delta = [zeros(1,50), 1, zeros(1,50)]

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

are saved with the file name and extension.m.

Exercises:

1) U s e M A T L A B t o g e n e r a t e t

x[n]=Br n with B=5, r=2 in the range −10 ≤ n≤ 10.

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:

3) The solution to a linear differential equation is given by:


−t −0.5 t
x ( t )=10 e −5 e . Using MATLAB, plot x(t) versus t in the range

−0 ≤ t ≤ 5 with the interval 0.01.


Solution:

Output:

4) A rectangular pulse x(t) is defined as:


{
x ( t )= 10 , 0 ≤t ≤5
0 , otherwise

Generate x(t) as a difference of a pair of time shifted step signals.

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:

 To understand the representation of LTI systems in MATLAB

 To compute and plot the responses of LTI system.

Theory:

Output of LTI system is given by convolution of its impulse response

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

be represented only as approximations. Another fact that needs to be considered is

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

approximate the infinite length signal by a finite length one.

Convolution in MATLAB is evaluated using the built in function that c

convolution sum of two finite length sequences. If x and h are two sequences

length L and M, then their convolution sequence y is given as shown below

contains L+M-1 elements.

y = conv(x,h);

In general, if the first element of x corresponds to timex , n=k


and the first element

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

responses both are causal, first p elements of y obtained as above usin

elements of x and h provide the output of the system.

Imaginary and real part of any complex sequence can be obtained using bu

function as:

a=real(x); b=imag(x);

Another well-known representation of DT LTI system is difference equation of the

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

c o n t a i n i n g c o e f f i c i e n tks aan d bk . F o r n o n - z e r o i n i t i a l c o n d i t i o ni s=, y [ - 1 ], y [ - 2 ],

y[-3],…… y[-N], y=filter(b, a, x, zi); where zi=filtic(b, a, yi);

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 ] -

u[n-12]} and impulse response h[n] = 0.9 n {u[n-2]-u[n-13]}.

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

transfer function using inbuilt MATLAB functions.

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

calculates N point DFT of finite length sequence x[n] of length N. I


represents one period of a periodic signal x[n] with period N, its DTF

evaluated using fft as:

X=fft(x)/N;

In similar manner, time domain representations can be obtained using ifft.

The system function of a discrete system is given as:

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

50, its frequency transform using 100-point fft.

Solution:
Output:

2) Determine the DTFS coefficients of the following signal using fft command.

π 3π
x [ n ] =sin( n+ )
12 8

Also reconstruct and plot the one period of original signal.

Solution:
Output:

3) Determine and plot the FS coefficients of the signal given below

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-

1] +6x[n-2] +4x[n-3] +x[n-4])

Solution:

Output:

You might also like