You are on page 1of 54

Practical File

Course Title: Basic Simulation Lab


Course Code: ES-204
Credit Units:01

Department of Computer Science and Engineering


Amity Institute of Engineering and Technology
Uttar Pradesh, Noida

Name: Harshit Aggarwal


Class:4CSE1Y
Enrolment Number: A2305218044
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Scanned with CamScanner
Practical File
Course Title: Basic Simulation Lab
Course Code: ES-204
Credit Units:01

Department of Computer Science and Engineering


Amity Institute of Engineering and Technology
Uttar Pradesh, Noida

Name: Harshit Aggarwal


Class:4CSE1Y
Enrolment Number: A2305218044
Experiment 6
Generating a Sinusoidal Signal of a given frequency with Titling, Labeling, Adding Text, Adding
Legends, Printing Text in Greek Letters, Plotting as Multiple and Subplot. Time scale the generated
signal for different values. E.g. 2X, 4X, 0.25X, 0.0625X.

Matlab Code:-

clc
clear
close
t=-4*pi:pi/10:4*pi %defining range of x-axis
f=0.1 %setting the value of frequency
y=sin(2*pi*f*t) %defining sin function
plot(t,y,'r--') %plotting the function
text(0,1,'Max Value','fontsize',10,'color','magenta') %setting text on given
coordinate
title('sine graph') % setting title

Output:-
Criteria Total Marks Marks Obtained Comments
Concept(A) 2
Implementation(B) 2
Performance(C) 2
Total 6(To be scaled down to
1)
Experiment 7:- : Solving First, Second and third Order Ordinary Differential Equation using Built-in
Functions and plot.

Matlab Code:-

(a)

Clc
Clear
close
syms y(t) a %symbolically defining variables
p=diff(y,t)==a*y %first order differential equation
dsolve(p) %solving the differential equation

Output:-

(b)

clc
clear
close
syms y(t) a %symbolically defining variables
p=diff(y,t,2)==a*y %3rd order differential equation
q=diff(y,t) %defining 1st order differential equation
cond=[y(0)==1 q(0)==2] %defining given conditions
dsolve(p,cond) %solving the differential equation

Output:-
Criteria Total Marks Marks Obtained Comments
Concept(A) 2
Implementation(B) 2
Performance(C) 2
Total 6(To be scaled down to
1)
Experiment 8

Writing brief Scripts starting each Script with a request for input (using input) to Evaluate the function
h(T) using if-else statement, where, o h(T) = (T – 10) for 0 < T < 100  = (0.45 T + 900) for T > 100.
Exercise: Testing the Scripts written using A). T = 5, h = -5 and B). T = 110, h =949.5

Software Used:- Matlab 2019

Code:-

T=input('Enter the value of T:');

if(T>0) && (T<=100)

H=T-10;

disp(H);

elseif(T>100)

H=0.45*T+900;

disp(H);

else

disp('incorrect value of T entered')

end

Output:-
Criteria Total Marks Marks Obtained Comments
Concept(A) 2
Implementation(B) 2
Performance(C) 2
Total 6(To be scaled down to
1)
Experiment 9

Aim:- Generating a Square Wave from sum of Sine Waves of certain Amplitude and Frequencies.

Software Required: MATLAB

Theory:
*For loop
Syntax
Sum=0
For i=1:5
Sum=sum+i;
End

*sin function
Y=sin(x);
X is in radians

*Square Wave is a waveform in which the amplitude alternates at a steady frequency between fixed
minimum and maximum values.

Code:-

f = 5;
w = 2*pi*f;
t = 0:0.0001:1
y = 0;
for n = 1:2:99;
y = y + (1/n)*sin (n*w*t);
end

subplot(2,2,1)
plot(t,y, 'r--');
xlabel('Time axis');
ylabel('Amplitude');
legend('Squarewave');
title('squarewave continous');

subplot(2,2,2)
stem(t,y, 'o--');
xlabel('Time axis');
ylabel('Amplitude');
legend('squarewave');
title('squarewave discret');

Output:-
Criteria Total Marks Marks Obtained Comments
Concept(A) 2
Implementation(B) 2
Performance(C) 2
Total 6(To be scaled down to
1)
Experiment 10:
Aim:- Basic 2D and 3D plots: parametric space curve. polygons with vertices. 3D contour lines,
pie and bar charts.
Software Used:- Matlab 2019.
Code:-
clc
clear
close
t = 0:pi/50:10*pi;
st = sin(t);
ct = cos(t);
subplot(3,2,1)
plot3(st,ct,t)
x = 0:pi/10:2*pi;
y = sin(x);
subplot(3,2,2)
pie(x,y)
subplot(3,2,3)
pie3(x,y)
subplot(3,2,4)
bar(x,y)
subplot(3,2,5)
bar3(x,y)

Output:-
Criteria Total Marks Marks Obtained Comments
Concept(A) 2
Implementation(B) 2
Performance(C) 2
Total 6(To be scaled down to
1)
Open Ended Experiment
Basic Simulation Lab

Harshit Aggarwal
A2305218044
4CSE1Y

Submitted to:-
Mr. Yogesh
OPEN ENDED EXPERIMENT

Aim: To covert coloured image to grayscale and then to black and white.
Software Used: MATLAB R2019b
Theory:
RGB = RGB('COLORNAME') returns the red-green-blue triple
corresponding to the color named COLORNAME by the CSS3 proposed
standard [1], which contains 139 different colors (an rgb triple is a 1x3 vector of
numbers between 0 and 1). The color names are the ones accepted by almost all
web browsers, for example Brown, DarkRed, SlateGray.

RGB CHART creates a figure window showing all the available colors with
their names.

COLORNAME = RGB(r,g,b) and COLORNAME = RGB([r,g,b]) both find the


name of the color with the triple that is closest to [r,b,g] (measured by sum of
squares).

A = imread(filename) reads the image from the file specified by filename,


inferring the format of the file from its contents. If filename is a multi-image
file, then imread reads the first image in the file.

rgb2gray converts RGB images to grayscale by eliminating the hue and


saturation information while retaining the luminance. If the input is an RGB
image, it can be of class uint8, uint16, single, or double. The output image I is
of the same class as the input image. If the input is a colormap, the input and
output colormaps are both of class double.

BW = im2bw(I,level) converts the grayscale image I to binary image BW, by


replacing all pixels in the input image with luminance greater than level with
the value 1 (white) and replacing all other pixels with the value 0 (black).
This range is relative to the signal levels possible for the image's class.
Therefore, a level value of 0.5 corresponds to an intensity value halfway
between the minimum and maximum value of the class.
Matlab Programme:-
clc;
clear;
close;
img=imread('C:\Users\7615349\Desktop\h044\srk.jpg'); % Reading image
subplot(3,1,1);
imshow(img);
title('RGB');
greyimg=rgb2gray(img); %RGB to Grayscale
subplot(3,1,2);
imshow(greyimg);
title('Grayscale');
threshold=graythresh(img);
bw=im2bw(img,threshold); %Converting to B&W
subplot(3,1,3);
imshow(bw);
title('B&W');

Output:-

You might also like