bugGNU Octave - Bugs: bug #56560, [octave forge] (control) Error by...

 
 

bug #56560: [octave forge] (control) Error by addition of two frd objects

Submitted by:  Jonas Frischknecht <jonas24>
Submitted on:  Thu 27 Jun 2019 09:08:52 AM UTC  
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  5.1.0 Operating System:  Microsoft Windows

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Tue 09 Jul 2019 10:39:54 PM UTC, comment #16: 
Mike Miller <mtmiller>
Project Administrator
Tue 09 Jul 2019 09:04:15 PM UTC, comment #15: 

This can be closed now.

I pushed the fix.

Changeset:
1613 (ddb727dc0c90) _sys_group_: fix bug #56560

Doug Stewart <dastew>
Mon 08 Jul 2019 07:57:43 AM UTC, comment #14: 

Yes, it seems to work. I didn't recognize that there is another issue with bode, becaues I don't use bode. I've written my own function to plot the bode diagrams.

Jonas Frischknecht <jonas24>
Wed 03 Jul 2019 11:04:45 PM UTC, comment #13: 

With the changes in comment #7, the original bug reported here looks fixed to me. Here is a patch repeating those changes with Octave coding style

diff --git a/inst/@frd/__sys_group__.m b/inst/@frd/__sys_group__.m
--- a/inst/@frd/__sys_group__.m
+++ b/inst/@frd/__sys_group__.m
@@ -28,10 +28,12 @@ function retsys = __sys_group__ (sys1, s

   if (! isa (sys1, "frd"))
     sys1 = frd (sys1, sys2.w);
+    sys1.lti = sys2.lti;
   endif

   if (! isa (sys2, "frd"))
     sys2 = frd (sys2, sys1.w);
+    sys2.lti = sys1.lti;
   endif

   retsys = frd ();

So I'd call that a fix and close this. Both for the original example and the full example in comment #11.

There is still another issue with the full script in the call to "bode" on a system of type "frd", but that shouldn't block this bug from being fixed.

Mike Miller <mtmiller>
Project Administrator
Fri 28 Jun 2019 10:40:12 AM UTC, comment #12: 

Just realized a small error in the for-loop. The magnitude is already in abs. So the for-loop should look like this:

for k=1:length(W)
   cmpl(k,1) = Mag(k)*(cosd(Pha(k))+1i*sind(Pha(k)));
end

Jonas Frischknecht <jonas24>
Fri 28 Jun 2019 10:26:50 AM UTC, comment #11: 

Sure. Here you go

% System to simulate measured vectors
Example_System = tf([1 10],[1 0.56 12]);
[Mag, Pha, W] = bode(Example_System);
% sampling time
Ts = 1e-3;
Tn = 1;
% Calculate complex response
for k=1:length(W)
   cmpl(k,1) = 10^(Mag(k)/20)*(cosd(Pha(k))+1i*sind(Pha(k)));
end
% Generate frd object
P = frd(cmpl,W,Ts);
% Controller
C = c2d(tf([Tn 1],[Tn 0]),Ts,'tustin');
% Calculate closed loop
OpLo = P*C;
T = OpLo/(1 + OpLo);
% plot bode
figure(1)
bode(P,C,OpLo,T)

Jonas Frischknecht <jonas24>
Thu 27 Jun 2019 01:58:54 PM UTC, comment #10: 

I need a running example in order to help improve the control package. Would you be willing to post your code so that I can use it?

Doug Stewart <dastew>
Thu 27 Jun 2019 01:29:26 PM UTC, comment #9: 

they are setting the sample time to be the same.

Doug Stewart <dastew>
Thu 27 Jun 2019 01:26:29 PM UTC, comment #8: 

It's looking good! I'm going to cross check this with matlab the next days.. but it seems to work. Thanks a lot!
What are those lines doing?

Jonas Frischknecht <jonas24>
Thu 27 Jun 2019 01:13:28 PM UTC, comment #7: 

OK in _sys_group_.m
try adding 2 lines to make it look like this:


  if (! isa (sys1, "frd"))
    sys1 = frd (sys1, sys2.w);
        sys1.lti=sys2.lti;
  endif

  if (! isa (sys2, "frd"))
    sys2 = frd (sys2, sys1.w);
        sys2.lti=sys1.lti;
  endif

Let me know if this helps.

Doug Stewart <dastew>
Thu 27 Jun 2019 12:48:45 PM UTC, comment #6: 

By calculating the denominator (1 + PC) I recieve the error systems must have identical sampling times. So I can't add 1 to an frd object. Further, I made an frd object for 1 (was the soloution in older matlab versions). But it still doesn't work.

So I realized, that I get the same error, even when I try to make an addition of two identical systems with the same frequencies and the same sampling times. As I tried to make clear with my small example.

Jonas Frischknecht <jonas24>
Thu 27 Jun 2019 12:29:49 PM UTC, comment #5: 

Lets look at your original problem.
"P*C/(1+P*C)"

What was the problem?

Doug Stewart <dastew>
Thu 27 Jun 2019 12:18:09 PM UTC, comment #4: 

What you tried actually works for me. But I don't have a continuous system.

Jonas Frischknecht <jonas24>
Thu 27 Jun 2019 11:56:50 AM UTC, comment #3: 

I tried:

s=tf('s')
sys=(s+1)/(s^2+s+10)
sys1=frd(sys)
bode(sys1)

and this did not work. I don't think the frd system in octave is very complete yet.

Doug Stewart <dastew>
Thu 27 Jun 2019 10:42:45 AM UTC, comment #2: 

It's just a simplified example to make clear where the error occurs. What I want to do is to calculate a closed loop with a measured Plant P a discrete controller C, like P*C/(1+P*C) and plot the bode diagramm. First I struggled with (1+P*C) so I tried to generate an frd object for 1 (works in Matlab directly). It didn't work so i tried to make an addition with two identical systems.

Jonas Frischknecht <jonas24>
Thu 27 Jun 2019 10:30:55 AM UTC, comment #1: 

I think I have a fix, but I am not familiar with frd objects.
How are you going to use NewSys?
I would like to use it to be sure that my fix works properly.

Doug Stewart <dastew>
Thu 27 Jun 2019 09:08:52 AM UTC, original submission:  

The following code

% generate a frequency vector and response data
freq = logspace(1,4);
resp = 1.23*(freq).*exp(i*2*freq);
% Create a FRD model
sysTEST = frd(resp,freq,1e-3);
NewSys = sysTEST + sysTEST;

gives the error, that the systems must have identical sampling times (works with Matlab).

By calling the frd function without the sampling time it works also in ovtave. But in that case it isn't possible to set the sampling time like this:

NewSys.Ts = 1e-3;

The error "invalid sampling time" appears.

Jonas Frischknecht <jonas24>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dastew (Posted a comment)
  • -email is unavailable- added by jonas24 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-07-09 mtmiller StatusPatch Submitted => Fixed
        Open/ClosedOpen => Closed
    2019-07-03 mtmiller StatusNone => Patch Submitted
    2019-06-27 mtmiller SummaryError by addition of two frd objects (control package) => [octave forge] (control) Error by addition of two frd objects

    Back to the top


    Powered by Savane 3.5