MATLAB >> Simple RC circuits in sinulink

by Michael Chan » Wed, 17 Nov 2004 11:27:59 GMT

Hi all,

Is it possible to model the behaviour of an RC circuit in simulink? I know
that I can simply represent a circuit as a transfer function, but this
doesn't work if I cascade two circuits together, since the transfer function
isn't simply the product of the individual circuit transfer functions.

It is my opinion that simulink cannot handle this (although I don't know
alot about simulink). To simulate blocks of circuits, a block needs to know
the loading effect of the block in front of it, and the output impedance of
the block behind it; something simulinks simulator cannot easily account
for.

Please let me know if I'm wrong, or how I might accomplish the above. Also,
if anyone knows of a simulation program that is like simulink, but accounts
for loading effects, I would be very interested.

Thanks,

Michael Chan.



MATLAB >> Simple RC circuits in sinulink

by kludge » Wed, 17 Nov 2004 22:38:58 GMT



Why not use SPICE? It would seem a much more elegant way of doing what
you describe, with a lot less work.
--scott

--
"C'est un Nagra. C'est suisse, et tres, tres precis."

MATLAB >> Simple RC circuits in sinulink

by Steve Amphlett » Wed, 17 Nov 2004 22:48:39 GMT


The problem with using Simulink is that it is causal. Information
flows from one block to the next in a pre-described manner. So you
really need to know all the interaction effects to model the whole
thing.

You might want to take a look at dymola from dynasim ( < http://www.dynasim.de >
). It uses an acausal model description language (modelica) to
describe systems, completely eliminating the problem you describe.

MATLAB >> Simple RC circuits in sinulink

by No one » Thu, 18 Nov 2004 00:04:21 GMT


"possible"? yes. "do you really want to try"? depends.


why would that be true? if you were to implement a two-port block, say
with 'gain' relationships from port 1 to port 2 and port 2 to port 1,
would that, somehow, not account for 'input' and 'output' loading?


Hspice, Pspice, some variants, are 'like' simulink in a fundamental
sense, but are intended for a different level of work.
--
'No one'

MATLAB >> Simple RC circuits in sinulink

by Per Sundqvist » Thu, 18 Nov 2004 01:23:32 GMT


Yes I got it to work, and I have right now 15 min. experience in
simulink...

It's a feedback system (serial RC circuit was assumed) with the
ingredients:
a) Uc=U(t)-i*R
b) i=C*dUc(t)/dt

Uc from a) goes into b) which deliver back i to a). As U(t) I used a
sinewave (the second input of a).
2 gain (one has gain=-R, and the other gain=C), 1 sum, 1
derivative, 1 mux, 1 sinewave and 1 scope. Thats it.

The result seemes resonable with 90deg diffrence between Uc and i.

/Per

MATLAB >> Simple RC circuits in sinulink

by Per Sundqvist » Thu, 18 Nov 2004 07:18:23 GMT


but
easily

Hi again

I found it possible to build a feed-back based resistor-block, with
inputs R, U2 and "output" U1. The current i=(U2-U1)/R, but is only
"seen" inside the block. The trick is an infinitisemal time delay dt
(not nesseary to invoke explicitly -it works anyway), so the next
"independent" equation is U1=U2-R*i. The I-V for my model agrees
perfectly with Ohm's law.

The value of U1 between different resistors are unknown, until the
last restistor is grounded. we get then a sort of coupled system with
unknown U1 for each R, but we leave to simulink to solve that.

Next to build blocks for C and L etc, would be similar with feedback
system. Note: in real components there is a time-delay due to the
limit of the speed of light, which is clear if we solve Maxwells
equations instead of a "discrete" approximation such as a RC-net for
example. Therefore the "independency" a)i=(U2-U1)/R and b)U1=U2-R*i
is not wrong.

PS. Is it possible to get a .m file with some sort of "command line"
version of the simulink model? I use it in femlab, but don't know how
to do it with simulink. DS

Per

MATLAB >> Simple RC circuits in sinulink

by Michael Chan » Thu, 18 Nov 2004 08:52:18 GMT


SPICE will work, but SPICE is slow, and is quite low level. With simulink,
prototyping systems is quite fast and the GUI makes it easy. A behavioural
level simulator also allows one to model a systems behaviour, without
needing to be clear on an implementation.

MATLAB >> Simple RC circuits in sinulink

by Michael Chan » Thu, 18 Nov 2004 08:56:08 GMT


function

I'm not sure I follow you. I have considered a scenario where each block
has an output port that feeds back loading information to the block
preceeding it, and an output port that feeds forward information to the
block in front of it, but this gets very messy very quickly, and is far from
elegant.

MATLAB >> Simple RC circuits in sinulink

by No one » Thu, 18 Nov 2004 11:53:16 GMT


[behavioral model of r-c network]

true, hence the suggestion to use Hspice (or equivalent) mentioned by
someone else. but you want to build a behavioral model that includes
this, so you can model higher-level systems (i imagine...), in short
simulation time, and you don't want to ignore loading.

