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


RE: Bode/Nyquist/Nichols plot.....Fully functional - toshk - 05-14-2015 10:15 AM

Frequency response plots corresponding to G =

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

BODE(ƒ1,ƒ2,[numerator],[denominator]) enter
Home Screen. (all functions are executed from Home screen)
BODE(-2,2,[1 1],[1 .2 1]) enter
Use VIEW key for Plot selection
VIEW>>START to refresh
Soft menu to Zoom....
App is based on Statistics_2Var_Copy.
Code:

Tf();
BODE();
VIEW "Start/Info",START()
BEGIN
C1:={};
C2:={};
S1:={'C1','C2','1','12'};
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;
Statistics_2Var_Copy.Xmin:=ALOG(Xmin);
Statistics_2Var_Copy.Xmax:=ALOG(Xmax);
L2:=Tf(L1);
L7:=20*LOG(ABS(L2));
L3:=ARG(L2);
L4:=IM(L2);
L5:=RE(L2);
END;

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

VIEW "Nyquist",nyquist()
BEGIN
S1:={'C1','C2','1','12'};
L4▶C2;
L5▶C1;
Xmin:= FLOOR(MIN(C1)+1);
Xmax:= CEILING(MAX(C1)+1);
Xtick:=.2;
Ymin:= FLOOR(MIN(C2)+1);
Ymax:= CEILING(MAX(C2)+1);
END;

VIEW "Magnitude",Magnitude()
BEGIN
S1:={'C1','C2','1','12'};
C1:=L1;
C2:=L7;
Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax;
Xtick:=10;
Ymin:= FLOOR(MIN(C2)+1);
Ymax:= CEILING(MAX(C2)+1);
END;

VIEW "Phase",Phase()
BEGIN
S1:={'C1','C2','1','12'};
C1:=L1;
C2:=L3;
Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax;
Xtick:=10;
Ymin:= FLOOR(MIN(C2)+1);
Ymax:= CEILING(MAX(C2)+1);
END;

VIEW "Nichols",Nichols()
BEGIN
S1:={'C1','C2','1','12'};
C1:=L3;
C2:=L7;
Ymin:=Statistics_2Var_Copy.Xmin;
Ymax:=Statistics_2Var_Copy.Xmax;
Ytick:=10;
Xmin:= FLOOR(MIN(C1)+1);
Xmax:= CEILING(MAX(C1)+1);
END;

PLOT()
BEGIN
STARTVIEW(1,1);
END;



RE: Bode/Nyquist plot..... - alexzkter - 05-14-2015 10:17 AM

Okay, I get it now.
I tried BODE(-1,1,[1],[1 0.2 1]) and got {5}
View-->start takes me to an empty home screen.
View-->Nyquist, Magnitude and Phase don't do anything.... [attachment=1972]
edit1: I was trying with Statistics 1Var, just tried with Statistics 2Var and same result.

What am I missing?

Edit: Can't get it to compile without Sintax error on physical Prime. And my Prime is just formated, in English. Copied the 2-Var Statistics, renamed it to Statistics_2Var_Copy and on HP Connectivity kit went to Program tab for the Statistics_2Var_Copy app, and replaced the code with the proper one.
Did the same thing on Virtual Calculator and got no sintax error (No errors in program).............


RE: Bode/Nyquist plot..... - toshk - 05-14-2015 10:42 AM

App is based on Statistics_2Var_Copy.
recompile it on your calculator...check for bug (no bugs)and then exit.
launch the App again, home screen enter your BODE(-1,1,[1],[1 0.2 1])
View and choose a plot and then hit PLOT to plot it.
soft menu to zoom.
to plot another graph back out to home and hit VIEW for options.
View >> Start/Info will refresh it
hit View>> (for options)
works here.....


RE: Bode/Nyquist plot..... - alexzkter - 05-14-2015 10:48 AM

(05-14-2015 10:42 AM)toshk Wrote:  App is based on Statistics_2Var_Copy.
recompile it on your calculator...check for bug (no bugs)and then exit.
launch the App again, home screen enter your BODE(-1,1,[1],[1 0.2 1])
View and choose a plot and then hit PLOT to plot it.

