BL - En.u4ece22033 - M Bhanu Charan

You might also like

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

NOV|2023

Signals and Systems Assignment


19ECE203: Signals and Systems

Submitted by

BL.EN.U4ECE22033 M BHANU CHARAN


in partial fulfillment for the award of the degree
of
BACHELOR OF TECHNOLOGY
IN
“ELETRONICS AND COMMUNICATION”
ENGINEERING

NOVEMBER-2023

AMRITA VISHWA VIDYAPEETHAM


AMRITA SCHOOL OF ENGINEERING, BENGALURU, 560035

Department of ECE, ASE, Bengaluru


A: INTRODUCTION TO MATLAB
QUESTION 1

a) Create a row vector x with elements 1, 2, 9, -2, 4, 3, -6, and a column vector y with the same

sequence of elements.

b) Use length(x) and find the length of vector x.

c) Find the transpose of x and y. What do you observe?

d) Find x.*x.

close all

x=[1, 2, 9, -2, 4, 3, -6];


y=[1; 2; 9; -2; 4,; 3; -6];

disp("the length of x is: "+length(x));

the length of x is: 7

disp("the lenght of y is: "+length(y));

the lenght of y is: 7

disp("the transpose of x is:");

the transpose of x is:

x'

ans = 7×1
1
2
9
-2
4
3
-6

disp("the transppose of y is:");

the transppose of y is:

y'

ans = 1×7
1 2 9 -2 4 3 -6

disp("the value of x*x' is: " +x*x');

the value of x*x' is: 151


QUESTION 2

Create two 3×3 matrices A and B with elements (1 4 1; 2 3 4; -1 6 7) and (7 4 2;3 5 6; -1 2 1) and

determine the following.

a) A + B

b) A.*B

c) A*B

d) A(:, 3)

e) B(1:2, : )

f) AT + 2BT

A=[1,4,1;2,3,4;-1,6,7];
B=[7,4,2;3,5,6;-1,2,1];
%2.a)
a=A+B

a = 3×3
8 8 3
5 8 10
-2 8 8

%2.b)
b=A.*B

b = 3×3
7 16 2
6 15 24
1 12 7

%2.c)
c=A*B

c = 3×3
18 26 27
19 31 26
4 40 41

%2.d)
d=A(:, 3)

d = 3×1
1
4
7

%2.e)
e=B(1:2, : )

e = 2×3
7 4 2
3 5 6

%2.f)
f=transpose(A)+2*transpose(B)

f = 3×3
15 8 -3
12 13 10
5 16 9

QUESTION 3

Explore the in-built functions sqrt, sin, cos, exp, log10, log, in MATLAB and use them:

clc
close all

disp("p= "+ (2*sqrt(3)+ 2/(sqrt(5)-1)));

p= 5.0821

disp("q= "+(log(exp(5)) + log10(10^2)));

q= 7

disp("r= "+(sin(pi/6)*sin(pi/6))+(cos(pi/6)*cos(pi/6)));

r= 0.250060.74994

disp("s= "+(1+5*sqrt(-1))/(1-5*sqrt(-1)));

s= -0.92308+0.38462i

disp("w= "+(exp(1).^sqrt(-1)*pi/4));

w= 0.42441+0.66098i

disp("u= "+(exp(1).^pi/2*sqrt(-1)));

u= 0+11.5751i

QUESTION 4

Create a vector t = 0:0.001:2 , find x1 = sin(2π10t) and x2 = cos(2π20t).

a) Plot the signals x1 and x2 versus t in two figure windows. (Hint: Use commands plot, xlabel,

ylabel)

b) Plot the signals x1 and x2 versus t in the same figure window. (Hint: Use commands subplot,

plot)

clc
close all
t=0:0.001:2;
x1=sin(2*pi*10*t);
x2=cos(2*pi*20*t);
figure(1);
plot(t,x1);
xlabel('Time(t)');
ylabel('Signal x1');

figure(2);
plot(t,x2);
xlabel('Time (t)');
ylabel('x2');

QUESTION 5
Explore the working following built-in functions in MATLAB (submit code showing how each of the

functions is to be used and show output)

abs(x), cos (x), sin(x), tan(x), ceil(x), fix(x), floor(x), round(x),

char(x), eye(), ones(), zeros(), real(x), mag(x)

clc

close all

x=10.23;
disp("abs:"+ abs(x));

abs:10.23

disp("cos:"+ cos(x));

cos:-0.69295

disp("sin:"+ sin(x));

sin:-0.72098

disp("tan:"+ tan(x));

tan:1.0405