a two-port can be described by a 2 x 2 matrix: 1,1 is the input; 2,2 is
the output; 1,2 is forward transfer; 2,1 is reverse transfer. want
something simpler? Per Sundqvist has one suggestion; J. M. Miller gave
us all a way to approximate port loading, back in 1919.

so... will any of that work well in Matlab? depends... on how far you
want to go, on how much 'reality' you want to include.
--
'No one'

MATLAB >> Simple RC circuits in sinulink

by Michael Chan » Thu, 18 Nov 2004 13:49:02 GMT


Yeah, that's what I figured. Working around this is probably too much
effort in simulink. Thanks for the tip about dynasim. This looks like the
sort of program I was thinking of.

Cheers.

< http://www.dynasim.de >

MATLAB >> Simple RC circuits in sinulink

by DJL » Thu, 18 Nov 2004 14:49:13 GMT


wants to do circuit simulation and should use PLECS available from
http://www.plexim.com/

There is a freeware student version.

See for details:
http://people.ee.ethz.ch/ ~jost/peds99.pdf

MATLAB >> Simple RC circuits in sinulink

by Steve Amphlett » Thu, 18 Nov 2004 17:20:49 GMT


<snip>



I gave you a bad link - sorry. It should be:

< http://www.dynasim.se > (.se as in Sweden)

MATLAB >> Simple RC circuits in sinulink

by Robert Zeng » Thu, 18 Nov 2004 23:22:53 GMT

Look at two new RF products from MathWorks:

http://www.mathworks.com/products/rftoolbox/

http://www.mathworks.com/products/rftoolbox/

I believe these two products are what you are looking for.



Robert Zeng




know
function
know
of
Also,
accounts

MATLAB >> Simple RC circuits in sinulink

by Michael Chan » Fri, 19 Nov 2004 11:38:18 GMT


Thanks, I'll look into these when I get a chance.

Similar Threads

1. Frequency Reponse RC circuit Simpower systems

I am beginning a linear modeling project using 
SimPowerSystems and simulink. I am so new to this that 
while I can manage to construct a simple RC circuit and 
simulate it; I cannot seem to return a transfer function's 
magnitude and phase plots vs frequency. I would like to be 
able to programatically and iteratively change the 
elements' values and analyze the transfer function. I know 
there is a way to do this. Can anyone help me? Is there a 
good demo for this?

2. digital signal processing - Plotting Square wave applied on series RC circuit - MATLAB

3. Simple RC filter

Hi all,

Can anyone advise me on how to write a m-file to simulate a simple rc
high pass filtering with sinewave.I want to see how well this rc high
pass filter perform in matlab and also can this rc filter be build on
electronic circuit. I tried a few way, but it doesnt seem to be
working. Pls advise

4. Voltage measurement in a simple circuit - MATLAB

5. Simple RL circuit with switch

function dcrl = RL (t,i)
%function for RL circuit calculations
clear all;
Vs=50;
R=1;
L=9;
t=1:1:100;
i0=0;

for x=1:30,
    i(x)=(Vs/R)*(1-exp(-(R/L)*t(x)));
end
for x=31:100,
    i(x)=i(30)*exp(-(R/L)*t(x));
end
plot (t,i)

I am using those coding above and I cannot get the right answer.
There is a simple R (resistance), L (inductance) circuit with switch.
The real formula for this equation to solve is di/dt=Vs/R-R*i/L. When
we solve this equation it comes up i(t)=(Vs/R)*(1-exp(-(R/L)*t). Then
I use matlab to plot i(t) and calculate potential of L and R and
their current. On the other hand I use ode45 to solve it directly(you
can see below)

function dcrl = inductansoff(t,i)
% function for RL circuit calculations
Vs=50;
i0=0;
L=9;
R=1;
X = Vs/L;
Y = i*R/L;
if t<30
    dcrl = X - Y;
else
   dcrl = -Y; %switched 0ff Vs=0
   if t>50
       dcrl = X - Y;
   else
       dcrl = -Y; %switched 0ff Vs=0
   end
end

but I could not plot exactly what I want to see.
Does anyone can help me, maybe one word can be so valuable for me.

Thanks
Gurhan Ertasgin

6. Simple RLC circuit calculation not working correctly -- why? - MATLAB

7. Question about sinulink and NaN

I am new to matlab and simulink. I built an s-function lms2.m in my
modle lms.mdl. The two inputs of the S-fun are exported from a
look-up table block.
when debuged,it appears"Output returned by S-function 'lms2' in block
'lms/S-Function' during flag=3 call must be a real vector of length
1"
Then i set a breakpoint while "case 3" in the s-fun lms2.m. I found
the inputs of the s-fun are both "NaN". It was said that the output
of the look-up table bolck was NaN.
But when tested singlely, the output of the look-up table block had
no flaw.
i want to know why.
Thanks.
Ps:My english is poor, i hope i have explained clearly.

8. simple simple simple - MATLAB