This post was updated on .
I mainly work with PSIM.
PSIM has a general control system design software named smartctrl. Matlab has something simlar, I think. According to https://www.youtube.com/watch?v=tpoCpC-oX7Q, the following steps in smartctrl can be taken to determine the design parameters for a specific control system: 1. import the bode plot obtained from an AC sweep of your simulation into smartctrl. 2. Select a sensor (voltage divider and ect) from the smartctrl. 3. Select a controller (PI or etc). 4. Afterwards, select a point from the cross over frequency vs Phase Margin solution map that gives a specific step response. Smartctl also shows the bode plots for the closed loop response. Smartctrl gives the P and I for the specific point picked in the solution map. Is there anyway to get octave to give the same type of information? Thanks, Stephen -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list Help-octave@gnu.org https://lists.gnu.org/mailman/listinfo/help-octave |
Hello,
I did some searching and found invfreqz and invfreqs. It seems they can be used to convert gain/phase data from the system to a transfer function in the discrete (=G(z)) and continuous (=G(s)) domain respectively. I could then find out the total closed loop response by G/(1+G*H), where H is the PID transfer function. So, I am assuming I could use complex samples from the bode diagram as inputs to either of these two functions,i.e h=[(1+i),(2+2i),...], w=[1,1.01,..], n=?,m=?,invfreqz(h,w,n,m). Is that correct? How would I determine n and m? I am thinking that selecting n=1 and m = 2 would be a good start. if the plot of the transfer function doesn't give a good match to the original transfer function, I would just increase m and then increase n the next time if match is still not good. Would that work? Am I working in the right direction? Thanks, Stephen -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Hello,
The frequency response data given in buckVfreqResp.csv (see attached file) is the result of a frequency sweep in PSIM. The attached m file, converts that data to a descrete system and plots its bode plot (See Bode Plot of Descrete System Image). The two bode plots somewhat match each other on the left side of the bode plot; however, the frequency range on the discrete system bode plot doesn't match the frequency range on frequency sweep bode plot. the buck converter sample rate is 20kHz. The max frequency on the discrete system bode plot is 2e-4 rad/seconds, which is equivalent to 0.64Hz. Why am I getting such small frequencies on the discrete system bode plot? Stephen <http://octave.1599824.n4.nabble.com/file/t372348/FrequencyResponseFromPSIMSimulation.png> <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot.png> buckVfreqResp.csv <http://octave.1599824.n4.nabble.com/file/t372348/buckVfreqResp.csv> CreateTFfromFreqResponse.m <http://octave.1599824.n4.nabble.com/file/t372348/CreateTFfromFreqResponse.m> -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) instead of
tf(b,a,SampleFrequency). The bode plot seem to match each other much better and the frequency range is a little better, with the only issue is that the max discrete frequency is 10 (>> pi). Is there some type of issue with the bode() function? <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot2.png> -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
On Wed, Dec 6, 2017 at 4:57 PM, shall689 <[hidden email]> wrote: Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) instead of Hi Shall If you would post your exact code, for me to run, then I am sure that I can answer your questions. https://pastebin.com/ is one way to post it. _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Doug Stewart-4 wrote
> On Wed, Dec 6, 2017 at 4:57 PM, shall689 < > sahallacy@ > > wrote: > >> Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) instead >> of >> tf(b,a,SampleFrequency). >> >> The bode plot seem to match each other much better and the frequency >> range >> is a little better, with the only issue is that the max discrete >> frequency >> is 10 (>> pi). >> >> Is there some type of issue with the bode() function? >> >> >> <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot2.png> >> >> >> >> -- >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> f1599825.html >> >> > Hi Shall > If you would post your exact code, for me to run, then I am sure that I > can > answer your questions. > https://pastebin.com/ is one way to post it. > > > > -- > DAS > > <https://linuxcounter.net/user/206392.html> > > _______________________________________________ > Help-octave mailing list > Help-octave@ > https://lists.gnu.org/mailman/listinfo/help-octave Here's my latest code. It is the same as my original code except in the original I used sys = tf(b,a,SampleFrequency) instead of sys = tf(b,a). The original code and the data file (i.e. buckVfreqResp.csv) was attached to my previous post. Please tell me if you need anything else. Oh.. I just noticed something, I am using the sampling frequency instead of the sample time.. Stephen pkg load control; pkg load signal; clear all x = csvread('buckVfreqResp.csv'); SampleFrequency = 20000; f = x(:,1); r = x(:,2); phase_rad = x(:,3).*(pi/180); h = r.*cos(phase_rad) + r.*(sin(phase_rad)*i); w = f.*2*pi/SampleFrequency; [b,a] = invfreqz(h,w,12,14) sys = tf(b,a) bode(sys) -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by Doug Stewart-4
I updated my code to use the 1/SampleFrequency in the tf() function. It
seems to give me much better results. The code in my last post had n am m values for invfreqz() that were not related to my previous post. I had been playing around with those values to see if I could get a bode plot that was closer to the bode plot generated from the PSIM simulation frequency sweep. The code below uses the n and m values I had in my original code. How do I decide the n and m value --- by trial and error? Stephen pkg load control; pkg load signal; clear all x = csvread('buckVfreqResp.csv'); SampleFrequency = 20000; T = 1/SampleFrequency; f = x(:,1); r = x(:,2); phase_rad = x(:,3).*(pi/180); h = r.*cos(phase_rad) + r.*(sin(phase_rad)*i); w = f.*(2*pi*T); [b,a] = invfreqz(h,w,2,3) sys = tf(b,a) bode(sys) -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by Doug Stewart-4
Doug Stewart-4 wrote
> On Wed, Dec 6, 2017 at 4:57 PM, shall689 < > sahallacy@ > > wrote: > >> Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) instead >> of >> tf(b,a,SampleFrequency). >> >> The bode plot seem to match each other much better and the frequency >> range >> is a little better, with the only issue is that the max discrete >> frequency >> is 10 (>> pi). >> >> Is there some type of issue with the bode() function? >> >> >> <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot2.png> >> >> >> >> -- >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> f1599825.html >> >> > Hi Shall > If you would post your exact code, for me to run, then I am sure that I > can > answer your questions. > https://pastebin.com/ is one way to post it. > > > > -- > DAS > > <https://linuxcounter.net/user/206392.html> > > _______________________________________________ > Help-octave mailing list > Help-octave@ > https://lists.gnu.org/mailman/listinfo/help-octave https://pastebin.com/HwYAq4f6 -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by Doug Stewart-4
Doug Stewart-4 wrote
> On Wed, Dec 6, 2017 at 4:57 PM, shall689 < > sahallacy@ > > wrote: > >> Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) instead >> of >> tf(b,a,SampleFrequency). >> >> The bode plot seem to match each other much better and the frequency >> range >> is a little better, with the only issue is that the max discrete >> frequency >> is 10 (>> pi). >> >> Is there some type of issue with the bode() function? >> >> >> <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot2.png> >> >> >> >> -- >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> f1599825.html >> >> > Hi Shall > If you would post your exact code, for me to run, then I am sure that I > can > answer your questions. > https://pastebin.com/ is one way to post it. > > > > -- > DAS > > <https://linuxcounter.net/user/206392.html> > > _______________________________________________ > Help-octave mailing list > Help-octave@ > https://lists.gnu.org/mailman/listinfo/help-octave I looked at invfreqz.m and found out that that function is missing the "superior algorithm that guarantees stability of the resulting linear system and searches for the best fit using a numerical, iterative scheme" as mentioned in matlab's documentation. Stephen -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by shall689
On Wed, Dec 6, 2017 at 6:30 PM, shall689 <[hidden email]> wrote: I updated my code to use the 1/SampleFrequency in the tf() function. It I don't see how you are using n and m in this code? Doug
_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Doug Stewart-4 wrote
> On Wed, Dec 6, 2017 at 6:30 PM, shall689 < > sahallacy@ > > wrote: > >> I updated my code to use the 1/SampleFrequency in the tf() function. It >> seems to give me much better results. >> >> The code in my last post had n am m values for invfreqz() that were not >> related to my previous post. I had been playing around with those values >> to >> see if I could get a bode plot that was closer to the bode plot generated >> from the PSIM simulation frequency sweep. The code below uses the n and >> m >> values I had in my original code. How do I decide the n and m value --- >> by >> trial and error? >> >> I don't see how you are using n and m in this code? > Doug > > > > >> >> >> > > >> >> pkg load control; >> pkg load signal; >> clear all >> x = csvread('buckVfreqResp.csv'); >> SampleFrequency = 20000; >> T = 1/SampleFrequency; >> f = x(:,1); >> r = x(:,2); >> phase_rad = x(:,3).*(pi/180); >> h = r.*cos(phase_rad) + r.*(sin(phase_rad)*i); >> w = f.*(2*pi*T); >> [b,a] = invfreqz(h,w,2,3) >> sys = tf(b,a) >> bode(sys) >> >> >> >> -- >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> f1599825.html >> >> _______________________________________________ >> Help-octave mailing list >> > Help-octave@ >> https://lists.gnu.org/mailman/listinfo/help-octave >> > > > > -- > DAS[image: Certificate for 206392] > > <https://linuxcounter.net/user/206392.html> > > _______________________________________________ > Help-octave mailing list > Help-octave@ > https://lists.gnu.org/mailman/listinfo/help-octave Hello Doug, n and m represent n and m in the function [b,a] = invfreqz(h,w,n,m). Thanks, Stephen -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by Doug Stewart-4
Doug Stewart-4 wrote
> On Wed, Dec 6, 2017 at 4:57 PM, shall689 < > sahallacy@ > > wrote: > >> Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) instead >> of >> tf(b,a,SampleFrequency). >> >> The bode plot seem to match each other much better and the frequency >> range >> is a little better, with the only issue is that the max discrete >> frequency >> is 10 (>> pi). >> >> Is there some type of issue with the bode() function? >> >> >> <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot2.png> >> >> >> >> -- >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> f1599825.html >> >> > Hi Shall > If you would post your exact code, for me to run, then I am sure that I > can > answer your questions. > https://pastebin.com/ is one way to post it. > > > > -- > DAS > > <https://linuxcounter.net/user/206392.html> > > _______________________________________________ > Help-octave mailing list > Help-octave@ > https://lists.gnu.org/mailman/listinfo/help-octave The a and b were reversed in the tf() function. I corrected that issue (see below). Now, there is even a greater difference between the simulator's frequency response data and the transfer function returned by invfreqz(). Stephen pkg load control; pkg load signal; clear all close all clc x = csvread('buckVfreqResp.csv'); SampleFrequency = 20000; f = x(:,1); r = x(:,2); phase_rad = x(:,3).*(pi/180); h = r.*cos(phase_rad) + r.*(sin(phase_rad)*i); w = f.*2*pi/SampleFrequency; [b,a] = invfreqz(h,w,2,2) sys = tf(a,b,1/SampleFrequency) bode(sys); -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
On Thu, Dec 7, 2017 at 10:30 AM, shall689 <[hidden email]> wrote: Doug Stewart-4 wrote Sorry for the long delays. I think this is much closer to what you want. But it is giving me complex roots and they should be closer to 2 real roots. clear pkg load control; pkg load signal; clear all x = csvread('buckVfreqResp.csv'); SampleFrequency = 20000; T = 1/SampleFrequency; f = x(2:end,1); r = x(2:end,2); ph=x(2:end,3); figure(1) semilogx(f,r,f,ph) grid minor on # this shows that you have a total of 180 deg phase shift # and 90 deg is at about 515 Hrz # so you have a second order system with a corner freq of 515 Hz. phase_rad = ph.*(pi/180); w=2*pi*f; # now plot it with radians if you want to. figure(2) semilogx(w,r,w,phase_rad) grid minor on r1=10.^(r./20); figure(3) h = r1.*cos(ph) + r1.*(sin(ph)*i); w = f.*(2*pi*T); [b,a] = invfreqz(h,w,0,2) sys = tf(b,a,T) bode(sys) _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Doug Stewart-4 wrote
> On Thu, Dec 7, 2017 at 10:30 AM, shall689 < > sahallacy@ > > wrote: > >> Doug Stewart-4 wrote >> > On Wed, Dec 6, 2017 at 4:57 PM, shall689 < >> >> > sahallacy@ >> >> > > wrote: >> > >> >> Ok, I removed SampleFrequency from the tf function, i.e. tf(b,a) >> instead >> >> of >> >> tf(b,a,SampleFrequency). >> >> >> >> The bode plot seem to match each other much better and the frequency >> >> range >> >> is a little better, with the only issue is that the max discrete >> >> frequency >> >> is 10 (>> pi). >> >> >> >> Is there some type of issue with the bode() function? >> >> >> >> >> >> <http://octave.1599824.n4.nabble.com/file/t372348/BodePlot2.png> >> >> >> >> >> >> >> >> -- >> >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> >> f1599825.html >> >> >> >> >> > Hi Shall >> > If you would post your exact code, for me to run, then I am sure that I >> > can >> > answer your questions. >> > https://pastebin.com/ is one way to post it. >> > >> > >> > >> > -- >> > DAS >> > >> > <https://linuxcounter.net/user/206392.html> >> > >> > _______________________________________________ >> > Help-octave mailing list >> >> > Help-octave@ >> >> > https://lists.gnu.org/mailman/listinfo/help-octave >> >> >> The a and b were reversed in the tf() function. I corrected that issue >> (see >> below). Now, there is even a greater difference between the simulator's >> frequency response data and the transfer function returned by invfreqz(). >> >> Stephen >> >> >> pkg load control; >> pkg load signal; >> clear all >> close all >> clc >> x = csvread('buckVfreqResp.csv'); >> SampleFrequency = 20000; >> f = x(:,1); >> r = x(:,2); >> phase_rad = x(:,3).*(pi/180); >> h = r.*cos(phase_rad) + r.*(sin(phase_rad)*i); >> w = f.*2*pi/SampleFrequency; >> [b,a] = invfreqz(h,w,2,2) >> sys = tf(a,b,1/SampleFrequency) >> bode(sys); >> >> >> >> -- >> Sent from: http://octave.1599824.n4.nabble.com/Octave-General- >> f1599825.html >> >> _______________________________________________ >> Help-octave mailing list >> > Help-octave@ >> https://lists.gnu.org/mailman/listinfo/help-octave >> > Sorry for the long delays. > > I think this is much closer to what you want. > But it is giving me complex roots and they should be closer to 2 real > roots. > > clear > > pkg load control; > pkg load signal; > clear all > x = csvread('buckVfreqResp.csv'); > SampleFrequency = 20000; > T = 1/SampleFrequency; > f = x(2:end,1); > r = x(2:end,2); > ph=x(2:end,3); > figure(1) > semilogx(f,r,f,ph) > grid minor on > # this shows that you have a total of 180 deg phase shift > # and 90 deg is at about 515 Hrz > # so you have a second order system with a corner freq of 515 Hz. > > phase_rad = ph.*(pi/180); > w=2*pi*f; > # now plot it with radians if you want to. > figure(2) > semilogx(w,r,w,phase_rad) > grid minor on > > r1=10.^(r./20); > figure(3) > h = r1.*cos(ph) + r1.*(sin(ph)*i); > w = f.*(2*pi*T); > > > [b,a] = invfreqz(h,w,0,2) > sys = tf(b,a,T) > bode(sys) > > > > -- > DAS[image: Certificate for 206392] > > <https://linuxcounter.net/user/206392.html> > > _______________________________________________ > Help-octave mailing list > Help-octave@ > https://lists.gnu.org/mailman/listinfo/help-octave Hello Doug, That's closer. I think I was getting confused with rad and rad/sec. I was thinking that the x axis was rad. Is there a way to get the final transfer function to more closely match the cutoff frequency and low frequency gain? Thanks, Stephen -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Free forum by Nabble | Edit this page |