disp("ceil:"+ceil(x));

ceil:11

disp("fix:"+ fix(x));

fix:10

disp("floor:"+floor(x));

floor:10

disp("roumd:"+round(x));

roumd:10

disp("char:"+char(x));

char:

disp("eye:"+eye(10));

Columns 1 through 3

"eye:1" "eye:0" "eye:0"


"eye:0" "eye:1" "eye:0"
"eye:0" "eye:0" "eye:1"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"

Columns 4 through 6

"eye:0" "eye:0" "eye:0"


"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:1" "eye:0" "eye:0"
"eye:0" "eye:1" "eye:0"
"eye:0" "eye:0" "eye:1"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"

Columns 7 through 9

"eye:0" "eye:0" "eye:0"


"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:0" "eye:0" "eye:0"
"eye:1" "eye:0" "eye:0"
"eye:0" "eye:1" "eye:0"
"eye:0" "eye:0" "eye:1"
"eye:0" "eye:0" "eye:0"

Column 10

"eye:0"
"eye:0"
"eye:0"
"eye:0"
"eye:0"
"eye:0"
"eye:0"
"eye:0"
"eye:0"
"eye:1"

disp("ones:"+ones(5));

Columns 1 through 3

"ones:1" "ones:1" "ones:1"


"ones:1" "ones:1" "ones:1"
"ones:1" "ones:1" "ones:1"
"ones:1" "ones:1" "ones:1"
"ones:1" "ones:1" "ones:1"

Columns 4 through 5

"ones:1" "ones:1"
"ones:1" "ones:1"
"ones:1" "ones:1"
"ones:1" "ones:1"
"ones:1" "ones:1"
disp("zeros:"+zeros(2,2));

"zeros:0" "zeros:0"
"zeros:0" "zeros:0"

disp("real:"+real(x));

real:10.23

disp("mag:"+imag(x));

mag:0

B. Generation of Sequences - I

Generate the following signals and plot them using MATLAB.

a. A continuous-time sinusoidal signal, x(t) = 2sin(2πt+φ) for 0 ≤ t ≤ 4 for phase, φ = 0 and π.

b. A discrete-time sinusoidal signal with a fundamental period N=10, for -20 ≤ n ≤ 20.

c. A rectangular pulse with a pulse width of 2.

d. A triangular waveform with a time-period of 0.5 sec for -2 ≤ t ≤ 2, with peak value occurring at

p = 0.8.

e. A continuous-time exponential waveform, y(t) = e-t, 0 ≤ t ≤ 5 and a discrete time exponential

signal, x[n] = an, where a = 0.8 and 0 ≤ n ≤ 25.

Hint: Use functions sin(), rectpuls(), sawtooth(), exp(), stem(), figure(),

plot(), legend(), xlabel(), ylabel(), subplot(), grid(), etc.

%(a)
t=0:0.001:4;
xt=2*sin(2*pi*t+0);
plot(t,xt);
xlabel('t');
ylabel('2sin(2πt+φ)');
title('continuous-time sinusoidal for φ=0 ');
grid on;
xt2=2*sin(2*pi*t+pi);
subplot(2,1,2);
plot(t,xt2);
xlabel('t');
ylabel('2sin(2πt+φ)');
title('continuous-time sinusoidal for φ=π');
grid on;

%(b)
N=10;
n=-20:20;
xn=sin(2*pi*n/N);
figure;
stem(n,xn);
title('Discrete time sinusodial signal')
xlabel('n');
ylabel('xn');
grid on ;
%(c)

t=-2:0.01:2;
rect_pulse= rectpuls(t,2);
figure;
plot(t,rect_pulse)
title('Rectangular pulse');
xlabel('t');
ylabel('Rect_pulse');

%(D)

T=0.5
T = 0.5000

P=0.8

P = 0.8000

t = -2:0.1:2;
tri_pulse=P* sawtooth(2*pi/T * t,0.8);
figure;
plot(t,tri_pulse);
title('Triangular pulse');
xlabel('t');
grid on;
ylabel('Tri_pulse');

%(E)
t=0:0.001:5;
e=2.71828;
x=e.^(-t);
figure(1);
subplot(2,1,1);
plot(t,x);
xlabel('t');
ylabel('x');
title('Continuous-time exponential waveform');
n=0:25;
a=0.8;
y=a.^n;
subplot(2,1,2);
stem(n,y);
xlabel('n');
ylabel('y');
title('Discrete time exponential waveform');
grid on;

C. Generation of Sequences - I
Generate impulse, step, and ramp signals (continuous time & discrete time) using:

a. Logical operations

