0% found this document useful (0 votes)
18 views24 pages

Worksheet-2 & 3 Report

The document outlines an experiment conducted at Amrita School of Engineering Bengaluru, focusing on signal generation and operations using MATLAB. It includes detailed instructions for generating various signals such as impulse, step, ramp, and sinusoidal signals, along with plotting and analyzing their characteristics. The document also provides inferences from the generated graphs, highlighting the behavior of the signals under different conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views24 pages

Worksheet-2 & 3 Report

The document outlines an experiment conducted at Amrita School of Engineering Bengaluru, focusing on signal generation and operations using MATLAB. It includes detailed instructions for generating various signals such as impulse, step, ramp, and sinusoidal signals, along with plotting and analyzing their characteristics. The document also provides inferences from the generated graphs, highlighting the behavior of the signals under different conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Amrita School of Engineering Bengaluru

Name: Sai Haasini Ravinuthala Reg.no: BL.EN.U4ECE24151


Experiment no.: 2 Date: 28-01-2025

SIGNAL GENERATION

Aim: To generate elementary and composite signals such as exponential, triangular, rectangular
in MATLAB

1.​ Write a function to generate the following signals


a) unit impulse signal 𝛿[𝑛] 𝑎𝑛𝑑 𝛿(𝑡)
b) unit step signal 𝑢[𝑛] 𝑎𝑛𝑑 𝑢(𝑡)
c) unit ramp signal 𝑟[𝑛] 𝑎𝑛𝑑 𝑟(𝑡)

a) function [y] = impulse_24151(t)


y = t==0;

end

x_dis = -10:1:10;

y_dis = impulse_24151(x_dis)

x_con = -10:0.1:10;

y_con = impulse_24151(x_con);

figure()

subplot(2, 1, 1)

stem(x_dis, y_dis, 'r')

title("Discrete-time unit impulse signal - 151")

xlabel('n')

ylabel('𝜹[n]')

subplot(2, 1, 2)

plot(x_con, y_con)

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

title("Continuous-time unit impulse signal - 151")

xlabel('t')

ylabel('𝜹(t)')

b) function [y] = step_24151(t)


y = t>=0;

end

x_dis = -10:1:10;

y_dis = step_24151(x_dis);

x_con = -10:0.1:10;

y_con = step_24151(x_con);

figure()

subplot(2, 1, 1)

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

stem(x_dis, y_dis, 'r', 'filled')

grid on

title("Unit step signal in discrete time - 151")

xlabel('n')

ylabel('u[n]')

subplot(2, 1, 2)

plot(x_con, y_con)

grid on

title("Unit step signal in continuous time - 151")

xlabel('t')

ylabel('u(t)')

​ ​

​ ​
c) function [y] = step_24151(t)
y = t>=0;

end

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

function [del] = ramp_24151(t, a)

del = t.*a;

end

x_dis = -10:1:10;

y_dis = ramp_24151(x_dis, step_24151(x_dis));

x_con = -10:0.1:10;

y_con = ramp_24151(x_con, step_24151(x_con));

figure()

subplot(2, 1, 1)

stem(x_dis, y_dis, 'r')

grid on

title("Ramp function in discrete time intervals - 151")

xlabel('n')

ylabel('r[n]')

subplot(2, 1, 2)

plot(x_con, y_con)

grid on

title("Ramp function in continuous time intervals - 151")

xlabel('t')

ylabel('r(t)')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

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

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

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

a) t = 0:0.001:2;

x1 = sin(2*pi*10*t);

x2 = cos(2*pi*20*t);

plot(t, x1, 'r-')

xlabel('t');

ylabel('x1(t)');

title("Graph of sin(pi*t) - 151")

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

plot(t, x2, '-')

xlabel('t');

ylabel('x2(t)');

title("Graph of cos(pi*t) - 151")

b) t = 0:0.001:2;

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

x1 = sin(2*pi*10*t);

x2 = cos(2*pi*20*t);

subplot(2, 1, 1);

plot(t, x1, 'r-')

title("Graph of sin(pi*t) - 151")

subplot(2, 1, 2);

plot(t, x2, '-')

title("Graph of cos(pi*t) - 151")

3.​ Write a program to generate the following signals in MATLAB

(a) x(t)={ 𝑡 0≤𝑡≤3

𝑡−1 3< 𝑡 < 6

0 𝐸𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒}

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

(b) x[n]=u[n]-u[n-N] where u[n] is unit step signal where N should be varied from 2
to 20.

a) t = -2:0.001:8;

x = zeros(1, length(t));

for i = i:length(t)

if t(i)>=0 && t(i)<=3

x(i) = t(i);

elseif t(i)>3 && t(i)<=6

x(i) = t(i)-1;

else

x(i) = 0;

end

end

plot(t, x, 'r')

grid on

title("Graph of x(t) v/s t - 151")

xlabel('t')

