Re: freqz_plot alterations

Daniel J Sebald <[email protected]> Thu, 05 Aug 2004 13:35:54 -0500
Newsgroups gmane.comp.gnu.octave.graphics
Message-ID <[email protected]>
Daniel J Sebald wrote:
 > For anyone interested, attached are some slight alterations
 > to the freqz_plot.m file.  The three plots are made to have the
 > same height and the tics for the phase angle are made more
 > congruous with 5, 15, 30, 45, 60, etc  (Being able to specify a
 > sample rate, i.e., non-normalized frequency would be nice,
 > but probably not compatible.)

Sorry, I forgot the unified flag.  A new diff file is attached.

Also, I've noticed a roundoff problem with the right border using 
gnuplot.  Sometimes the right border is slightly to the left of the 
vertical grid line and tic.  The issue is that

      axis ([ w(1), w(n), maxmag-3, maxmag ]);

translates to

gset xrange [0:1.99805]

(i.e., w(n) = 1.99805) which causes the aberration, whereas

gset xrange [0:2]

avoids the aberration.  I've posted to the gnuplot beta list wondering 
if this is gnuplot's problem or not.  (My opinion is that it is.)

Dan
freqz_plot.patch (text/plain, 2.1 KB)
--- /usr/src/redhat/SOURCES/octave-2.1.57/scripts/signal/freqz_plot.m	Mon Nov 24 21:59:41 2003
+++ freqz_plot-2.1.57-mod.m	Thu Aug  5 13:15:48 2004
@@ -1,3 +1,14 @@
+## EXPERIMENTAL CODE!!! by Dan Sebald. (Aug 5, 2004)
+##
+## This file is NOT part of the Octave distribution.
+##
+## This file is a variation of the freqz_plot.m file from version
+## 2.1.57.  The plot locations are changed so that all plot heights
+## are the same.  Also, the phase plot attempts to choose a more
+## appropriate tic for angles.
+##
+## =====================================================================
+##
 ## Copyright (C) 2002 John W. Eaton
 ##
 ## This file is part of Octave.
@@ -45,6 +56,10 @@
       automatic_replot = 0;
 
       subplot (311);
+      gset size 1,0.26;
+      gset origin 0,0.72;
+      gset bmargin 0;
+      gset tmargin 0;
       gset lmargin 10;
       axis ("labely");
       xlabel ("");
@@ -52,11 +67,10 @@
       axis ([ w(1), w(n), maxmag-3, maxmag ]);
       plot (w, mag, ";Pass band (dB);");
 
-      subplot (312);
+      gset origin 0,0.42;
       axis ("labely");
       title ("");
       xlabel ("");
-      gset tmargin 0;
       grid ("on");
       if (maxmag - min (mag) > 100)
       	axis ([ w(1), w(n), maxmag-100, maxmag ]);
@@ -65,10 +79,28 @@
       endif
       plot (w, mag, ";Stop band (dB);");
       
-      subplot (313);
+      gset origin 0,0.12;
       axis ("label");
       title ("");
       grid ("on");
+      phasediff = (max (phase) - min (phase))*360/(2*pi);
+      if (phasediff < 5)
+	gset ytics autofreq;
+      elseif (phasediff < 30)
+	gset ytics 5;
+      elseif (phasediff < 90)
+	gset ytics 15;
+      elseif (phasediff < 180)
+	gset ytics 30;
+      elseif (phasediff < 240)
+	gset ytics 45;
+      elseif (phasediff < 360)
+	gset ytics 60;
+      elseif (phasediff < 540)
+	gset ytics 90;
+      else
+	gset ytics autofreq;
+      endif
       axis ("autoy");
       xlabel ("Frequency");
       axis ([ w(1), w(n) ]);
@@ -86,6 +118,8 @@
       axis ("auto", "label");
       gset lmargin;
       gset tmargin;
+      gset bmargin;
+      gset ytics autofreq;
       oneplot ();
 
       automatic_replot = replot_state;