On just formated Virtual Prime, did just that, and when hitting PLOT button it shows "S1 - Error: Statistics data size not equal":
[attachment=1973]

:/


RE: Bode/Nyquist plot..... - toshk - 05-14-2015 10:52 AM

View>>Start/info
and try again...work here.
or hit symb key and see whats the parameters?


RE: Bode/Nyquist plot..... - alexzkter - 05-14-2015 11:17 AM

(05-14-2015 10:52 AM)toshk Wrote:  View>>Start/info
and try again...work here.
or hit symb key and see whats the parameters?


View-->Start/Info, takes me to an empty white page. I hit View again, and the previous page shows up again (the one with the BODE[.....]) so I hit View once again, choose Niquist for instance, nothing happens, hit plot and this shows up:
[attachment=1976]
hit Escape and this shows up:
[attachment=1978]
and if I hit Symb this is what comes up:
[attachment=1977]


RE: Bode/Nyquist plot..... - toshk - 05-14-2015 11:32 AM

(05-14-2015 11:17 AM)alexzkter Wrote:  
(05-14-2015 10:52 AM)toshk Wrote:  View>>Start/info
and try again...work here.
or hit symb key and see whats the parameters?


View-->Start/Info, takes me to an empty white page. I hit View again, and the previous page shows up again (the one with the BODE[.....]) so I hit View once again, choose Niquist for instance, nothing happens, hit plot and this shows up:

hit Escape and this shows up:

and if I hit Symb this is what comes up:
launch the App...you will see empty page(), press any key to go home. enter BODE with your arguments and enter. view>>choose a plot and then hit plot. soft menu for auto scale......
if you happen to see error, manually change settings >>press the Symb key and also the plot setup and hit plot gain..., latest firmware?


RE: Bode/Nyquist plot..... - alexzkter - 05-14-2015 10:57 PM

Finally...the bode code wasn't correct, I was copy pasting it from the web, that's why I was getting {5} instead of something like this:

[attachment=1991]

So now I'm trying this transfer function:
[attachment=1993]

But this is what I get:
[attachment=1992]

What exactly are the f1 and f2 cells for on the bode code?


RE: Bode/Nyquist plot.....Fixed - toshk - 05-16-2015 03:57 AM

