You are on page 1of 15

Simulation Lab-2

1.Using MATLAB plot y=sin(x) taking 100 linearly spaced points in the given interval of
0x2.
Ans: x=linspace(0,2*pi,100)
y=sin(x)
plot(x,y)

1
0.8
0.6
0.4
0.2
0

0. 1

0. 2

0. 3

0. 4

0. 5

0. 6

0. 7

0. 8

0. 9

Magnitude

-0.2
-0.4
-0.6
-0.8
-1
0

3
Time

x =Columns 1 through 7
0

0.0635

0.1269

0.1904

0.2539

0.3173

0.3808

Columns 8 through 14
0.4443

0.5077

0.5712

0.6347

0.6981

0.7616

0.8251

1.0789

1.1424

1.2059

1.2693

1.5232

1.5867

1.6501

1.7136

1.9675

2.0309

2.0944

2.1579

2.4117

2.4752

2.5387

2.6021

Columns 15 through 21
0.8885

0.9520

1.0155

Columns 22 through 28
1.3328

1.3963

1.4597

Columns 29 through 35
1.7771

1.8405

1.9040

Columns 36 through 42
2.2213

2.2848

2.3483

Columns 43 through 49
2.6656

2.7291

2.7925

2.8560

2.9195

2.9829

3.0464

3.3003

3.3637

3.4272

3.4907

3.7445

3.8080

3.8715

3.9349

4.1888

4.2523

4.3157

4.3792

4.6331

4.6965

4.7600

4.8235

5.0773

5.1408

5.2043

5.2677

5.5216

5.5851

5.6485

5.7120

5.9659

6.0293

6.0928

6.1563

Columns 50 through 56
3.1099

3.1733

3.2368

Columns 57 through 63
3.5541

3.6176

3.6811

Columns 64 through 70
3.9984

4.0619

4.1253

Columns 71 through 77
4.4427

4.5061

4.5696

Columns 78 through 84
4.8869

4.9504

5.0139

Columns 85 through 91
5.3312

5.3947

5.4581

Columns 92 through 98
5.7755

5.8389

5.9024

Columns 99 through 100


6.2197

6.2832

y =Columns 1 through 7
0

0.0634

0.1266

0.1893

0.2511

0.3120

0.3717

Columns 8 through 14
0.4298

0.4862

0.5406

0.5929

0.6428

0.6901

0.7346

0.8815

0.9096

0.9341

0.9549

0.9989

0.9999

0.9969

0.9898

0.9224

0.8960

0.8660

0.8326

Columns 15 through 21
0.7761

0.8146

0.8497

Columns 22 through 28
0.9718

0.9848

0.9938

Columns 29 through 35
0.9788

0.9638

0.9450

Columns 36 through 42

0.7958

0.7557

0.7127

0.6668

0.6182

0.5671

0.5137

0.2817

0.2203

0.1580

0.0951

Columns 43 through 49
0.4582

0.4009

0.3420

Columns 50 through 56
0.0317 -0.0317 -0.0951 -0.1580 -0.2203 -0.2817 -0.3420
Columns 57 through 63
-0.4009 -0.4582 -0.5137 -0.5671 -0.6182 -0.6668 -0.7127
Columns 64 through 70
-0.7557 -0.7958 -0.8326 -0.8660 -0.8960 -0.9224 -0.9450
Columns 71 through 77
-0.9638 -0.9788 -0.9898 -0.9969 -0.9999 -0.9989 -0.9938
Columns 78 through 84
-0.9848 -0.9718 -0.9549 -0.9341 -0.9096 -0.8815 -0.8497
Columns 85 through 91
-0.8146 -0.7761 -0.7346 -0.6901 -0.6428 -0.5929 -0.5406
Columns 92 through 98
-0.4862 -0.4298 -0.3717 -0.3120 -0.2511 -0.1893 -0.1266
Columns 99 through 100
-0.0634 -0.0000

------------------------------XXX-----------------------------2.Using MATLAB plot y=cos(x) taking 100 linearly spaced points in the given interval of
0x2.
Ans: x=linspace(0,2*pi,100)
y=cos(x)
plot(x,y)

1
0.8
0.6
0.4
0.2

Magnitude

0. 1

0. 2

0. 3

0. 4

0. 5

0. 6

0. 7

0. 8

0. 9

-0.2
-0.4
-0.6
-0.8
-1
0

Time

x = Columns 1 through 12
0

0.0635

0.1269

0.1904

0.2539

0.3173

0.3808

0.4443

0.5077

0.5712

0.6347

0.6981

Columns 13 through 24
0.7616

0.8251

0.8885 0.9520

1.0155

1.0789

1.1424

1.2059

1.2693

1.3328

1.3963

1.4597

1.7771

1.8405

1.9040

1.9675

2.0309

2.0944

2.1579

2.2213

2.5387

2.6021

2.6656

2.7291

2.7925

2.8560

2.9195

2.9829

3.3003

3.3637

3.4272

3.4907

3.5541

3.6176

3.6811

3.7445

4.0619

4.1253

4.1888

4.2523

4.3157

4.3792

4.4427

4.5061

4.8235

4.8869

4.9504

5.0139

5.0773

5.1408

5.2043

5.2677

5.5851

5.6485

5.7120

5.7755

5.8389

5.9024

5.9659

6.0293

Columns 25 through 36
1.5232

1.5867

1.6501 1.7136

Columns 37 through 48
2.2848

2.3483

2.4117 2.4752

Columns 49 through 60
3.0464

3.1099

3.1733 3.2368

Columns 61 through 72
3.8080

3.8715

3.9349 3.9984

Columns 73 through 84
4.5696

4.6331

4.6965 4.7600

Columns 85 through 96
5.3312

5.3947

5.4581 5.5216

Columns 97 through 100

6.0928

6.1563

6.2197 6.2832

y = Columns 1 through 12
1.0000

0.9980

0.9920 0.9819

0.9679

0.9501

0.9284

0.9029

0.8738

0.8413

0.8053

0.7660

0.5272

0.4723

0.4154

0.3569

0.2969

0.2358

0.1736

0.1108

Columns 13 through 24
0.7237

0.6785

0.6306 0.5801

Columns 25 through 36
0.0476 -0.0159 -0.0792 -0.1423 -0.2048 -0.2665 -0.3271 -0.3863 -0.4441 -0.5000 -0.5539 -0.6056
Columns 37 through 48
-0.6549 -0.7015 -0.7453 -0.7861 -0.8237 -0.8580 -0.8888 -0.9161 -0.9397 -0.9595 -0.9754 -0.9874
Columns 49 through 60
-0.9955 -0.9995 -0.9995 -0.9955 -0.9874 -0.9754 -0.9595 -0.9397 -0.9161 -0.8888 -0.8580 -0.8237
Columns 61 through 72
-0.7861 -0.7453 -0.7015 -0.6549 -0.6056 -0.5539 -0.5000 -0.4441 -0.3863 -0.3271 -0.2665 -0.2048
Columns 73 through 84
-0.1423 -0.0792 -0.0159

0.0476

0.1108

0.1736

0.2358

0.2969

0.3569

0.4154

0.4723

0.5272

0.6785 0.7237

0.7660

0.8053

0.8413

0.8738

0.9029

0.9284

0.9501

0.9679

Columns 85 through 96
0.5801

0.6306

Columns 97 through 100


0.9819

0.9920

0.9980 1.0000

------------------------------XXX-----------------------------3. Using MATLAB plot the waveform v=asint (where: a=vmax=220, =2f, frequency=50Hz).
Plot the response of voltage using Bar-plot, stem-plot, polar-plot, -plot, stairs-plot.
Ans: a=220
t=0:0.001:0.02
f=50
w=2*pi*f
y=a*sin(w*t)
plot(w*t,y)

250

200

150

100

50

Magnitude

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

-50

-100

-150

-200

-250

Time

a = 220
t = Columns 1 through 12
0

0.0010

0.0020

