Not able to add delay to transfer function

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

Not able to add delay to transfer function

shall689
Hello,

octave returns "exp: not defined for class" when I multiply a transfer
function by exp(-s*tau).  

Is there any other way to add a delay?

Stephen



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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

Octave - General mailing list
On Wed, 2020-07-29 at 13:52 -0500, shall689 wrote:
> Hello,
>
> octave returns "exp: not defined for class" when I multiply a transfer
> function by exp(-s*tau).  
>
> Is there any other way to add a delay?
>
> Stephen
>

AFAIK, this is not (yet) possible. You can try padecoef () [1] for
approximating the delay by poles/zeros. Example: PT1 (T1=0.5, K=1) with
0.3s delay:

>> [num,den] = padecoef (0.3,8)
>> step (tf (1,[0.5 1])*tf (num,den))


Torsten


[1]   https://octave.sourceforge.io/octave/function/padecoef.html 



Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

shall689
Hello Torsten,

That seems to work.

I also tried (1+s*tau)/(1-s*tau), but the step response gave me the error:
"open_gl_renderer: data values greater than float capacity error"

(1+s*tau)/(1-s*tau) was mentioned on page 2 of this document:
http://users.ece.utexas.edu/~buckman/H3.pdf

Thanks,
Stephen



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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

Octave - General mailing list

On 29/07/2020 22:53, shall689 wrote:

> Hello Torsten,
>
> That seems to work.
>
> I also tried (1+s*tau)/(1-s*tau), but the step response gave me the error:
> "open_gl_renderer: data values greater than float capacity error"
>
> (1+s*tau)/(1-s*tau) was mentioned on page 2 of this document:
> http://users.ece.utexas.edu/~buckman/H3.pdf
>
> Thanks,
> Stephen
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>
I do not understand why you are trying to add something to your transfer
function (delay in this case). IIRC, in the beginning you stated you had
frequency response of your system. I asked whether the response was
complex (as in complex numbers) or just magnitude - I don't remember
getting a reply; I asked the question to better understand the task at hand.

If you have complex frequency response, you probably don't even need the
corresponding transfer function. This is because having the response and
the PID parameters you can have the resulting complex frequency response
which can be converted by 'ifft' into the resulting impulse response,
which also means it can be converted into step response (probably the
step response of most interest).

Anyway, having complex frequency response you can try to obtain rational
polynomial (i.e. either B(s)/A(s) or B(z)/A(z)) using 'invfreqs' or
'invfreqz' functions respectively. I believe what I'm writing is
methodologically correct, though from practice I know that for "funky"
frequency responses obtaining the resulting rational polynomial is very
tricky, i.e. small polynomial orders are not sufficient, and high
polynomial orders give convergence problems - do not fit the input
complex frequency response well.


If you only have magnitude response, you still need to obtain complex
frequency response - otherwise you can't build the corrected systems. Is
this the case and are you trying to add delay to the magnitude response
? If that's the case, I do not think your methodology is correct. Not
that you don't need delay - quite the opposite. But for minimum phase
systems magnitude response and phase response are tightly related - see
https://en.wikipedia.org/wiki/Kramers%E2%80%93Kronig_relations#Magnitude_(gain)%E2%80%93phase_relation 
,
https://en.wikipedia.org/wiki/Minimum_phase#Relationship_of_magnitude_response_to_phase_response 
. So, you really need to know complete true phase response of your system.

Anyway, I'm just a curious observer ...

--Sergei.



Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

shall689
Hello Sergie,

Thanks for information.

