HP Forums
Bode/Nyquist plot..... - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Bode/Nyquist plot..... (/thread-3822.html)

Pages: 1 2


Bode/Nyquist plot..... - toshk - 05-13-2015 11:03 AM

program is based on (Statistics 1Var)...the numerical values from this this code is valid but plots are temperamental. need help pls.
BODE(ƒ1,ƒ2,[num],[den])>>enter. example
BODE(-1,1,[1],[1 0.2 1])>>enter.
use VIEW key to select graphs.

Code:

Tf();
BODE();
VIEW "Start",START()
BEGIN
D1:={};
D2:={};
SetSample(H1,D1);
SetFreq(H1,D2);
H1Type:=4;
STARTVIEW(6,1);
WAIT();
STARTVIEW(-1,1);
END;

export BODE(Xmin,Xmax,num,den)
BEGIN
local num:=poly2symb(num,"*x");
local den:=poly2symb(den,"*x");
expand(num/den)▶F1;
Xtick:=0.01;
makelist(ALOG(X),X,Xmin,Xmax,Xtick)▶L1;
L2:=Tf(L1);
L7:=20*LOG(ABS(L2));
L3:=ARG(L2)*180/pi;
L4:=IM(L2);
L5:=RE(L2);
END;

EXPORT Tf(x)
BEGIN
L2:=(F1(X)|x=L1);
END;

VIEW "Nyquist",nyquist()
BEGIN
L5▶D2;
L4▶D1;
Xmin:= FLOOR(MIN(D1)+1);
Xmax:=CEILING(MAX(D1)+1);
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
STARTVIEW(1,1);
END;

VIEW "Magnitude",Magnitude()
BEGIN
D1:=L1;
D2:=L7;
Xmin:= -1;
Xmax:= 1;
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
STARTVIEW(1,1);
END;

VIEW "Phase",Phase()
BEGIN
D1:=L1;
D2:=L3;
Xmin:= -1;
Xmax:= 1;
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
STARTVIEW(1,1);
END;

PLOT()
BEGIN
Xmin:= -1;
Xmax:= 1;
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
STARTVIEW(1,1);
END;

Symb()
BEGIN
SetSample(H1,D1);
SetFreq(H1,D2);
H1Type:=4;
STARTVIEW(0,1);
END;



RE: Bode/Nyquist plot..... - salvomic - 05-13-2015 11:13 AM

(05-13-2015 11:03 AM)toshk Wrote:  program is based on (Statistics 1Var)...
...

hi, thank you, but, please, check the code included...
I get this error (copy and pasting):
error in line 7 -> SetSample(H1,D1);
I don't think that the error is really there, perhaps elsewhere...

Thank you,
Salvo

EDIT:
no error in your program!
here there was previous data on Statistic 1var, so there there was an error with H1 and so on...
Also with some programs of mine this happens...

please, advice what data put in Statistic 1var for your example above, so I'll be able to test...


RE: Bode/Nyquist plot..... - toshk - 05-13-2015 04:04 PM

(05-13-2015 11:13 AM)salvomic Wrote:  
(05-13-2015 11:03 AM)toshk Wrote:  program is based on (Statistics 1Var)...
...

hi, thank you, but, please, check the code included...
I get this error (copy and pasting):
error in line 7 -> SetSample(H1,D1);
I don't think that the error is really there, perhaps elsewhere...

Thank you,
Salvo

EDIT:
no error in your program!
here there was previous data on Statistic 1var, so there there was an error with H1 and so on...
Also with some programs of mine this happens...

please, advice what data put in Statistic 1var for your example above, so I'll be able to test...
G(s) =

1
---------------
s^2 + 0.2 s + 1

Continuous-time transfer function. for frequencies(rad/s) between .01 and 10 shd be entered:

BODE(-1,1,[1],[1 0.2 1])>>enter.
use VIEW >>Start (if you think to empty D1 and D2)
use VIEW >>Magnitude. (to load freq. vs dB magnitude)
soft Menu>>Zoom>>Auotscale (to see how off the plot is)


RE: Bode/Nyquist plot..... - salvomic - 05-13-2015 04:37 PM