b. Function files.

%(a)
%continuous impusule signal
t = -1:0.001:1;
delta_t = (t == 0);
figure;
subplot(3,1,1)
plot(t, delta_t, 'LineWidth', 2);
title('Impulse Signal');
xlabel('Time');
ylabel('\delta(t)');
grid on;
%continuous unit step signal
u_t = heaviside(t);
subplot(3,1,2);
plot(t, u_t);
title('Unit Step Signal');
xlabel('Time');
ylabel('u(t)');
%continuous ramp signal
r_t = t .* (t >= 0);
subplot(3,1,3);
plot(t, r_t);
title('Ramp Signal');
xlabel('Time');
ylabel('r(t)');

n = -10:10;
delta_n = (n == 0);
%DIsctrete impusle signal
figure;
subplot(3,1,1);
stem(n, delta_n);
title('Unit Impulse Signal');
xlabel('n');
ylabel('\delta[n]');
grid on;
%discrete Unit step signal
u_n = heaviside(n);
n = -10:10;
u_n = zeros(size(n));
u_n(n >= 0) = 1;
subplot(3,1,2)
stem(n, u_n, 'LineWidth', 2);
title('Unit Step Signal');
xlabel('n');
ylabel('u[n]');
grid on;
%Discrete ramp signal
r_n = n .* (n >= 0);
subplot(3,1,3);
stem(n, r_n);
title('Ramp Signal');
xlabel('n');
ylabel('r[n]');
%(b)
t_cont = -5:0.01:5;
n_discrete = -5:5;
impulse_cont = signals(t_cont,'impulse');
step_cont = signals(t_cont, 'step');
ramp_cont = signals(t_cont, 'ramp');
impulse_discrete = signals(n_discrete, 'impulse');
step_discrete = signals(n_discrete, 'step');
ramp_discrete = signals(n_discrete, 'ramp');
figure;
subplot(3,2,1); plot(t_cont, impulse_cont); title('Continuous Time Impulse Signal');
subplot(3,2,2); plot(t_cont, step_cont); title('Continuous Time Step Signal');
subplot(3,2,3); plot(t_cont, ramp_cont); title('Continuous Time Ramp Signal');
subplot(3,2,4); stem(n_discrete, impulse_discrete); title('Discrete Time Impulse Signal');
subplot(3,2,5); stem(n_discrete, step_discrete); title('Discrete Time Step Signal');
subplot(3,2,6); stem(n_discrete, ramp_discrete); title('Discrete Time Ramp Signal');
D. Basic operations on signals
Question 1

1. Generate a signal x(t) = 3sin(10πt)e-5t for 0 ≤ t ≤ 2, and perform the following operations:

(a) y1(t) = x(–t)

(b) y2(t) = x(t–3)

(c) y3(t) = x(t+2)

(d) y4(t) = x(t/2)

(e) y5(t) = x(2t)

Hint: Use commands as subplot(), plot(), legend(), axis(), grid(), etc.

%(A)
t=0:0.001:2;
pi=3.142;
e=2.71828;
T=t;
xt=3*sin(10*pi*T)*e.*(-5*T);
figure;
subplot(2,1,1);
plot(T,xt);
title('X(t)');
xlabel('t');
ylabel('x(t)');
grid on;
T=-t;
subplot(2,1,2);
plot(T,xt);
title('y1(t) = x(–t)');
xlabel('t');
ylabel('y1(t)');
grid on;

T=t+3;
figure;
subplot(2,1,1);
plot(T,xt);
title('y2(t) = x(t–3)');
xlabel('t');
ylabel('y2(t)');
T=t-2;
subplot(2,1,2);
plot(T,xt);
title('y3(t) = x(t+2)');
xlabel('t');
ylabel('y3(t)');
T=t*2;
figure;
subplot(2,1,1);
plot(T,xt);
title('y4(t) = x(t/2)');
xlabel('t');
ylabel('y4(t)');
T=t/2;
subplot(2,1,2);
plot(T,xt);
title('y5(t) = x(2t)');
xlabel('t');
ylabel('y5(t)');
QUESTION 2

Verify whether the following signals are even, odd or neither even nor odd, by decomposing the signals into

their even and odd components. For each signal, generate a figure window and plot the signal, it’s even and odd

parts using subplots.

(a) x1(t) = 5cos[(π/8)t]

(b) x2(t) = 4sin[(π/6)t]

(c) x3(t) = e-2t for 0 ≤ t ≤ 2.