ylabel('x(t)')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Inference: The graph has the value x(t) = t from t = 0 to t = 3, and the value x(t) = t-1
from t = 3 to t = 6. It is zero for all other values. So at t = 3, there is a sharp drop of
amplitude from 3 to 2.

b) t = 0:1:20;

N = 4;

y = unitstep_func_24151(t) - unitstep_func_24151(t-N);

stem(t, y, 'k', 'filled')

xlabel('n')

ylabel('x[n]')

title("Graph of x[n] v/s n - 151")

grid on

function y = unitstep_func_24151(t)

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

y = zeros(1, length(t));

for i = 1:length(t)

y = t>=0;

end

end

If N = 10:

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Inference: The equation u[n] - u[n-N] basically shows the windowed version of the discrete
unit step signal upto a certain interval N. The number of samples in the graph increases upon
increasing the value of N. Eg. for N = 10, we have samples from 0 to 9, as the graph from n =
10 gets deleted.

4.​ Write a user-defined function which generates an exponential damped sinusoid


signal 𝑥(𝑡) = 𝑒^( −𝜎𝑡)*sin(2𝜋𝑓𝑡). Generate the signal for various values of 𝜎 and observe the
change in the signal generated (Hint: Take 𝜎, 𝑓,𝑡 as parameters of the function). t is limited
to 10 cycles of the frequency of the sine wave f.
clc

clear

close all

s = 0.73;

f = 5;

t = 0:0.001:5;

x = expDampedSin_151(s, f, t);

plot(t, x)

grid on

title("Graph of exponentially damped sinusoid - 151")

xlabel('t')

ylabel('x(t)')

function x = expDampedSin_151(s, f, t)

x = exp(-s*t).*sin(2*pi*f*t);

end

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Fig (a)

Keeping f and t constant:

If s = 1:

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Fig (b)

If s = 0.09:

Fig (c)

Keeping s and t constant:

If f = 1:

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Fig (d)

If f = 10:

Fig (e)

Inference: Keeping frequency and time constant, sigma (damping factor) value is changed.
Initial value of sigma is taken as 0.73 to obtain the graph in Fig (a). If the value of sigma is
increased to 1, the amplitude decreases rapidly and approaches zero within a short span of
time.. Whereas, when sigma is decreased, the oscillations continue for a longer time with less
noticeable decay.

Now when time and sigma are constant, frequency is varied. If frequency is high, the number
of oscillations in the given time frame are also more. Whereas, if frequency is low, the number
of oscillations are less.

5.​ Plot the signal given in Figure 1. (Hint: The first section in the figure is an
exponentially decaying signal 𝑒^ (−0.5 𝑡) , -3t+1 from -1 to 0 and last part is 𝑒 ^(0.5𝑡)*
sin(5𝜋𝑡))
t = -2:0.001:4;

y = zeros(1, length(t));

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

xlim([-2, 4]);

ylim([-8, 8]);

s = -0.5;

f = 2.5;

for i = 1:length(t)

if t(i)>=-3 && t(i)<=-1

y(i) = exp(-0.5*t(i));

elseif t(i)>-1 && t(i)<=0

y(i) = -3*t(i) + 1;

elseif t(i)>=2 && t(i)<=4

y(i) = expDampedSin_151(s, f, t(i));

else

y(i) = 1;

end

end

plot(t, y, 'b')

xlabel('t')

ylabel('amplitude')

title("Graph of x(t) v/s t - 151")

grid on

legend('x(t)')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Inference: This graph is a decaying exponential until t = -1, a line -3t+1 from -1 to 0, a
constant value 1 upto t = 2, and an exponentially growing sinusoid, indicating an oscillatory
nature with increasing amplitude from t = 2 to 4. There are abrupt changes as t = -1, 0, 2 which
may indicate instability in signal.

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Experiment no.: 3 Date: 04-02-2025

SIGNAL OPERATION ON DEPENDENT VARIABLE


1.​ Generate 1000 samples of the signal x(t) = 𝑒 ^(j20πt) between t = -0.5s and t =
0.5s. What is the time period and frequency (linear and angular) of these signals?
Generate 1000 samples of the signal x1(t) = Re{x(t)} from the samples of x(t), where,
Re{} denotes the real part of a complex variable. What is the amplitude of x1(t)?
Generate x2(t) = 5x1(t), and plot x1(t) and x2(t) in a single plot window (use subplots for
this). Observe the amplitude of x2(t).
clc

clear

close all

t = -0.5:0.001:0.5;

x = exp(1i*20*pi*t);

plot(t, x)

title("x(t) v/s t - 151")

xlabel('t')

ylabel('x(t)')

x1 = real(x);

x2 = 5*x1;

subplot(2, 1, 1)

plot(t, x1, 'r')

title("x1(t) v/s t - 151")

xlabel('t')

ylabel('x1(t)')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