I did respond to you in the other thread ("I have both magnitude and phase
data.").  It just got lost in all the replies.  Also, I started a new thread
because I was asking a different question.

I got stuck on getting a transfer function that matched the frequency
response data, so I moved on to trying to get a transfer function using an
average model of the the Half bridge inverter.  I think I successfully came
up with the correct transfer equation using the average model.

I would still like to be able to come up with the equation using the
transfer function data.

I looked at ifft and it needs to have an iddata objects.  I think iddata
needs to be used to get the iddata objects, but iddata doesn't take
frequency response data.

A while back I unsuccessfully tried to get the transfer equation for a buck
converter from frequency response data.  I posted that question in the
following thread:
https://octave.1599824.n4.nabble.com/Control-System-Design-methods-using-Octave-tc4685799.html).
Doug was very helpful and I think the transfer equation was close but not
close enough.


Stephen



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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

Octave - General mailing list

On 30/07/2020 21:04, shall689 wrote:

> Hello Sergie,
>
> Thanks for information.
>
> I did respond to you in the other thread ("I have both magnitude and phase
> data.").  It just got lost in all the replies.  Also, I started a new thread
> because I was asking a different question.
>
> I got stuck on getting a transfer function that matched the frequency
> response data, so I moved on to trying to get a transfer function using an
> average model of the the Half bridge inverter.  I think I successfully came
> up with the correct transfer equation using the average model.
>
> I would still like to be able to come up with the equation using the
> transfer function data.
>
> I looked at ifft and it needs to have an iddata objects.  I think iddata
> needs to be used to get the iddata objects, but iddata doesn't take
> frequency response data.
>
> A while back I unsuccessfully tried to get the transfer equation for a buck
> converter from frequency response data.  I posted that question in the
> following thread:
> https://octave.1599824.n4.nabble.com/Control-System-Design-methods-using-Octave-tc4685799.html).
> Doug was very helpful and I think the transfer equation was close but not
> close enough.
>
>
> Stephen
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>

"I looked at ifft and it needs to have an iddata objects" - I meant
plain old procedural 'ifft':
https://octave.sourceforge.io/octave/function/ifft.html .

For that matter., invfreq& functions are described here:
https://octave.sourceforge.io/signal/function/invfreq.html ,
https://octave.sourceforge.io/signal/function/invfreqs.html ,
https://octave.sourceforge.io/signal/function/invfreqz.html .

--Sergei.




Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

GoSim
In reply to this post by shall689
Hi, if you post a step response I can probably create a high quality model for you, and also a controller (better than PID).


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

GoSim
In reply to this post by shall689
send in a step into you system and record the output and also record the step that you are sending in and also the sample time. With this data I can help you.
 
make sure the step response reaches steady state (becomes stationary) to get all the frequencies.


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

shall689
In reply to this post by Octave - General mailing list
Hello Sergei and GoPro,

I was able to compute the actual transfer function, so I won't need to
convert the frequency response to the transfer function right now.

Also, I came to the conclusion I didn't actually need a delay.  I needed a
ZOH hold.  I was able to get it by doing the following (using info Torsten
gave me):
s = tf('s')
[num,den] = padecoef(1/20000,1) % 1st order pade
sys  = tf(num,den)
zoh = (1-sys)/s

Also, I was able to get the same thing from slide 14 of
http://ecee.colorado.edu/~ecen5807/course_material/sampled/ 

Stephen



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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

shall689
In reply to this post by GoSim
Hello GoPro,

Here's the Transfer function I currently have:

s = tf('s');
num=[2.962962962962964e10 8.465608465608469e14]
den =[1.0 4.050793650793651e4 1.261375661375662e8 4.232804232804234e12]
sys_continuous = tf(num,den)
sys_discrete = c2d(sys_continuous,1/20000,'tusten');
step(sys_continuous)
hold on
step(sys_discrete)

Stephen



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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

GoSim
In reply to this post by shall689
I have created several controllers here, no problem to control this tf. I need this info to adjust:
 
1. Do you have signal noise? How much? Try to estimate it with white noise and tell me the amplitude of the white noise.
2. What is the max/min derivative of the control signal you accept?
3. Min/max value of the control signal?
4. Largest step you will make for the desired value?
5. How fast do you want the control signal?
6. What sample time do you use?
 
 
 


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

Octave - General mailing list
In reply to this post by shall689

On 03/08/2020 10:11, shall689 wrote:

> Hello Sergei and GoPro,
>
> I was able to compute the actual transfer function, so I won't need to
> convert the frequency response to the transfer function right now.
>
> Also, I came to the conclusion I didn't actually need a delay.  I needed a
> ZOH hold.  I was able to get it by doing the following (using info Torsten
> gave me):
> s = tf('s')
> [num,den] = padecoef(1/20000,1) % 1st order pade
> sys  = tf(num,den)
> zoh = (1-sys)/s
>
> Also, I was able to get the same thing from slide 14 of
> http://ecee.colorado.edu/~ecen5807/course_material/sampled/
>
> Stephen
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>
Now that you have your transfer function, if not yet you better test its
accuracy. By that I mean measure the transfer function magnitude and
phase responses and compare them to the actual system measured data
(using which you approximated the transfer function) and make sure that
the differences are small enough - I'd say no more than 1db in magnitude
and no more than 5 degrees in phase.

Having done that you might consider changing the tool. I suggest to
switch to a SPICE-type simulator with convenient GUI. I myself LTSpice a
lot under Linux under 'wine'.

LTSpice has arbitrary behavior voltage and current sources, and they can
utilize Laplace transform - on that read in e.g.
http://ltwiki.org/?title=B_sources_%28complete_reference%29 . So you can
code your system transfer function and the rest should be trivial. If I
understand correctly, PID controller in terms of electronics is Ri -> C
-> Rd circuit with possibly an amplifier, with Ri being mostly
responsible for integration, and Rd being mostly responsible for
differentiation (this is a very simplified explanation).

So all in all you'll have to draw a very simple circuit in LTSpice
circuit editor and you will be able to easily simulate it and easily
play with PID controller parameters. LTSpice has very nice graphs/waves
display, so you'll have easy access to all intermediate points of your
system model.

--Sergei.




Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

GoSim
In reply to this post by shall689
The controller i do is not a PID, it's a more advanced tf, so if you can only implement a PID with electronics don't waste your time with the questions and forget them.


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

Octave - General mailing list


On 04/08/2020 1:49, GoSim GoSim wrote:
The controller i do is not a PID, it's a more advanced tf, so if you can only implement a PID with electronics don't waste your time with the questions and forget them.


    

If it was a reply (mostly) to me, I gave PID as a simple example. Obviously, one can implement whatever controller he wants and still simulate it in SPICE-like simulator.

...

Extending the topic (or offtopic) - there is a Julia package to interface LTSpice: https://github.com/cstook/LTspice.jl . The point being one can code, say, global optimization around LTSpice. E.g. one can decide to implement, say, a 6th order controller and play with parameters no manually, but using in the case Julia and set optimization criteria as one wishes, e.g. some combination of slew rate and overshoot.

--Sergei.



Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

shall689
In reply to this post by Octave - General mailing list
Hello Sergio,

> Now that you have your transfer function, if not yet you better test its
> accuracy. By that I mean measure the transfer function magnitude and
> phase responses and compare them to the actual system measured data

I didn't get the frequency response from the actual hardware.  I got it from
a Half bridge inverter PSIM simulation, but it might be a good idea to
compare the equation against the frequency response data  from the PSIM
simulation.

> LTSpice has arbitrary behavior voltage and current sources, and they can
> utilize Laplace transform - on that read in e.g.
> http://ltwiki.org/?title=B_sources_%28complete_reference%29 .

Ok, that is interesting. I found a youtube video that explains how to use
it. https://www.youtube.com/watch?v=jI6AXEVloB4.  I already have Ltspice on
my ubuntu laptop, so I will try it out.

Thanks,
Stephen





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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

shall689
In reply to this post by GoSim
The PID is implemented on an FPGA.



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


Reply | Threaded
Open this post in threaded view
|

Re: Not able to add delay to transfer function

Octave - General mailing list

On 06/08/2020 1:24, shall689 wrote:
> The PID is implemented on an FPGA.
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>
Assuming FPGA means digital implementation (Z-domain) - LTSpice can also
run discrete simulations. I.e. there is a memory element - IIRC it's
called something like delay line. There's also 'sign' function - maybe
it's called differently.

--Sergei.