How Tune PID in octave using Frequency Response data

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

How Tune PID in octave using Frequency Response data

shall689
Hello,

I have the frequency response data of a plant. What steps would I take to
tune a PID in octave?

Thanks,
Stephen



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Octave - General mailing list

On 24/07/2020 16:31, shall689 wrote:
> Hello,
>
> I have the frequency response data of a plant. What steps would I take to
> tune a PID in octave?
>
> Thanks,
> Stephen
>
>
Is your frequency response complex or just magnitude one ?

--Sergei.



Reply | Threaded
Open this post in threaded view
|

Re[2]: How Tune PID in octave using Frequency Response data

Chris Manning


Your request jogged my memory.  I assume that SciLab are a competitor of Octave.  The thing that I like about SciLab is that the windoze install didn't throw up a list of 33 unresolved dependencies.

If I understand correctly not only is SciLab open source, and therefore could be a source of routines to be put into Octave, any toolsets also could be useful.  Tuning PID loops should fit neatly in their system for dynamic packages.


SciLab.org

Why Model-Based Design?
http://www.modelbaseddesign.at/

Embedded Adaptive Self-Tuning Control Development by a Free Toolchain
http://www.hrpub.org/download/20150730/UJCA3-15004086.pdf

Input design and parameter estimation with open source tools
https://www.tu-ilmenau.de/fileadmin/public/regelungstechnik/Mitarbeiter/Prof_Johann_Reger/reger_MATHMOD2015.pdf

Model based design (MBD) – a free tool-chain
Simon Mayr, (Gernot Grabmair)
Simon Mayr, University of Applied Sciences
Upper Austria , Austria
https://www.scilab.org/content/download/1702/15077/file/AustriaUniversity_ScilabTEC2014.pdf

ProtoFrame
http://www.modelbaseddesign.at/projects/protoframe/27-2/

Eng. Shady Mohsen blog: Spirograph
The following are some curves drawn by the spirograph code I wrote in Scilab
https://eng-shady-mohsen.blogspot.com/2011/07/spirograph.html

----- Original Message -----
From: Sergei Steshenko via Help-octave ([hidden email])
Date: 07/24/20 09:47
To: [hidden email]
Subject: Re: How Tune PID in octave using Frequency Response data

On 24/07/2020 16:31, shall689 wrote:
> Hello,
>
> I have the frequency response data of a plant. What steps would I take to
> tune a PID in octave?
>
> Thanks,
> Stephen
>
>
Is your frequency response complex or just magnitude one ?

--Sergei.




Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

shall689
In reply to this post by Octave - General mailing list
I have both magnitude and phase data.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Doug Stewart-4


On Fri, Jul 24, 2020 at 10:03 AM shall689 <[hidden email]> wrote:
I have both magnitude and phase data.

What have you tried so far?


 


--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html




--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Doug Stewart-4
In reply to this post by shall689


On Fri, Jul 24, 2020 at 10:03 AM shall689 <[hidden email]> wrote:
I have both magnitude and phase data.


You should tell us more about what you know about the system.
Does it have a first order roll off?
Does it have any complex poles?
Etc.
Are you just learning the theory?
Can you do it by "hand"
etc.


 

--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html




--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Nicklas Karlsson
In reply to this post by shall689
> Hello,
>
> I have the frequency response data of a plant. What steps would I take to
> tune a PID in octave?
>
> Thanks,
> Stephen

For tuning there are several options, Ziegler-Nichols method is one but it might be better to do some mathematical analysis on how your gains effect the bode plot of the closed system. Noise may also be a problem if you do not want this to enter control loop, integral gain is least sensistivity for noise, proportional gain in between and derivative gain most sensitive to noise. Usually there is a choice between noise entering control loop, it may also make audible noise and speed. Charging batteries is a slow process while unstable processes like inverted pendulum must be fast enough to stabilized pendulum.

The tuned system may be checked with nyquist(...) by closing the control loop with your PID regulator. You probably want to check phase and amplitude margins, maybe also sensitivity.