subplot(2, 1, 2)

plot(t, x2, 'g')

title("x2(t) v/s t - 151")

xlabel('t')

ylabel('x2(t)')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Inference: The first graph is plotted by ignoring any imaginary parts of the function, so it
produces the same graph as x1(t), which is the real part of x(t). The peak amplitude in both
cases is 1. x2(t) is basically the function x1(t) scaled by a factor of 5. So the peak amplitude of
x2(t) is 5.

2.​ Generate 1000 samples of the signal x3(t) = cos(60𝜋𝑡 + π/4 ) between t = -0.5s and
t = 0.5s. Compute the corresponding samples of the signals x4(t) = x1(t) + x3(t) and x5(t)
= 2x1(t) + 3x3(t). Plot x1(t), x3(t), x4(t) and x5(t) in a single plot window.

clc

clear

close all

t = -0.5:0.001:0.5;

x1 = real(exp(1i*20*pi*t));

x3 = cos(60*pi*t + pi/4);

x4 = x1+x3;

x5 = 2*x1 + 3*x3;

subplot(4, 1, 1)

plot(t, x1, 'b')

title("x1(t) v/s t - 151")

xlabel('t')

ylabel('x1(t)')

grid on

subplot(4, 1, 2)

plot(t, x3, 'r')

title("x3(t) v/s t - 151")

xlabel('t')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

ylabel('x3(t)')

grid on

subplot(4, 1, 3)

plot(t, x4, 'g')

title("x4(t) v/s t - 151")

xlabel('t')

ylabel('x4(t)')

grid on

subplot(4, 1, 4)

plot(t, x5, 'k')

title("x5(t) v/s t - 151")

xlabel('t')

ylabel('x5(t)')

grid on

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Inference: x3(t) is a cosine graph shifted to the left by π/4 units. It has a higher frequency and
oscillates more rapidly. x4 is a combination of the signals x1 and x3. x5 is the sum of
the amplified versions of x1 and x3.

3.​ Generate 1000 samples of the signal x1(t) =𝑒^(-0.25t) and x2(t) =sin(4𝜋t) between t=
-5s and t= 5s. Compute the corresponding samples of the signal y(t) =x1(t)x2(t). Plot
x1(t), x2(t) and y(t) in a single plot window.

t = -5:0.001:5;

x1 = exp(-0.25*t);

x2 = sin(4*pi*t);

y = x1.*x2;

subplot(3, 1, 1)

plot(t, x1, 'r')

title("Graph of x1(t) v/s t - 151")

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

xlabel('t')

ylabel('x1(t)')

subplot(3, 1, 2)

plot(t, x2, 'b')

title("Graph of x2(t) v/s t - 151")

xlabel('t')

ylabel('x2(t)')

subplot(3, 1, 3)

plot(t, y, 'g')

title("Graph of y(t) v/s t - 151")

xlabel('t')

ylabel('y(t)')

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

Inference: x1 is an exponentially decaying function and x2 is a standard sinusoidal function.


y(t) is the multiplication of both these signals which results in an exponentially damped
sinusoid, whose amplitude is decreasing over time.

4.​ Write a function lincomp_RollNO which takes 4 inputs-a, b, 𝑥₁[𝑛] and 𝑥₂[𝑛] and
generates the signal y[𝑛] = 𝑎 𝑥₁ [𝑛] + 𝑏 𝑥₂[𝑛] where a and b are scalars. Using the
abovementioned function, generate the following signals 𝑦₁ [𝑛] = 𝑥₁ [𝑛] + 𝑥₂[𝑛] and 𝑦₂
[𝑛] = 𝑥₁[𝑛] − 𝑥₂[𝑛] where 𝑥₁[𝑛] = [2,1,3,4,5] and 𝑥₂[𝑛] = [5,4,3,1,2]. Assume the first
value to be the amplitude corresponding to n=0 for both the signals.

x1 = [2 1 3 4 5];

x2 = [5 4 3 1 2];

n = 0:1:4;

y1 = lincomp_151(1, 1, x1, x2);

y2 = lincomp_151(1, -1, x1, x2);

subplot(2, 1, 1)

stem(n, y1, 'r', 'filled')

title("Graph of y1[n] v/s n - 151")

xlabel('n')

ylabel('y1[n]')

subplot(2, 1, 2)

stem(n, y2, 'filled')

title("Graph of y2[n] v/s n - 151")

xlabel('n')

ylabel('y2[n]')

function y = lincomp_151(a, b, x1, x2)

y = a*x1 + b*x2;

Amrita School of Engineering Bengaluru


Amrita School of Engineering Bengaluru

end

Inference: y1[n] is an addition of x1[n] and x2[n], with a and b values both being 1. Whereas,
y2[n] is a subtraction of x1[n] and x2[n], with a and b being 1 and -1 respectively.

Amrita School of Engineering Bengaluru

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy