You are on page 1of 9

Matlab Course

Date: 2014.2.24
TopicUse Matlab m-file/Simulink to simulate RC circuit
Example 1:
A low pass RC circuit is shown below with R1 R 2 R 3 10 and C 0.01 F .
Let the input signal

be v in (t ) 10sin(2 t ) .

Use Simulink and m-file to simulate the time and frequency responses of this RC
circuit respectively.

R1

vin

+
-

R3

R2

vout

Before doing simulation, please use to find the transfer function of this
circuit.

Sol:

The standard form of the 1st-order system:

V out ( s )
V in ( s )

z s 1
p s 1

s 0 : K 0.5 ,

v out (t ) 0 : z 0
V out ( s)
V in ( s )

v in (t ) 0: p

3RC
2

1
1
1

= T(s)
2 3RC s 1 3RC s + 2
2

when v in (t ) 10sin(2 t ) , the output signal in the steady state should be


v out (t ) 10 T ( j2 ) sin(2 t T ( j2 )) 3.638 sin(2 t - 43.303o )

RC circuit in Simulink:

C ontinuous
powergui

R1

v +
-

Input

Output1

R3

R2

+ v
-

Output
Scope

From the simulation result by Simulink, the steady state output response is obtained as
v out (t) = 3.64sin(2t - 43.30 )

It can be found that the result obtained by Simulink is the same as that by
.

Bode plot:
To find state-space realization matrices (A,B,C,D) by power_analyze:
[A,B,C,D]=power_analyze('circuit_1')
Then, convert A,B,C,D from the format of array to the system type by ss
Sys=ss(A,B,C(1,1),D(1,1))
The transfer function can be calculated by ss2tf
[n,d]=ss2tf(A,B,C(1,1),D(1,1))
sys=tf(n,d)
The frequency response of this circuit could be obtained by using: bode
bode(sys)
Bode Diagram
0

Magnitude (dB)

-10
System: T
Frequency (rad/sec): 6.67
Magnitude (dB): -9.03

-20
-30
-40

Phase (deg)

-50
0

-45
System: T
Frequency (rad/sec): 6.66
Phase (deg): -45
-90
-1

10

10

10

Frequency (rad/sec)

10

10

Example 2:
A low pass RC circuit is plotted below with R1 R 2 R 3 10 and C 0.01 F
with the input of v in (t ) 10sin(2 t ) . in the block diagram of this RC circuit and
compare its output signal from that of the previous representation.

R3

R1

+
v1

i1

i2

v2

R2

i3

v3

Sol:
Block Diagram:

i3
v1 +

1
R1

i1 +

v2
R2

v2

How to obtain transfer function from Matlab?


1. LFT code
2. linmod

+
v3

1
R3

i3

1
Cs

v3

Comparison of output signals from two different representations:


10
Input
output(Ex1)
output(Ex2)

8
6
X: 1.37
Y: 3.639

Amplitude(V)

2
0
-2
-4
-6
-8
-10

0.2

0.4

0.6

0.8

1
time(s)

1.2

1.4

1.6

1.8

Bode Diagram
0

Magnitude (dB)

-10
System: T
Frequency (Hz): 1
Magnitude (dB): -8.8

-20
-30
-40

Phase (deg)

-50
0

-45
System: T
Frequency (Hz): 1
Phase (deg): -43.4
-90
-2

10

-1

10

10

Frequency (Hz)

Amplitude of output:
output 10 10( 8.8/20) 3.63

10

10

The transfer function of this system could be directly obtained by the function
[num,den]=linmod('Example_HW02_s_2');
T=tf(num,den)

The transfer function by using Simulink: T ( s)

3.33
s 6.667

this results is the same with the one obtained by :


1
1
T ( s)

3RC s 2 0.3 s 2
Moreover, the user could setup the simulation parameters in Simulink through
m-file: simset, sim, plot, hold on

Case 1:
R1=10;R2=10;R3=10;C=0.01;
opt=simset('Solver','ode3');
sim('Example_HW02_s_3',[0 2],opt);
plot(tout,input,tout,output);hold on;

Case 2:
R1=1;R2=1;R3=1;C=0.01;
opt=simset('Solver','ode3');
sim('Example_HW02_s_3',[0 2],opt);
plot(tout,output,'r');hold on;

The parameters of the system could be adjusted easily through m-file.


10

input
output case 1
output case 2

8
X: 0.2655
Y: 4.978

X: 1.369
Y: 3.639

Amplitude(V)

4
2
0
-2
-4
-6
-8
-10

0.2

0.4

0.6

0.8

1
time(s)

1.2

1.4

1.6

1.8

Bode plot of R1=1;R2=1;R3=1;C=0.01

(Case 2)

Bode Diagram
0

Magnitude (dB)

-10

System: T2
Frequency (Hz): 1
Magnitude (dB): -6.06

-20
-30
-40

Phase (deg)

-50
0
System: T2
Frequency (Hz): 1
Phase (deg): -5.4
-45

-90
-1

10

10

10

10

10

Frequency (Hz)

Amplitude of output:
output 10 10( 6.06/20) 0.498

Exercise 1:
A high pass RC circuit is given below with R1 10 , R 2 20 , R 3 30 and
C 0.01 F .

Let the input signal be v in (t ) 5sin(10 t ) .


a) Find the transfer function, DC gain, amplitude and phase in the steady state of this
circuit.
b) Use Simulink to implement this circuit and plot the output and input signals
simultaneously.
c) Plot bode plot.

R1

vin

+
-

R3
R2

vout

Exercise 2:
A high pass RC circuit is given below with R1 R 2 R 3 10 k and C 10 F .
Let the input signal be v in (t ) Asin(2 f t ) 10sin(2000 t ) .
a) Find the block diagram of this circuit and compare the output responses from
these two representations.
ps: use m-file to plot the output responses during the time 0~0.01 sec
b) Use Matlab to find out the transfer function, plot the bode plot and find the
frequency of bandwidth.
ps: mark the frequencies on the plot
c) Plot the output responses from R 0.1, 1, 10, 1000 simultaneously during the
time 0~0.01 sec and discuss the differences in amplitude.

R1

vin

+
-

R3
R2

vout

You might also like