help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to find gain margin


From: Kai Shing Lee
Subject: Re: how to find gain margin
Date: Thu, 19 May 2005 16:30:30 +0800 (CST)

Thanks. 

I enhance it a bit by adding the followings. Any
comment?


# find the Phase Margin and its location

[pm ipx]=min(abs(mag-1));
PM=180+ph(ipx);

mg=mag(ipx);
mg=abs(mg-1);
if ( mg > 0.05 )
        printf("Gain=1 is not found.\n");
else
        printf("PM = %4.2f\n",PM);
endif



--- Doug Stewart <address@hidden> 撰寫:
> Kai Shing Lee wrote:
> 
> >Does anyone know how to find gain margin in octave
> ?
> >
> >  
> >
> 
> Here is one way to do it.
> Doug Stewart
> 
> 
> ## Copyright (C) 2004 doug
> ##
> ## This program is free software; you can
> redistribute it and/or modify
> ## it under the terms of the GNU General Public
> License as published by
> ## the Free Software Foundation; either version 2 of
> the License, or
> ## (at your option) any later version.
> ##
> ## This program is distributed in the hope that it
> will be useful,
> ## but WITHOUT ANY WARRANTY; without even the
> implied warranty of
> ## MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE. See the
> ## GNU General Public License for more details.
> ##
> ## You should have received a copy of the GNU
> General Public License
> ## along with this program; if not, write to the
> Free Software
> ## Foundation, Inc., 59 Temple Place, Suite 330,
> Boston, MA 02111-1307 USA
> %
> %function bode1 (n,d)
> %n= numerator
> % d=denominator
> %
> 
> ## bode1w
> 
> ## Author: Doug Stewart
> ##
> ## 2004-09-27 doug
> ## * Initial revision
> ## Rev #1 Nov 29 2004 Doug Stewart
> 
> function bode1w (n,d);
> 
> sys=tf2sys(n,d);
> [mag,ph,w]=bode(sys);
> 
> # fix the phase wrap arownd
> ll=length(ph);
> [qm iqm]=max(abs(diff(ph)));
> if(qm>300)
> ph(iqm+1:ll)=ph(iqm+1:ll)-360;
> endif
> 
> 
> # make a 180 deg line
> v=ones(ll,1)*(-180);
> db=20*log10(mag);
> 
> # find the Gain Margin and its location
> [x ix]=min(abs(ph+180));
> if (x>1)
> GM="INF"
> ix=length(ph);
> else
> Gm=20*log10(mag(ix))
> endif
> 
> # find the Phase Margin and its location
> [pmx ipmx]=min(abs(mag-1));
> PM=180+ph(ipmx)
> 
> 
> #f=w/(2*pi);
> semilogx(w,db,1,0,w,ph,w,v,[w(ix) w(ix)],[30 -180]
> ,[w(ipmx) w(ipmx)],[0
> -200])
> gset grid mxtics xtics ytics
> replot
> 
> endfunction
> 
> 
> 
>
-------------------------------------------------------------
> Octave is freely available under the terms of the
> GNU GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects: 
> http://www.octave.org/funding.html
> Subscription information: 
> http://www.octave.org/archive.html
>
-------------------------------------------------------------
> 
> 

__________________________________
想即時收到新 email 通知?
下載 Yahoo! Messenger
http://messenger.yahoo.com.hk/



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]