Using your Wolfram in question...
BODE(.01,100, [1],[1 1])
.1 and 100 are the frequency range you want to analyze.
all plots/bode() executions shd be entered from Home screen.
Use VIEW>> {Start/Info, Magnitude, Phase, Nyquist, Nichols} HOME SCREEN
VIEW>>Start/Info (refreshes Statistics_2Var_Copy parameters...hit any Key to get You to Home Screen again)
Use VIEW>> {Start/Info, Magnitude, Phase, Nyquist, Nichols} again for the same BODE().
use soft Menu zoom (auto-scale)to zone in on plots. (just because i can't graphs to center on the screen) help needed on that!!!
This App is based on Statistics_2Var_Copy.
You need to recompile before your first use of this App.
Code:

Tf();
BODE();
Xmi,Xma;
VIEW "Start/Info",START()
BEGIN
C1:={};
C2:={};
S1:={'C1','C2','1','13'};
STARTVIEW(6,1);
WAIT();
STARTVIEW(-1,1);
END;

export BODE(Xmi,Xma,num,den)
BEGIN
local num:=poly2symb(num,"*x");
local den:=poly2symb(den,"*x");
expand(num/den)▶F1;
makelist(X,X,1,1000,1)▶L9;
L1:=ALOG(LOG(Xmi)+(L9-1)*(LOG(Xma)-LOG(Xmi))/1000);
Statistics_2Var_Copy.Xmin:=(Xmi);
Statistics_2Var_Copy.Xmax:=(Xma);
F2:=20*LOG(CAS.ABS(F1));
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 "Magnitude",Magnitude()
BEGIN
S1:={'C1','C2','1','13'};
C1:=LOG(L1);
C2:=L7;
Statistics_2Var_Copy.Xmin:=Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=10;
END;

VIEW "Phase",Phase()
BEGIN
C1:=LOG(L1);
C2:=L3;
Statistics_2Var_Copy.Xmin:=Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=5
END;

VIEW "Nyquist",nyquist()
BEGIN
C1:=L5;
L4▶C2;
Statistics_2Var_Copy.Xmin:= FLOOR(MIN(C1)+1);
Statistics_2Var_Copy.Xmax:= CEILING(MAX(C1)+1);
Xtick:=.2;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=0.2;
END;

VIEW "Nichols",Nichols()
BEGIN
C1:=L3;
C2:=L7;
Statistics_2Var_Copy.Xmin:= FLOOR(MIN(C1)+1);
Statistics_2Var_Copy.Xmax:= CEILING(MAX(C1)+1);
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=10;
END;

PLOT()
BEGIN
STARTVIEW(1,1);
END;
enjoy....!! thanks


FOUND BUG COMPILING WITH DIGIT GROUPING - alexzkter - 05-16-2015 09:41 AM

Hi again,

I just found out why I was getting Sintax error when compiling in my physical Prime (7820 fw.)
I realized that if you compile your program when the 123456,789 digit grouping is selected (the one we use in Spain), you get a Sintax error which doesn't happen if you have the default one (123,456.789).

I have to say the digit grouping feature was a really bad idea, it only has given me a lot of trouble :/

By the way, thanks for your last post, will try all that as soon as posible!


RE: Bode/Nyquist plot..... - alexzkter - 05-16-2015 10:53 AM

Hi again, I didn't know f1 and f2 was the frequency range (rad/s). You typing [-1,1] and [-2,2] on some examples confused me since negative frequencies don't exist.

I've been trying to plot this:
[attachment=2025]

and I got this:
[attachment=2024] [attachment=2023]

But, I don't understand why the 'x' takes negative values, since that's the frequency axis. How am I supposed to read the frequency values, mate? Thanks in advance


RE: Bode/Nyquist plot..... - toshk - 05-16-2015 03:56 PM

Use Trace to read values.....or Num key. (the numerical values are really spot on.)
remember is a log10 scale: values on the X-axis: values Trace on the X-axis shd be 10^(X-value) .(for magnitude,phase plots)
so your negative values on X-axis are pretty much fractions.
so instead of -1, 1 just enter .1,10 all in rad/sec.
BODE(.1,10 [1],[1 1]) is what you really have to enter.

on the Info tab in Conkit just paste the below instructions and recompile the App, this will give you the info when u do start the App or press VIEW>>Start/Info:

Frequency response plots corresponding to G =

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

BODE(ƒ1,ƒ2,[numerator],[denominator]) enter
BODE(0.01,100,[1 1],[1 .2 1]) enter
Use VIEW key for Plot selection
VIEW>>START to refresh


RE: Bode/Nyquist plot..... - toshk - 05-16-2015 10:51 PM

added Response time.....(Time delay....'t')

Code:

Tf();
Tfr();
Delay();
BODE();
Xmi,Xma,Xt;
VIEW "Start/Info",START()
BEGIN
C1:={};
C2:={};
S1:={'C1','C2','1','13'};
STARTVIEW(6,1);
WAIT();
STARTVIEW(-1,1);
END;

export BODE(Xmi,Xma,num,den)
BEGIN
local num:=poly2symb(num,"*x");
local den:=poly2symb(den,"*x");
expand(num/den)▶F1;
makelist(X,X,1,1000,1)▶L9;
L1:=ALOG(LOG(Xmi)+(L9-1)*(LOG(Xma)-LOG(Xmi))/1000);
Statistics_2Var_Copy.Xmin:=(Xmi);
Statistics_2Var_Copy.Xmax:=(Xma);
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;

EXPORT Tfr(x)
BEGIN
L0:=−x*L1*180/π;
L8:=L3+L0;
END;

VIEW "Magnitude",Magnitude()
BEGIN
S1:={'C1','C2','1','13'};
C1:=LOG(L1);
C2:=L7;
Statistics_2Var_Copy.Xmin:=Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=10;
END;

VIEW "Phase",Phase()
BEGIN
C1:=LOG(L1);
C2:=L3;
Statistics_2Var_Copy.Xmin:=Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=5
END;

VIEW "Nyquist",nyquist()
BEGIN
C1:=L5;
L4▶C2;
Statistics_2Var_Copy.Xmin:= FLOOR(MIN(C1)+1);
Statistics_2Var_Copy.Xmax:= CEILING(MAX(C1)+1);
Xtick:=.2;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=0.2;
END;

VIEW "Nichols",Nichols()
BEGIN
C1:=L3;
C2:=L7;
Statistics_2Var_Copy.Xmin:= FLOOR(MIN(C1)+1);
Statistics_2Var_Copy.Xmax:= CEILING(MAX(C1)+1);
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=10;
END;

VIEW "Reponse",Response()
BEGIN
INPUT(Xt);
Tfr(Xt);
C1:=LOG(L1);
C2:=L8;
Xmin:=Statistics_2Var_Copy.Xmin;
Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=5
END;

PLOT()
BEGIN
STARTVIEW(1,1);
END;



RE: Bode/Nyquist plot..... - toshk - 05-17-2015 12:40 AM

added Response time.....(Time delay....'t')! and adjusted the effect on the phase/Nichols plot
Code:

Tf();
Tfr();
Delay();
BODE();
Xmi,Xma,Xt=0;
VIEW "Start/Info",START()
BEGIN
C1:={};
C2:={};
S1:={'C1','C2','1','13'};
STARTVIEW(6,1);
WAIT();
STARTVIEW(-1,1);
END;

export BODE(Xmi,Xma,num,den)
BEGIN
local num:=poly2symb(num,"*x");
local den:=poly2symb(den,"*x");
Xt:=0;
expand(num/den)▶F1;
makelist(X,X,1,1000,1)▶L9;
L1:=ALOG(LOG(Xmi)+(L9-1)*(LOG(Xma)-LOG(Xmi))/1000);
Statistics_2Var_Copy.Xmin:=(Xmi);
Statistics_2Var_Copy.Xmax:=(Xma);
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;

EXPORT Tfr(Xt)
BEGIN
L3:=ARG(L2)*180/pi;
L0:=−Xt*L1*180/π;
L8:=L3+L0;
L3:=L8;
END;

VIEW "Magnitude",Magnitude()
BEGIN
S1:={'C1','C2','1','13'};
C1:=LOG(L1);
C2:=L7;
Statistics_2Var_Copy.Xmin:=Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=10;
END;

VIEW "Phase",Phase()
BEGIN
C1:=LOG(L1);
C2:=L3;
Statistics_2Var_Copy.Xmin:=Statistics_2Var_Copy.Xmin;
Statistics_2Var_Copy.Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=5
END;

VIEW "Nyquist",nyquist()
BEGIN
C1:=L5;
L4▶C2;
Statistics_2Var_Copy.Xmin:= FLOOR(MIN(C1)+1);
Statistics_2Var_Copy.Xmax:= CEILING(MAX(C1)+1);
Xtick:=.2;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=0.2;
END;

VIEW "Nichols",Nichols()
BEGIN
C1:=L3;
C2:=L7;
Statistics_2Var_Copy.Xmin:= FLOOR(MIN(C1)+1);
Statistics_2Var_Copy.Xmax:= CEILING(MAX(C1)+1);
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=10;
END;

VIEW "Reponse",Response()
BEGIN
MSGBOX("Affects Nichols/Phase Plots too");
INPUT(Xt);
Tfr(Xt);
C1:=LOG(L1);
C2:=L8;
Xmin:=Statistics_2Var_Copy.Xmin;
Xmax:=Statistics_2Var_Copy.Xmax;
Xtick:=1;
Statistics_2Var_Copy.Ymin:= FLOOR(MIN(C2)+1);
Statistics_2Var_Copy.Ymax:= CEILING(MAX(C2)+1);
Ytick:=5
END;



RE: Bode/Nyquist plot..... - StephenG1CMZ - 10-10-2015 10:25 PM

(05-16-2015 10:53 AM)alexzkter Wrote:  Hi again, I didn't know f1 and f2 was the frequency range (rad/s). You typing [-1,1] and [-2,2] on some examples confused me since negative frequencies don't exist.

I've been trying to plot this:


and I got this:


But, I don't understand why the 'x' takes negative values, since that's the frequency axis. How am I supposed to read the frequency values, mate? Thanks in advance

I haven't studied the graph, but some physicists argue that negative frequencies exist, much like negative distances or displacements. Consider for example a clock, with a second hand rotating clockwise. Apply a negative rotational force - the frequency that the second hands sweeps clockwise will reduce and eventually reach 0. continue to apply the force. The second hand will begin to sweep anti-clockwise at a positive frequency - or clockwise at a negative frequency, if you like. Just like walking -5m North really. Though perhaps it could be called something else, like we distinguish 5m distant (positive) from 5m North (signed).


RE: Bode/Nyquist plot..... - don7 - 11-04-2016 06:16 PM

This is a nice app -- I'm hoping someone can help with my user errors & setup...

I am unable to get the positive values on imaginary axis to display in the nyquist plots (basically anything > 0 on Y axis is not plotted). Positive / negative real values are okay. Is there a setting to change behavior?

<corrected above and deleted other question because it was previously answered>

Thanks!


RE: Bode/Nyquist plot..... - toshk - 11-04-2016 07:36 PM

(11-04-2016 06:16 PM)don7 Wrote:  This is a nice app -- I'm hoping someone can help with my user errors & setup...

I am unable to get the positive values on imaginary axis to display in the nyquist plots (basically anything > 0 on Y axis is not plotted). Positive / negative real values are okay. Is there a setting to change behavior?

<corrected above and deleted other question because it was previously answered>

Thanks!
symmetric graph.....
type:
C3:=-C2
hit Symb:
check S2: assign C1 C3
Plot: Autoscale to see graph.
http://www.hpmuseum.org/forum/thread-3891.html


RE: Bode/Nyquist plot..... - don7 - 11-04-2016 10:05 PM

Thanks, it's not working for me but I'll keep playing as I'm sure I'm doing something wrong ( calculator is brand new and I'm coming from a 48)

Seems that the check box disappears as soon as I run nyquist plot and graph is the same.

On home screen I enter:

C3:=-C2 (it returns {} or contains data.I'm guessing depending on if I executed bode previously)

In the symbol screen, I replace the C0 with C1 and C2 with C3 as well as check the box

I then evaluate the bode expression and get the same results as before. If I check back in the symbol I see the check box has cleared but C1/C3 remain.

I'll keep playing, thanks for help


RE: Bode/Nyquist plot..... - toshk - 11-06-2016 08:34 PM

(11-04-2016 10:05 PM)don7 Wrote:  Thanks, it's not working for me but I'll keep playing as I'm sure I'm doing something wrong ( calculator is brand new and I'm coming from a 48)

Seems that the check box disappears as soon as I run nyquist plot and graph is the same.

On home screen I enter:

C3:=-C2 (it returns {} or contains data.I'm guessing depending on if I executed bode previously)

In the symbol screen, I replace the C0 with C1 and C2 with C3 as well as check the box

I then evaluate the bode expression and get the same results as before. If I check back in the symbol I see the check box has cleared but C1/C3 remain.

I'll keep playing, thanks for help

executed bode
plot the nyquist
type:
C3:=-C2
hit Symb:
check S2: assign C1 C3
Plot: Autoscale to see graph. (DO NOT execute Bode again)


RE: Bode/Nyquist plot..... - hectometro00@gmail.com - 11-28-2016 11:10 PM

Hi, how can I use delay time?