0.0030

0.0040

0.0050

0.0060

0.0070

0.0080

0.0090

0.0100

0.0110

Columns 13 through 21
0.0120
f=

0.0130

0.0140 0.0150

0.0160

0.0170

0.0180

0.0190

0.0200

50

w = 314.1593
y = Columns 1 through 12
0 67.9837 129.3128 177.9837 209.2324 220.0000 209.2324 177.9837 129.3128 67.9837
67.9837
Columns 13 through 21
-129.3128 -177.9837 -209.2324 -220.0000 -209.2324 -177.9837 -129.3128 -67.9837 -0.0000

0.0000 -

Bar Plot
a=220
t=0:0.001:0.02
f=50
w=2*pi*f
y=a*sin(w*t)
bar(w*t,y)
250

200

150

100

50

Magnitude

-50

-100

-150

-200

-250
-1

3
Time

Stem Plot
a=220
t=0:0.001:0.02
f=50
w=2*pi*f
y=a*sin(w*t)
stem(w*t,y)

250

200

150

100

50

Magnitude

-50

-100

-150

-200

-250

Time

Polar Plot
a=220
t=0:0.001:0.02
f=50
w=2*pi*f
y=a*sin(w*t)
polar(w*t,y)
90
250
120

60
200
150

150

30
100
50

180

210

330

240

300
270

Pie Plot
a=220
t=0:0.001:0.02
f=50
w=2*pi*f
y=a*sin(w*t)
pie(w*t,y)
2%

< 1%
< 1%
2% 1%

10%

3%
3%
9%
4%

4%

9%
5%

5%
8%

6%

8%

6%
7%

Stair Plot
a=220
t=0:0.001:0.02
f=50
w=2*pi*f
y=a*sin(w*t)
stairs(w*t,y)

7%

250

200

150

100

50

Magnitude

-50

-100

-150

-200

-250

Time

4.Using MATLAB draw the response of 3- supply when y=sin(x), R=sin(x-120),


B=sin(x+120).
R=sin(x)
Y=sin(x-120)
B=Sin(x+120)
1
R
Y
B

0.8

0.6

0.4

Magnitude

0.2

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

-0.2

-0.4

-0.6

-0.8

-1

4
Time

Q-5

a) a=30
t=0:0.001:1
w=10
v=a*sin(w*t)
plot(w*t,v)

v(t)=aSin(wt)
30
a=30
w=10rad/sec

20

Magnitude

10

01
0.5
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

-10

-20

-30

b)
a=10
t=0:0.001:1
w=30
y=a*sin(w*t)
plot(w*t,v)

5
Time

10

10

Magnitude

-5

-10

10

15
Time

20

25

30

C) a=6
t=0:0.001:1
w=50
y=a*sin(w*t)
plot(w*t,v)

v(t)=ASin(wt)

Magnitude

-2

-4

-6

10

15

20

25
Time

30

35

40

45

50

6.Draw the equation of the straight line y=mx+c, where m=slope=0.5, c=point of
intersection= -2. (0x5)
Ans: x=[0 1 2 3 4 5]
m=0.5
c=-2
y=(m*x)+c
plot(x,y)

0.5

-0.5

y-axis

-1

-1.5

-2

0.5

1.5

2
x-axis

Q-7
x=0:1:4*pi
z=exp(-0.4)
y=z*sin(x)
plot(x,y)

2.5

3.5

4.5

0.8

0.6

0.4

Magnitude

0.2

0
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

-0.2

-0.4

-0.6

-0.8

6
Time

x=0:0.02:4*pi
z=exp(-0.4)
y=z*sin(x)
plot(x,y)

0.8

0.6

0.4

Magnitude

0.2

0
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

-0.2

-0.4

-0.6

-0.8

8
Time

x=0:0.001:4*pi
z=exp(-0.4)
y=z*sin(x)
plot(x,y)

10

12

14

10

12

0.8

0.6

0.4

Magnitude

0.2

0
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

-0.2

-0.4

-0.6

-0.8

8
Time

10

12

14