help-octave
[Top][All Lists]
Advanced

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

Re: A question regarding unwrap


From: Doug Stewart
Subject: Re: A question regarding unwrap
Date: Sat, 24 Sep 2005 22:08:40 -0500
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Doug Stewart wrote:

Joe Koski wrote:

on 9/24/05 7:44 PM, Doug Stewart at address@hidden wrote:

Ron Crummett wrote:

Hi -

I have a recent problem with unwrap; I tried plotting the phase of a
transfer function and it jumped halfway through the plot, from -180 to
180.  I tried to unwrap the phase using unwrap and plotted the phase
again, but still had the same jump.  Reading the help on unwrap, it
sounds like it will only really work if the phase is positive (it adds
2*pi).  For me, I have a negative phase, so I need to subtract 2*pi.
Any idea of what the solution could be?  I tried looking at the code
but couldn't make too much sense out of it from my few glances.

Thanks,

Ron Crummett

Here is my new and improved version.
(better help)

try this "filter" with bode.m and with my  bode1w.m

n=poly([ -1+100j  -1-100j   -2+150j -2-150j  -3-200j -3+200j])
d=poly([-1 -2 -3 -4 -5 -6 ]*500)
bode1w(n,d)
s=tf2sys(n,d)
%bode(s)

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     bode1w (n,d)
%n= numerator
%d=denominator
%
% This was written to help my students with Gain Margin and Phase Margin
%GM and PM lines are added to the Bode plot and
%GM and PM values are printed on the screen.


## bode1w

## Author: doug
##
## 2004-09-27 doug
## * Initial revision
## Rev #1  Nov 29 2004 Doug Stewart
## Rev #2 Sept 2005 Doug Stewart
##              - Added the If for negative phase steps.
##              - and the DO loop

function     bode1w (n,d);

sys=tf2sys(n,d);
[mag,ph,w]=bode(sys);


# fix the phase wrap arownd
do
   ll=length(ph);
   [qm iqm]=max((diff(ph)));
   if(qm>300)
    ph(iqm+1:ll)=ph(iqm+1:ll)-360;
   endif
   [qm iqm]=min((diff(ph)));
   if(qm<-300)
   ph(iqm+1:ll)=ph(iqm+1:ll)+360;
   endif
until (abs(qm)<300)




# 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
-------------------------------------------------------------



reply via email to

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