%(a)
t=linspace(-10,10,1000);
x1t=5*cos((pi/8)*t);
figure(1);
subplot(3,1,1);
plot(t,x1t);
xlabel('t');
ylabel('X1(t)');
xe=0.5*(x1t+fliplr(x1t));
subplot(3,1,2) ;
plot(t,xe);
xlabel('t');
ylabel('Xe');
title('Even components');
xo=0.5*(x1t-fliplr(x1t));
subplot(3,1,3);
plot(t,xo);
xlabel('t');
ylabel('Xo');
title('Odd components');
sgtitle('x1(t) = 5cos[(π/8)t]');
%(B)
t=linspace(-10,10,1000);
x2t=4*sin((pi/6)*t);
figure(1);
subplot(3,1,1);
plot(t,x2t);
xlabel('t');
ylabel('X2(t)');
xe=0.5*(x2t+fliplr(x2t));
subplot(3,1,2) ;
plot(t,xe);
xlabel('t');
ylabel('Xe');
title('Even components');
xo=0.5*(x2t-fliplr(x2t));
subplot(3,1,3);
plot(t,xo);
xlabel('t');
ylabel('Xo');
title('Odd components');
sgtitle('x2(t) = 4sin[(π/6)t]');
%(C)
e=2.71828;
t=0:0001:2;
x3t=e.*(-2*t);
figure;
subplot(3,1,1);
plot(t,x3t);
xlabel('t');
ylabel('X3(t)');
xe=0.5*(x3t+fliplr(x3t));
subplot(3,1,2) ;
plot(t,xe);
xlabel('t');
ylabel('Xe');
title('Even components');
xo=0.5*(x3t-fliplr(x3t));
subplot(3,1,3);
plot(t,xo);
xlabel('t');
ylabel('Xo');
title('Odd components');
sgtitle('x3(t) = e^(-2t)');
E. Convolution
QUESTION 1

Find the output of an LTI system characterized by impulse response h[n] = [1, 2, -1, 2, 3, -4,],

when the input signal is x[n] = [1, 0.5, -1, 3, -6, 4, 3, 5]. Numbers in bold are signal values at the

time origin n = 0. Use subplot to plot the input signal x[n], impulse response h[n], and output

signal y[n].

xn=-3:4;
x=[1, 0.5, -1, 3, -6, 4, 3, 5];
hn=-2:3;
h=[1, 2, -1, 2, 3, -4,];
figure(1);
subplot(3,1,1);
stem(xn,x,'b');
xlabel('n');
ylabel('x');
title('Input Signal-X(n)');
grid on;
subplot(3,1,2);
stem(hn,h,'r');
xlabel('n');
ylabel('h');
title('Impulse Signal-h(n)');
grid on;
yn = hn(1) + xn(1):hn(end) + xn(end);
y=conv(x,h);
subplot(3,1,3);
stem(yn,y,'g');
xlabel('n');
ylabel('y');
title('Output Signal-Y(n)');
grid on;
sgtitle('Convolution of signals')
QUESTION 2

Find y(t) = x(t) * h(t) with x(t) = u(t) – u(t-4) and h(t) = u(t+2) – u(t-2),

t = -10:10. Use subplot to plot the input signal, impulse response of the system, and output signal.

t=-10:0.1:10;
x =(t>= 0)-((t-4)>=0);
h=(t>=-2)-(t>=2);
figure(1);
subplot(3,1,1);
plot(t,x,'b');
xlabel('t');
ylabel('x');
title('Input Signal-X(t)');
grid on;
subplot(3,1,2);
plot(t,h,'r');
xlabel('t');
ylabel('h');
title('Impulse Signal-h(t)');
grid on;
y=conv(x,h,'same');
subplot(3,1,3);
plot(t,y,'g');
xlabel('t');
ylabel('y');
title('Output Signal-Y(t)');
grid on;
sgtitle('Convolution of signals')
QUESTION 3

Find y(t) = x(t) * h(t) where x(t) and h(t) are as shown below. Use subplot to plot input

signal x(t), impulse response of the system h(t) and output signal.

t=-0.5:0.01:0.5;
x=abs(t)<=0.5;
figure(1);
subplot(3,1,1);
plot(t,x,'b');
xlabel('t');
ylabel('x');
title('Input Signal-X(t)');
grid on;
t1=-1:0.01:1;
h=1-abs(t1);
subplot(3,1,2);
plot(t1,h,'r');
xlabel('t');
ylabel('h');
title('Impulse Signal-h(t)');
grid on;
y=conv(x,h,'same');
subplot(3,1,3);
plot(t,y,'g');
xlabel('t');
ylabel('y');
title('Output Signal-Y(t)');
grid on;

You might also like