(05-13-2015 04:04 PM)toshk Wrote:  Continuous-time transfer function. for frequencies(rad/s) between .01 and 10 shd be entered:

BODE(-1,1,[1],[1 0.2 1])>>enter.
use VIEW >>Start (if you think to empty D1 and D2)
use VIEW >>Magnitude. (to load freq. vs dB magnitude)
soft Menu>>Zoom>>Auotscale (to see how off the plot is)

ok, I mean: I have already D1 and D2 empty...
In View I can see only 1. "Split screen Plot Detail" 2. Autoscale...
Am I wrong?

Salvo


RE: Bode/Nyquist plot..... - toshk - 05-13-2015 05:01 PM

recompile under the copy of (Statistics 1Var)..then you shd see mine VIEW


RE: Bode/Nyquist plot..... - salvomic - 05-13-2015 05:13 PM

(05-13-2015 05:01 PM)toshk Wrote:  recompile under the copy of (Statistics 1Var)..then you shd see mine VIEW

ok, but... I don't remember how, please, help Smile


RE: Bode/Nyquist plot..... - Tim Wessman - 05-13-2015 05:14 PM

(05-13-2015 05:13 PM)salvomic Wrote:  ok, but... I don't remember how, please, help Smile

Open the app program in your program catalog (very top item), then exit and go the the app screen.


RE: Bode/Nyquist plot..... - toshk - 05-13-2015 05:20 PM

select the copy of (Statistics 1Var) with the code.
Apps>>Statistics 1Var copy>>Enter
Shift>>Program>>Statistics 1Var copy>>Enter>>Check (for bugs).


RE: Bode/Nyquist plot..... - salvomic - 05-13-2015 05:29 PM

(05-13-2015 05:14 PM)Tim Wessman Wrote:  
(05-13-2015 05:13 PM)salvomic Wrote:  ok, but... I don't remember how, please, help Smile

Open the app program in your program catalog (very top item), then exit and go the the app screen.

(05-13-2015 05:20 PM)toshk Wrote:  select the copy of (Statistics 1Var) with the code.
Apps>>Statistics 1Var copy>>Enter
Shift>>Program>>Statistics 1Var copy>>Enter>>Check (for bugs).

thanks to both of you

I created a Statistic 1var copy, followed both tips, but in View I can see always the standard items. I'm trying again

EDIT:
I put your code in a program (here called bode-nyquist). Must I put it in Statistic 1var copy also? Sorry, but for now I'm a bit confused...


RE: Bode/Nyquist plot..... - toshk - 05-13-2015 06:00 PM

the code must be in Statistics 1Var copy.
yes...
the code is based on Statistics 1Var, putting the code in mere program would not help.


RE: Bode/Nyquist plot..... - Tim Wessman - 05-13-2015 07:30 PM

Can you please define what you mean by "tempermental"? I got it running here and it seems to be working fine - however I am not certain what I should be looking for.


RE: Bode/Nyquist plot..... - toshk - 05-13-2015 08:43 PM

BODE(-1,1,[1],[1 0.2 1])
shd look like attached pix. are you getting the same? without having to hit VIEW or Plot and Zoom multiplies of times? the numerical values in D1 and D2 changes with each VIEW pressed but not the graph (Plot).
thanks


RE: Bode/Nyquist plot..... - salvomic - 05-13-2015 09:35 PM

I'm trying with the new firmware, and I get this (apparent) error in the line

H1Type=4;

...

Salvo


RE: Bode/Nyquist plot..... - toshk - 05-13-2015 10:25 PM

with the new firmware, edit them out.
H1Type=4;
H1Type=4; and compile without error.
use Symb to set it up.
choose Dot under Plot1:


RE: Bode/Nyquist plot..... - salvomic - 05-13-2015 10:34 PM

(05-13-2015 10:25 PM)toshk Wrote:  with the new firmware, edit them out.
H1Type=4;
H1Type=4; and compile without error.
use Symb to set it up.
choose Dot under Plot1:

ok, I set Dot, but I don't understand:
H1Type=4;
H1Type=4;
?
The error cursor is set first than the "H" of "H1Type", still...

ok, I'll try tomorrow Smile


RE: Bode/Nyquist plot..... - Tim Wessman - 05-13-2015 10:37 PM

