Worksheet-2 & 3 Report
Worksheet-2 & 3 Report
SIGNAL GENERATION
Aim: To generate elementary and composite signals such as exponential, triangular, rectangular
in MATLAB
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)
xlabel('n')
ylabel('𝜹[n]')
subplot(2, 1, 2)
plot(x_con, y_con)
xlabel('t')
ylabel('𝜹(t)')
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)
grid on
xlabel('n')
ylabel('u[n]')
subplot(2, 1, 2)
plot(x_con, y_con)
grid on
xlabel('t')
ylabel('u(t)')
c) function [y] = step_24151(t)
y = t>=0;
end
del = t.*a;
end
x_dis = -10:1:10;
x_con = -10:0.1:10;
figure()
subplot(2, 1, 1)
grid on
xlabel('n')
ylabel('r[n]')
subplot(2, 1, 2)
plot(x_con, y_con)
grid on
xlabel('t')
ylabel('r(t)')
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);
xlabel('t');
ylabel('x1(t)');
xlabel('t');
ylabel('x2(t)');
b) t = 0:0.001:2;
x1 = sin(2*pi*10*t);
x2 = cos(2*pi*20*t);
subplot(2, 1, 1);
subplot(2, 1, 2);
0 𝐸𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒}
(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)
x(i) = t(i);
x(i) = t(i)-1;
else
x(i) = 0;
end
end
plot(t, x, 'r')
grid on
xlabel('t')
ylabel('x(t)')
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);
xlabel('n')
ylabel('x[n]')
grid on
function y = unitstep_func_24151(t)
y = zeros(1, length(t));
for i = 1:length(t)
y = t>=0;
end
end
If N = 10:
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.
clear
close all
s = 0.73;
f = 5;
t = 0:0.001:5;
x = expDampedSin_151(s, f, t);
plot(t, x)
grid on
xlabel('t')
ylabel('x(t)')
function x = expDampedSin_151(s, f, t)
x = exp(-s*t).*sin(2*pi*f*t);
end
Fig (a)
If s = 1:
Fig (b)
If s = 0.09:
Fig (c)
If f = 1:
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));
xlim([-2, 4]);
ylim([-8, 8]);
s = -0.5;
f = 2.5;
for i = 1:length(t)
y(i) = exp(-0.5*t(i));
y(i) = -3*t(i) + 1;
else
y(i) = 1;
end
end
plot(t, y, 'b')
xlabel('t')
ylabel('amplitude')
grid on
legend('x(t)')
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.
clear
close all
t = -0.5:0.001:0.5;
x = exp(1i*20*pi*t);
plot(t, x)
xlabel('t')
ylabel('x(t)')
x1 = real(x);
x2 = 5*x1;
subplot(2, 1, 1)
xlabel('t')
ylabel('x1(t)')
subplot(2, 1, 2)
xlabel('t')
ylabel('x2(t)')
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)
xlabel('t')
ylabel('x1(t)')
grid on
subplot(4, 1, 2)
xlabel('t')
ylabel('x3(t)')
grid on
subplot(4, 1, 3)
xlabel('t')
ylabel('x4(t)')
grid on
subplot(4, 1, 4)
xlabel('t')
ylabel('x5(t)')
grid on
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)
xlabel('t')
ylabel('x1(t)')
subplot(3, 1, 2)
xlabel('t')
ylabel('x2(t)')
subplot(3, 1, 3)
plot(t, y, 'g')
xlabel('t')
ylabel('y(t)')
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;
subplot(2, 1, 1)
xlabel('n')
ylabel('y1[n]')
subplot(2, 1, 2)
xlabel('n')
ylabel('y2[n]')
y = a*x1 + b*x2;
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.