0% found this document useful (0 votes)
6 views

SNS Lab 2

Uploaded by

ihassam baloch
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SNS Lab 2

Uploaded by

ihassam baloch
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Signals & Systems Lab Department of Electrical & Computer Engineering

Lab 02- Symbolic Computation, Plotting And


Primitive Signals
Task 01:

MATLAB Code:
x = -5:0.1:5 ;

% Define parameters:

m = 0;

s = 1;

% Call the function:

y = f(x, m, s); % Calculate y values using f(x, m, s)

plot(x, y); % Plot the function:

% Set plot labels and title:

xlabel('x');

ylabel('y');

title('plot y(x)');

grid on; % Add grid lines (optional)

% Function to calculate y(x):

function y = f(x, m, s)

y = 1 / (s * sqrt(2 * pi)) .* exp(-0.5 .* ((x - m) / s) .^ 2);

end

Output:
plot y(x)
0.4

0.35

0.3

0.25

0.2
y

0.15

0.1

0.05

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
x

FIGURE 1 PLOT WITH FUNCTION

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Task 02:

MATLAB Code:
clear;clc;close all;

A).
t = -pi:0.01:pi ; % Define parameter

a = heaviside(t+1)+ heaviside(t-2)+ heaviside(t+4);

plot(t , a);

xlim([-3.5 4]); %Change the x-range of the plot

ylim([0.8 3.1]); %Change the y-range of the plot

% Set plot labels and title:

title('Plot the continuous time signal');

xlabel('time');

ylabel('amplitude');

grid on; % Add grid lines (optional)

B) .
syms t

u = @(t)double(t>0)

tr = -pi:0.01:pi; % Define parameter

b = u(tr+1)+u(tr-2)+u(tr+4);

figure;

plot(tr,b);

xlim([-3.5 4]); %Change the x-range of the plot

ylim([0.8 3.1]); %Change the y-range of the plot

% Set plot labels and title:

title('Plot the continuous time signal without heaviside');

xlabel('time');

ylabel('amplitude');

grid on; % Add grid lines (optional)

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Output:
Plot the continuous time signal with heaviside
3

2.5

amplitude 2

1.5

-3 -2 -1 0 1 2 3 4
time

FIGURE 2

Plot the continuous time signal without heaviside


3

2.5
amplitude

1.5

-3 -2 -1 0 1 2 3 4
time

FIGURE 3
Task 03:

MATLAB Code:
clc;clear;close all;

% Define parameters

t = -pi:0.01:pi; % Time vector from -pi to pi with step size 0.01

subplot(2,3,1);

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

a= plot ( cos(t),'k-', 'LineWidth', 1)

title('Cosine Wave');

xlabel('Time');

ylabel('Amplitude');

subplot(2,3,2);

b= plot ( sin(3*t),'m:', 'LineWidth', 1)

title('Sin Wave');

xlabel('Time');

ylabel('Amplitude');

subplot(2,3,3);

c= plot( cos(t)+ sin(3*t),'g-.', 'LineWidth', 1)

title('Combined Sine and Cosine Waves');

xlabel('Time');

ylabel('Amplitude');

subplot(2,3,4);

c= plot( cos(t)- sin(3*t),'g-.', 'LineWidth', 1)

title('Combined Sine and Cosine Waves');

xlabel('Time');

ylabel('Amplitude');

subplot(2,3,5);

d= plot(sin(pi/2*t),'b_', 'LineWidth', 1)

title('Sin Wave');

xlabel('Time');

ylabel('Amplitude');

subplot(2,3,6);

e= plot( cos(pi/4*t),'r.', 'LineWidth', 1)

title('Cosine Wave');

xlabel('Time');

ylabel('Amplitude');

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Output:

Cosine Wave Sin Wave Combined Sine and Cosine Waves


1 1 2

0.5 0.5 1
Amplitude

Amplitude

Amplitude
0 0 0

-0.5 -0.5 -1

-1 -1 -2
0 200 400 600 0 200 400 600 0 200 400 600
Time Time Time
Combined Sine and Cosine Waves Sin Wave Cosine Wave
2 1 1

1 0.5 0.5
Amplitude

Amplitude

Amplitude
0 0 0

-1 -0.5 -0.5

-2 -1 -1
0 200 400 600 0 200 400 600 0 200 400 600
Time Time Time

FIGURE 4 OUTPUT WAVE FORM'S


Task 04:

MATLAB Code:
clc;clear;close all;

syms t %Define as symbolic variables.

y = heaviside(t); %The continuous-time unit step function

a = diff(y,t)

y = dirac(t); %The derivative of the unit step function.

b = int(y,t,-inf,inf)

Registration No: FA22-BSEE-035


Signals & Systems Lab Department of Electrical & Computer Engineering

Output:

FIGURE 5 USAGE THE BUILT-IN FUNCTION

Task 05:

MATLAB Code:
clear;clc;close all;

syms t

a = int(dirac(t),t)

Output:

Lab Analysis:
In this lab, I learn about the discrete-time equivalent of the unit impulse function is known as
the unit pulse function or the kronecker delta function. I learned about the the derivative of
the unit step function is known as the unit impulse function, or the dirac delta function . I
learned about how to take derivative and integration in matlab.

Registration No: FA22-BSEE-035

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