You can now directly access the symb parameters in a consistent way. H1 will recall a list of parameters. H1(num):= will let you set any parameter.

So for example, you can just use this H1:={'D1','D2', 4}; to replace 3 commands.


RE: Bode/Nyquist plot..... - alexzkter - 05-13-2015 11:51 PM

I created the Bode program with the long code, see capture:
[attachment=1965]

Also created copy of Statistics 1Var named Bode:
[attachment=1966]

Went into the app, shift-Program-enter on Bode program, debug (no errors) went back into the Statistics 1Var copy app then entered the code BODE(-1,1,[1],[1 0.2 1]) on the first cell but error message shows up:

[attachment=1967]

What am I doing wrong?


RE: Bode/Nyquist plot..... - Tim Wessman - 05-14-2015 12:16 AM

I believe the intent is for that command BODE(-1,1,[1],[1 0.2 1]) to be executed from the home screen or similar.


This is what I've done:
  1. execute START from VIEW. Q: I assume this will be to show the Info screen on completion?
  2. BODE(-1,1,[1],[1 0.2 1]) on the home screen. I now see 0 in D1 and 5 in D2. Is that what I should get?
  3. I execute nyquest and the xmin/max and ymin/max are identical. I assume that should not be the case?



RE: Bode/Nyquist plot..... - toshk - 05-14-2015 12:21 AM

the code is based on Statistics_1Var_Copy (newer firmware)
it works but buggy using Symb>>Dot....this is my code.
execute START from VIEW. Q: I assume this will be to show the Info screen on completion? Yes and also reset App.
BODE(-1,1,[1],[1 0.2 1]) on the home screen. Yes
Home screen >>VIEW>>Magnitude>>Plot (to see bode) use Zoom from soft menu
Code:

Tf();
BODE();
Xmin=0,Xmax=0;
VIEW "Start/Info",START()
BEGIN
D1:={};
D2:={};
SetSample(H1,D1);
SetFreq(H1,D2);
H1(3):=8;
STARTVIEW(6,1);
WAIT();
STARTVIEW(-1,1);
END;

export BODE(Xmin,Xmax,num,den)
BEGIN
Statistics_1Var_Copy.Xmin:=Xmin;
Statistics_1Var_Copy.Xmax:=Xmax;
local num:=poly2symb(num,"*x");
local den:=poly2symb(den,"*x");
expand(num/den)▶F1;
Xtick:=0.01;
makelist(ALOG(X),X,Xmin,Xmax,Xtick)▶L1;
L2:=Tf(L1);
L7:=20*LOG(ABS(L2));
L3:=ARG(L2)*180/pi;
L4:=IM(L2);
L5:=RE(L2);
END;

EXPORT Tf(x)
BEGIN
L2:=(F1(X)|x=L1);
END;

VIEW "Nyquist",nyquist()
BEGIN
L5▶D2;
L4▶D1;
Xmin:= FLOOR(MIN(D1)+1);
Xmax:= CEILING(MAX(D1)+1);
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
END;

VIEW "Magnitude",Magnitude()
BEGIN
D1:=L1;
D2:=L7;
Xmin:= Statistics_1Var_Copy.Xmin;
Xmax:= Statistics_1Var_Copy.Xmax;
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
END;

VIEW "Phase",Phase()
BEGIN
D1:=L1;
D2:=L3;
Xmin:= Statistics_1Var_Copy.Xmin;
Xmax:= Statistics_1Var_Copy.Xmax;
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
END;

PLOT()
BEGIN
Xmin:= Statistics_1Var_Copy.Xmin;
Xmax:= Statistics_1Var_Copy.Xmax;
Ymin:= FLOOR(MIN(D2)+1);
Ymax:= CEILING(MAX(D2)+1);
STARTVIEW(1,1);
END;



RE: Bode/Nyquist plot..... - salvomic - 05-14-2015 08:58 AM

(05-13-2015 10:37 PM)Tim Wessman Wrote:  You can now directly access the symb parameters in a consistent way. H1 will recall a list of parameters. H1(num):= will let you set any parameter.

So for example, you can just use this H1:={'D1','D2', 4}; to replace 3 commands.

thanks Tim, very interesting now!

Salvo