Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Lab 6.

LTI System

Name: Ravi Shankar Prasad Sahu


Roll: 21CS8067

1. For each of the following system. Determine whether or not the system is time-invariant
=> A time-invariant system is a type of system in which the output of the system is only
dependent on the current and past inputs of the system and not on the time at which
these inputs occur. In other words, the system's behavior does not change over time.

If y(t) = x(t) denotes the output of the system when the input is x(t), and y1(t) = x(t-T0)
denotes the output of the system when the input is x(t-T0) then y(t-T0) = x(t-T0) = y1(t) for
all values of t and T0.

a. y(t) = tx(t)

=> Code:
def x(t): # take x(t) = sin(t)
return np.sin(t)

t0 = 2 #define time shift


t = np.linspace(0, 2*np.pi, 100)

def y(t):
return t*x(t)

def _y(t):
return t*x(t-t0)

def y1(t):
return (t-t0)*x(t-t0)

plt.plot(t, _y(t))
plt.plot(t, y1(t))
plt.show()

Output:

#So this system is


time varient system
2. y(t) = e x(t)

Code:

def y(t):
return np.exp(x(t))

def _y(t):
return np.exp(x(t-t0))

def y1(t):
return np.exp(x(t-t0))

plt.plot(t, _y(t))
plt.plot(t, y1(t))
plt.show()

Output:

# This system is not a time varient system

3. y(t) = x(t + 10) + x 2 (t)

Code:

def y(t):
return x(t+10) + x(t)**2

#shift in input x1(t) = x(t-t0)


def _y(t):
return x(t+10-t0) + x(t-t0)**2
#shifted output
def y1(t):
return x(t-10-t0) + x(t-t0)**2

plt.plot(t, _y(t))
plt.plot(t, y1(t))

Output:

#So this system is time varient system

4. y(n) = si n(x(n))

Code:
def y(t):
return np.sin(x(t))

def _y(t):
return np.sin(x(t-t0))

def y1(t):
return np.sin(x(t-t0))

plt.plot(t, _y(t))
plt.plot(t, y1(t))
plt.show()

Output:
# This system is not a time varient system

5. y(n) = x(n + 1) + x(n) + x(n − 1)

Code:

def y(t):
return x(t+1) + x(t) + x(t-1)

def _y(t):
return x(t+1-t0) + x(t-t0) + x(t-1-t0)

def y1(t):
return x(t-t0+1) + x(t-t0) + x(t-t0-1)

plt.plot(t, _y(t))
plt.plot(t, y1(t))
plt.show()

Output:

# This system is not a time varient system


2. Differential Equation of a system is given by: y ′′ (t) − y ′ (t) − 2y(t) =
x(t)
a. Determine system is LTI or not?
b. Find the impulse response of the system
c. Find the stability of system

a.

Code:

import sympy as sp

# Define the variables and functions


t = sp.symbols('t')
x = sp.Function('x')(t)
y = sp.Function('y')(t)

# Define the differential equation


eq = sp.diff(y, t, t) - sp.diff(y, t) - 2*y - x

# Define the inputs


a1, a2 = sp.symbols('a1 a2')
x1 = a1*sp.DiracDelta(t)
x2 = a2*sp.DiracDelta(t)

# Check the superposition property


if sp.simplify(eq.subs(x, x1 + x2) - eq.subs(x, x1) - eq.subs(x, x2)) == 0:
print("The system satisfies the superposition property")
else:
print("The system does not satisfy the superposition property")

# Check the homogeneity property


k = sp.symbols('k')
if sp.simplify(eq.subs(x, k*x)) == k*eq.subs(x, x):
print("The system satisfies the homogeneity property")
else:
print("The system does not satisfy the homogeneity property")

Output:
The system does not satisfy the superposition property
The system does not satisfy the homogeneity property
b.

Code:

from scipy import signal


import matplotlib.pyplot as plt
import numpy as np

# Define the transfer function of the system


num = [1] # numerator polynomial of X(s)
den = [1, -1, -2] # denominator polynomial of Y(s)
H = signal.TransferFunction(num, den)

# Obtain the impulse response of the system


t, h = signal.impulse(H)

# Plot the impulse response


plt.plot(t, h)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.title('Impulse Response')
plt.grid()
plt.show()

Output:

c.

Code:

import numpy as np
# Define the coefficients of the characteristic equation
a=1
b = -1
c = -2

# Calculate the discriminant of the characteristic equation


D = b**2 - 4*a*c

# Check if the roots have negative real parts


if D > 0:
r1 = (-b + np.sqrt(D)) / (2*a)
r2 = (-b - np.sqrt(D)) / (2*a)
if r1 < 0 and r2 < 0:
print("The system is asymptotically stable")
else:
print("The system is not asymptotically stable")
elif D == 0:
r = -b / (2*a)
if r < 0:
print("The system is marginally stable")
else:
print("The system is not marginally stable")
else:
print("The system is not stable")

Output:
The system is not asymptotically stable.

3. The output response y(t) of a continuous time LTI system is 2e −3t u(t),
when the input x(t) is u(t). Find the system function.

Code:

t, s, F = sp.symbols('t, s F')
def u(t):
return sp.Heaviside(t)

def laplas(f):
F = sp.laplace_transform(f, t, s)
return F

def inverseLaplas(f):
f = sp.inverse_laplace_transform(F, s, t)
return f

f = u(t)
# sp.plot(f)
f = 2*(sp.exp(-3*t)*u(t))
# sp.plot(f)

x_s = laplas(sp.Heaviside(t))
y_s = laplas(f)
h_s = y_s[0] / x_s[0]
_h = inverseLaplas(h_s)

Output: 𝐹(𝐹)

4. Find the output response of an LTI system with impulse response h(t) =
δ(t − 3) for
input x(t) = cos4t + cos7t

Code:

F = sp.DiracDelta(t-3)
x = sp.cos(4*t) + sp.cos(7*t)
f_s = laplas(F)
x_s = laplas(x)
y_t = f_s[0] * x_s[0]
inverseLaplas(y_t)

Output: (𝐹)𝐹(𝐹−3)

You might also like