System may be closed by transfer function if you have this but as I understand it you have frequency response. You may calculate frequency response of your PID regulator with bode(...) function and use numeric calculations on amplitudes and phases for your PID regulator and frequency response of plant. If do not know how to make these calculations I might try to get an hour or so thinkging about it and help you.


Nicklas SB Karlsson


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

shall689
In reply to this post by Doug Stewart-4
Hello Doug,

I previously tried to covert the frequency response data to a transfer
function (see
https://octave.1599824.n4.nabble.com/Control-System-Design-methods-using-Octave-tc4685799.html)

You helped me on it
(https://octave.1599824.n4.nabble.com/Control-System-Design-methods-using-Octave-tc4685799.html#a4685818).

However, the resulting transfer function didn't exactly fit the original
response data (see attached csv file).

Do you think the resulting transfer function is good enough?

Some background:  The frequency data was generated from a buck converter
simulation (using PSIM).  I am now simulating an inverter which has a
capacitor current feedback (actually inverter current - output current is
fed back)  I have no problem tuning a PID (using Ziegler–Nichols method) for
an inverter current feedback inner current loop, but I am not able to tune a
PID that has a capacitor current inner loop. The issue has to do with what
magnitude to use for the step response.

buckVfreqResp.csv
<https://octave.1599824.n4.nabble.com/file/t372348/buckVfreqResp.csv>  

Thanks,
Stephen



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

shall689
In reply to this post by Nicklas Karlsson
Hello Nicklas,

I have a basic understanding control system analysis, but I don't normally
analyze control systems.

"You may calculate frequency response of your PID regulator with bode(...)
function and use numeric calculations on amplitudes and phases for your PID
regulator and frequency response of plant."
I would appreciate if you could help me.

Thanks,
Stephen



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: How Tune PID in octave using Frequency Response data

shall689
In reply to this post by Chris Manning
Thanks Chris.

Some of the web pages were missing.

One of missing ones that I quite interested in is
https://www.tu-ilmenau.de/fileadmin/public/regelungstechnik/Mitarbeiter/Prof_Johann_Reger/reger_MATHMOD2015.pdf

Stephen



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Torsten Lilge
In reply to this post by shall689
On Fri, 2020-07-24 at 08:31 -0500, shall689 wrote:
> Hello,
>
> I have the frequency response data of a plant. What steps would I take
> to
> tune a PID in octave?
>
> Thanks,
> Stephen
>

Hello Stephen,

Besides considering the stability margins with nyquist(), bode() or
margin(), you can also consider the following tools/methods from the
control package:

 * optiPID to tune the PID controller based on an integral optimization
   criteria
 * rlocus() to plot the root locus for the closed loop depending on the
   open loop gain
 * rlocusx(), newly added to the control packages (but not yet in the
   released version), which allows to get resulting controller gains for
   specific root locations and plot related open loop bode, nyquist and
   margin plots together with the step response of the closed loop

Best
Torsten




Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

shall689
Thanks Torsten,

I will take a look at those, especially optiPID.

Stephen



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Nicklas Karlsson
In reply to this post by shall689
> Hello Nicklas,
>
> I have a basic understanding control system analysis, but I don't normally
> analyze control systems.
>
> "You may calculate frequency response of your PID regulator with bode(...)
> function and use numeric calculations on amplitudes and phases for your PID
> regulator and frequency response of plant."
> I would appreciate if you could help me.

G(jw) Frequency responce of your system
F(jw) Frequency response of PID regulator
Gry(jw) = F(jw)*G(jw)/(1 + F(jw)*G(jw)) Frequency response of closed system

Then you have frequency response with amplitude and angle for your system. First you have to calculate amplitude and angle for you PID controller at same frequencies. Calculations should be done point wise. For multiplication amplitudess are multiplied while angles are added. Divisor require some more thinking also by me but know value is multiplied with complex conjugate to get absolute value in square, convert from (phase, angle) form to (real, imaginary) should be one possibility. Calulations could be checked by doing them on a system on polynomial form, if numerical calculation on this agree with analytical you probably got it right.

To get Bode plot for the closed system you could use subplot(2,1,1) semilogy(...) subplot(2,1,2) and plot(...) functions.

To get nyquist diagram for stability analysis you plot with Gry(jw) for increasing frequencies with real part on x axis and imaginary part on y axis. If you have data on (phase, angle) form you have to convert to (real, imaginary) form.


Nicklas SB Karlsson


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

shall689
Hello Nicklas,

I have the open loop frequency response of 1/2 bridge inverter capacitor
current (using PSIM).  Now I would like to convert that response into a
transfer function so that I can create the closed loop response (as you
mentioned).

I do have an exact transfer equation for the capacitor voltage with respect
to duty cycle so maybe that can somehow be changed to capacitor current
since capacitor current equals C*dv/dt. Maybe just multiplying by Cs would
do it?

Stephen

Inverter Capacitor Current frequency response:
InverterCapCurrentFreqResponse_0p05.csv
<https://octave.1599824.n4.nabble.com/file/t372348/InverterCapCurrentFreqResponse_0p05.csv>  



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Nicklas Karlsson
> Hello Nicklas,
>
> I have the open loop frequency response of 1/2 bridge inverter capacitor
> current (using PSIM).  Now I would like to convert that response into a
> transfer function so that I can create the closed loop response (as you
> mentioned).
>
> I do have an exact transfer equation for the capacitor voltage with respect
> to duty cycle so maybe that can somehow be changed to capacitor current
> since capacitor current equals C*dv/dt. Maybe just multiplying by Cs would
> do it?

Best thing would be to write it down on state space form. As it is an inverter I would guess you could modify duty cycle each period and in such case duty cycle should be an input and you would make an average model over one cycle, there is probably some dead time which may or may not be important. In case it is non linear you also to have to linearize around curent working point.

Then written on state space form you could use lqr(...), lqg(...) or acker(...) functions in Octave to make you control loop while bode(...) and nyquist(...) functions could be used for stability analysis. In cause you did not att dead time in state space model you could add a phase delay then stability is checked.

Think I got it correct.


Nicklas SB Karlsson


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Nicklas Karlsson
In reply to this post by shall689
> Hello Nicklas,
>
> I have the open loop frequency response of 1/2 bridge inverter capacitor
> current (using PSIM).  Now I would like to convert that response into a
> transfer function so that I can create the closed loop response (as you
> mentioned).
>
> I do have an exact transfer equation for the capacitor voltage with respect
> to duty cycle so maybe that can somehow be changed to capacitor current
> since capacitor current equals C*dv/dt. Maybe just multiplying by Cs would
> do it?

Forgot about it. If you use lqr(..), lqq(...) or acker(...) functions feedback is assumed to come from internal states. It is still useful to write on state space form and there are functions to transform to transfer function in Octave if needed.


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Octave - General mailing list
In reply to this post by Nicklas Karlsson
On Mon, 2020-07-27 at 21:43 +0200, N wrote:

> > Hello Nicklas,
> >
> > I have a basic understanding control system analysis, but I don't
> > normally
> > analyze control systems.
> >
> > "You may calculate frequency response of your PID regulator with
> > bode(...)
> > function and use numeric calculations on amplitudes and phases for
> > your PID
> > regulator and frequency response of plant."
> > I would appreciate if you could help me.
>
> G(jw) Frequency responce of your system
> F(jw) Frequency response of PID regulator
> Gry(jw) = F(jw)*G(jw)/(1 + F(jw)*G(jw)) Frequency response of closed
> system
>
> Then you have frequency response with amplitude and angle for your
> system. First you have to calculate amplitude and angle for you PID
> controller at same frequencies. Calculations should be done point
> wise. For multiplication amplitudess are multiplied while angles are
> added. Divisor require some more thinking also by me but know value is
> multiplied with complex conjugate to get absolute value in square,
> convert from (phase, angle) form to (real, imaginary) should be one
> possibility. Calulations could be checked by doing them on a system on
> polynomial form, if numerical calculation on this agree with
> analytical you probably got it right.
>
> To get Bode plot for the closed system you could use subplot(2,1,1)
> semilogy(...) subplot(2,1,2) and plot(...) functions.
>
> To get nyquist diagram for stability analysis you plot with Gry(jw)
> for increasing frequencies with real part on x axis and imaginary part
> on y axis. If you have data on (phase, angle) form you have to convert
> to (real, imaginary) form.
>
>
> Nicklas SB Karlsson
>

For a stability analysis of the closed loop based on the Nyquist
criterion, you need the frequency repsonce (nyquist()) of the open loop,
not of Gry (jw), which represents the closed loop.

Torsten




Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Nicklas Karlsson
> On Mon, 2020-07-27 at 21:43 +0200, N wrote:
> > > Hello Nicklas,
> > >
> > > I have a basic understanding control system analysis, but I don't
> > > normally
> > > analyze control systems.
> > >
> > > "You may calculate frequency response of your PID regulator with
> > > bode(...)
> > > function and use numeric calculations on amplitudes and phases for
> > > your PID
> > > regulator and frequency response of plant."
> > > I would appreciate if you could help me.
> >
> > G(jw) Frequency responce of your system
> > F(jw) Frequency response of PID regulator
> > Gry(jw) = F(jw)*G(jw)/(1 + F(jw)*G(jw)) Frequency response of closed
> > system
> >
> > Then you have frequency response with amplitude and angle for your
> > system. First you have to calculate amplitude and angle for you PID
> > controller at same frequencies. Calculations should be done point
> > wise. For multiplication amplitudess are multiplied while angles are
> > added. Divisor require some more thinking also by me but know value is
> > multiplied with complex conjugate to get absolute value in square,
> > convert from (phase, angle) form to (real, imaginary) should be one
> > possibility. Calulations could be checked by doing them on a system on
> > polynomial form, if numerical calculation on this agree with
> > analytical you probably got it right.
> >
> > To get Bode plot for the closed system you could use subplot(2,1,1)
> > semilogy(...) subplot(2,1,2) and plot(...) functions.
> >
> > To get nyquist diagram for stability analysis you plot with Gry(jw)
> > for increasing frequencies with real part on x axis and imaginary part
> > on y axis. If you have data on (phase, angle) form you have to convert
> > to (real, imaginary) form.
> >
> >
> > Nicklas SB Karlsson
> >
>
> For a stability analysis of the closed loop based on the Nyquist
> criterion, you need the frequency repsonce (nyquist()) of the open loop,
> not of Gry (jw), which represents the closed loop.
>
> Torsten

It must be the closed loop, if using the open loop feedback gains are not included in the analysis.

With open loop frequency response it should however be possible to calculate closed looop frequency response.


Reply | Threaded
Open this post in threaded view
|

Re: How Tune PID in octave using Frequency Response data

Octave - General mailing list
On Tue, 2020-07-28 at 23:18 +0200, N wrote:

> >
> >
> > For a stability analysis of the closed loop based on the Nyquist
> > criterion, you need the frequency repsonce (nyquist()) of the open
> > loop,
> > not of Gry (jw), which represents the closed loop.
> >
> > Torsten
>
> It must be the closed loop, if using the open loop feedback gains are
> not included in the analysis.
>
> With open loop frequency response it should however be possible to
> calculate closed looop frequency response.

The feedback gain is in F(jw) since this is the frequency response of
the PID controller (with gain). Therefore:

"Assessment of the stability of a closed-loop negative feedback system
is done by applying the Nyquist stability criterion to the Nyquist plot
of the open-loop system (i.e. the same system without its feedback
loop)." [1]

There are also forms of the criterion that are using the open loop
frequency response with gain 1 and where the number of closed loop poles
with positive real part can be determined depending on the open loop
gain.

Torsten


[1] https://en.wikipedia.org/wiki/Nyquist_stability_criterion