changeset 3269:c6a82a2a31ae octave-forge

genqammod.m
author adb014
date Fri, 23 Mar 2007 20:25:12 +0000
parents 73fa4496fb07
children a34457658a11
files main/comm/inst/apkconst.m main/comm/inst/eyediagram.m main/comm/inst/genqammod.m main/comm/inst/modmap.m main/comm/inst/qaskenco.m main/comm/inst/scatterplot.m
diffstat 6 files changed, 164 insertions(+), 319 deletions(-) [+]
line wrap: on
line diff
--- a/main/comm/inst/apkconst.m	Fri Mar 23 16:14:46 2007 +0000
+++ b/main/comm/inst/apkconst.m	Fri Mar 23 20:25:12 2007 +0000
@@ -37,7 +37,7 @@
 ## in each ASK radii.
 ##
 ## In addition @dfn{apkconst} takes two string arguments 'n' and and @var{str}.
-## If the string 'n' is included in the erguments, then a number is printed
+## If the string 'n' is included in the arguments, then a number is printed
 ## next to each constellation point giving the symbol value that would be
 ## mapped to this point by the @dfn{modmap} function. The argument @var{str}
 ## is a plot style string (example 'r+') and determines the default gnuplot
@@ -63,7 +63,7 @@
 
   numargs = 0;
   printnums = 0;
-  fmt = "w p 1";
+  fmt = "+r";
   amp = [];
   phs = [];
 
@@ -78,7 +78,7 @@
 	  printnums = 0;
 	end
       else
-	fmt = __pltopt__ ("apkconst", arg);
+	fmt = arg;
       endif
     else
       numargs++;
@@ -126,43 +126,23 @@
   end
 
   if (nargout == 0)
-    try ar = automatic_replot();
-    catch ar = 0;
-    end
+    r = [0:0.02:2]'*pi;
+    x0 = cos(r) * amp;
+    y0 = sin(r) * amp;
+    plot(x0, y0, "b");
+    yy = [real(y), imag(y)];
+    hold on;
+    if (printnums)
+      xd = 0.05 * max(real(y));
+      for i=1:length(y)
+	text(real(y(i))+xd,imag(y(i)),num2str(i-1));
+      end
+    endif
+    plot (real(y), imag(y), fmt);
 
-    unwind_protect
-      clearplot;
-      title("ASK/PSK Constellation");
-      xlabel("In-phase");
-      ylabel("Quadrature");
-      axis([-1.1*max(amp), 1.1*max(amp), -1.1*max(amp), 1.1*max(amp)]);
-      legend("off");
-      hold off;
-      r = [0:0.02:2]'*pi;
-      x0 = cos(r) * amp;
-      y0 = sin(r) * amp;
-      plot(x0, y0, "2");
-      hold on;
-      yy = [real(y), imag(y)];
-      if (printnums)
-	xd = 0.05 * max(real(y));
-	for i=1:length(y)
-	  text(real(y(i))+xd,imag(y(i)),num2str(i-1));
-	end
-      endif
-      cmd = sprintf("__gnuplot_plot__ yy %s;", fmt);
-      eval(cmd);
-    unwind_protect_cleanup
-      xlabel("");
-      ylabel("");
-      title("");
-      axis();
-      hold off;
-      if (printnums)
-        text();
-      endif
-      automatic_replot(ar);
-    end_unwind_protect
+    title("ASK/PSK Constellation");
+    xlabel("In-phase");
+    ylabel("Quadrature");
   else
     yout = y;
   endif
--- a/main/comm/inst/eyediagram.m	Fri Mar 23 16:14:46 2007 +0000
+++ b/main/comm/inst/eyediagram.m	Fri Mar 23 20:25:12 2007 +0000
@@ -57,7 +57,7 @@
 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com>
 ##     * modified for new gnuplot interface (octave > 2.9.0)
 
-function hout = eyediagram (x, n, _per, _off, str, h)
+function varargout = eyediagram (x, n, _per, _off, str, h)
 
   if ((nargin < 2) || (nargin > 6))
     usage (" h = eyediagram (x, n [, per [, off [, str [, h]]]])");
@@ -118,153 +118,83 @@
 
   if (nargin > 4)
     if (isempty(str))
-      fmt = "w l 1";
+      fmt = "-r";
     elseif (ischar(str))
-      fmt = __pltopt__ ("eyediagram", str);
+      fmt = str;
     else
       error ("eyediagram: plot format must be a string");
     endif
   else
-    fmt = "w l 1";
+    fmt = "-r";
   endif
 
   if (nargin > 5)
     if (isempty(h))
-      if (!gnuplot_has_frames)
-	hout = figure ();
-      else
-	hout = 0;
-      endif
-    elseif (!isscalar(h) || !isreal(h) || (floor(h) != h) || (h < 0))
-      error ("eyediagram: figure handle must be a positive integer");
+      hout = figure ();
     else
-      if (!gnuplot_has_frames)
-	error ("eyediagram: gnuplot must have frames for figure handles");
-      endif
       hout = figure (h);
     endif
   else
-    if (!gnuplot_has_frames)
-      hout = figure ();
-    else
-      hout = 0;
-    endif
+    hout = figure ();
   endif
 
-  neven = (2*floor(n/2) == n);
-  if (neven)
-    horiz = (per*[0:n]/n - per/2)';
-  else
-    horiz = (n-2)/(n-1)*(per*[0:n-1]/(n-1) - per/2)';
+  horiz = (per*[0:n]/n - per/2)';
+  if (2*floor(n/2) != n)
+    horiz = horiz - per / n / 2;
   endif
   lx = length(xr);
   off = mod(off+ceil(n/2),n);
-
-  ## Need to save data to a temporary file, since we use line breaks
-  ## in the file to specify a discontinous plot to gnuplot plot. This
-  ## is much faster than multiple plot commands.....
-  tmpfile = tmpnam();
-  try mark_for_deletion(tmpfile);
-  catch 
-    warning("eyediagram: temporary file %s will not be deleted!\n",tmpfile)
-  end
-  fid = fopen(tmpfile,"w+t");
-  if (fid == -1)
-    error ("eyediagram: error opening temporary file");
+  Nn = ceil((off + lx) / n);
+  post = Nn*n - off - lx;
+  xr = reshape([NaN * ones(off,1); xr; NaN * ones(post,1)],n,Nn);
+  xr = [xr ; [xr(1,2:end), NaN]];
+  xr = [xr; NaN*ones(1,Nn)];
+  if (all(isnan(xr(2:end,end))))
+    xr(:,end) = [];
+    horiz = [repmat(horiz(1:n+1),1,Nn-1);NaN*ones(1,Nn-1)](:);
+  else
+    horiz = [repmat(horiz(1:n+1),1,Nn);NaN*ones(1,Nn)](:);
   endif
-  if (strcmp(signal,"complex"))
-    if (off != 0)
-      fprintf(fid, "%10.3e %10.3e %10.3e\n", [horiz(n-off+1:n), xr(1:off), ...
-					      xi(1:off)]');
-      if (neven && (lx != off))
-	fprintf(fid, "%10.3e %10.3e %10.3e\n", [horiz(n+1), xr(off+1), ...
-						xi(off+1)]');
-      endif
-      fprintf(fid, "\n");
-      indx = off;
-    else
-      indx = 0;
-    endif
 
-    while ((lx-indx) >= n)
-      fprintf(fid, "%10.3e %10.3e %10.3e\n", [horiz(1:n), xr(indx+1:indx+n), ...
-					      xi(indx+1:indx+n)]');
-      if (neven && (lx != indx+n))
-	fprintf(fid, "%10.3e %10.3e %10.3e\n", [horiz(n+1), xr(indx+n+1), ...
-						xi(indx+n+1)]');
-      endif
-      fprintf(fid, "\n");
-      indx = indx + n;
-    endwhile
-
-    if ((lx-indx) != 0)
-      fprintf(fid, "%10.3e %10.3e %10.3e\n", [horiz(1:lx-indx), ...
-					     xr(indx+1:lx), xi(indx+1:lx)]');
-    endif
-  else
-    if (off != 0)
-      fprintf(fid, "%10.3e %10.3e\n", [horiz(n-off+1:n), xr(1:off)]');
-      if (neven && (lx != off))
-	fprintf(fid, "%10.3e %10.3e\n", [horiz(n+1), xr(off+1)]');
-      endif
-      fprintf(fid, "\n");
-      indx = off;
-    else
-      indx = 0;
-    endif
-
-    while ((lx-indx) >= n)
-      fprintf(fid, "%10.3e %10.3e\n", [horiz(1:n), xr(indx+1:indx+n)]');
-      if (neven && (lx != indx+n))
-	fprintf(fid, "%10.3e %10.3e\n", [horiz(n+1), xr(indx+n+1)]');
-      endif
-      fprintf(fid, "\n");
-      indx = indx + n;
-    endwhile
-
-    if ((lx-indx) != 0)
-      fprintf(fid, "%10.3e %10.3e\n", [horiz(1:lx-indx), xr(indx+1:lx)]');
+  if (strcmp(signal,"complex"))
+    xi = reshape([NaN * ones(off,1); xi; NaN * ones(post,1)],n,Nn);
+    xi = [xi ; [xi(1,2:end), NaN]];
+    xi = [xi; NaN*ones(1,Nn)];
+    if (all(isnan(xi(2:end,end))))
+      xi(:,end) = [];
     endif
   endif
-  fclose(fid);
 
-  try ar = automatic_replot();
-  catch ar = 0;
-  end
-
-  unwind_protect
-    if (strcmp(signal,"complex"))
-      subplot(2,1,1);
-      title("Eye-diagram for in-phase signal");
-    else
-      oneplot();
-      title("Eye-diagram for signal");
-    endif
+  if (strcmp(signal,"complex"))
+    subplot(2,1,1);
+    plot(horiz,xr(:),fmt);
+    title("Eye-diagram for in-phase signal");
+    xlabel("Time");
+    ylabel("Amplitude");
+    subplot(2,1,2);
+    plot(horiz,xi(:),fmt);
+    title("Eye-diagram for quadrature signal");
+    xlabel("Time");
+    ylabel("Amplitude");
+  else
+    plot(horiz,xr(:),fmt);
+    title("Eye-diagram for signal");
     xlabel("Time");
     ylabel("Amplitude");
-    
-    legend("off");
-    hold off;
-    __gnuplot_plot__  tmpfile ;
-    if (strcmp(signal,"complex"))
-      subplot(2,1,2);
-      title("Eye-diagram for quadrature signal");
-      __gnuplot_plot__ tmpfile using 1:3;
-    endif
+  endif
 
-  unwind_protect_cleanup
-    xlabel("");
-    ylabel("");
-    title("");
-    if (strcmp(signal,"complex"))
-      oneplot();
-    endif
-    automatic_replot(ar);
-  end_unwind_protect
-
-  ## XXX FIXME XXX
-  ## Can't unlink the tmpfile now, since can't guarantee gnuplot finished
-  ## with it!!!
-  ## [u, msg] = unlink(tmpfile);
+  if (nargout > 0)
+    varargout{1} = hout;
+  endif
 
 endfunction
+
+%!demo
+%! n = 50;
+%! ovsp=50;
+%! x = 1:n;
+%! xi = [1:1/ovsp:n-0.1];
+%! y = randsrc(1,n,[1 + 1i, 1 - 1i, -1 - 1i, -1 + 1i]) ;
+%! yi = interp1(x,y,xi);
+%! noisy = awgn(yi,15,"measured");
+%! eyediagram(noisy,ovsp);
--- a/main/comm/inst/genqammod.m	Fri Mar 23 16:14:46 2007 +0000
+++ b/main/comm/inst/genqammod.m	Fri Mar 23 20:25:12 2007 +0000
@@ -12,7 +12,7 @@
 ##
 ## You should have received a copy of the GNU General Public License
 ## along with this program; see the file COPYING.  If not, write to the Free
-## Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02110-1301, USA.
+## Software Foundation, 51 Franklin Street, Fifth Flooor, Boston, MA  02110-1301, USA.
 ##
 
 ## -*- texinfo -*-
--- a/main/comm/inst/modmap.m	Fri Mar 23 16:14:46 2007 +0000
+++ b/main/comm/inst/modmap.m	Fri Mar 23 20:25:12 2007 +0000
@@ -148,10 +148,6 @@
     endif
   endif
 
-  try ar = automatic_replot();
-  catch ar = 0;
-  end
-
   if (strcmp(method,"ask"))
     if (nargin > optarg + 1)
       error ("modmap: too many arguments");
@@ -201,23 +197,14 @@
       endif
 
       ## This is an ugly plot, with little info. But hey!!!
-      unwind_protect
-	title("MSK constellation");
-	xlabel("Frequency (Hz)");
-	ylabel("");
-	axis([-fd, 2*fd, 0, 2]);
-	try stem ([0, fd], [2, 1]);
-	catch
-	  error ("modmap: can not find stem-plot function");
-	end
-      unwind_protect_cleanup
-	xlabel("");
-	ylabel("");
-	title("");
-	__gnuplot_set__ autoscale;
-	hold off;
-        automatic_replot(ar);
-      end_unwind_protect
+      try stem ([0, fd], [2, 1]);
+      catch
+	error ("modmap: can not find stem-plot function");
+      end
+      title("MSK constellation");
+      xlabel("Frequency (Hz)");
+      ylabel("");
+      axis([-fd, 2*fd, 0, 2]);
     else
       if (nargin > optarg)
 	error ("modmap: too many arguments");
@@ -240,23 +227,14 @@
 
     if (nargout == 0)
       ## This is an ugly plot, with little info. But hey!!!
-      unwind_protect
-	title("FSK constellation");
-	xlabel("Frequency (Hz)");
-	ylabel("");
-	axis([-tone, M*tone, 0, 2]);
-	try stem ([0:tone:(M-1)*tone], [2, ones(1,M-1)]);
-	catch
-	  error ("modmap: can not find stem-plot function");
-	end
-      unwind_protect_cleanup
-	xlabel("");
-	ylabel("");
-	title("");
-	__gnuplot_set__ autoscale;
-	hold off;
-        automatic_replot(ar);
-      end_unwind_protect
+      try stem ([0:tone:(M-1)*tone], [2, ones(1,M-1)]);
+      catch
+	error ("modmap: can not find stem-plot function");
+      end
+      title("FSK constellation");
+      xlabel("Frequency (Hz)");
+      ylabel("");
+      axis([-tone, M*tone, 0, 2]);
     else
       y = tone * x;
     endif
@@ -317,40 +295,25 @@
     endif
     
     if (nargout == 0)
-      unwind_protect
-	inphase = inphase(:);
-	quadr = quadr(:);
-	clearplot;
-	title("QASK Constellation");
-	xlabel("In-phase");
-	ylabel("Quadrature");
-	axis([min(inphase)-1, max(inphase)+1, min(quadr)-1, max(quadr)+1]);
-	__gnuplot_set__ nokey;
-	hold off;
-	yy = [inphase, quadr];
-	eval("__gnuplot_plot__ yy w p 1;");
-	hold on;
-	xd = 0.02 * max(inphase);
-	if (nargin == 2)
-	  msg = msg(:);
-	  for i=1:length(inphase)
-	    text(inphase(i)+xd,quadr(i),num2str(msg(i)));
-	  end
-	else
-	  for i=1:length(inphase)
-	    text(inphase(i)+xd,quadr(i),num2str(i-1));
-	  end
-	endif
-	replot;
-      unwind_protect_cleanup
-	xlabel("");
-	ylabel("");
-	title("");
-	__gnuplot_set__ autoscale;
-	hold off;
-	text();
-        automatic_replot(ar);
-      end_unwind_protect
+      inphase = inphase(:);
+      quadr = quadr(:);
+      plot (inphase, quadr, "+r");
+      title("QASK Constellation");
+      xlabel("In-phase");
+      ylabel("Quadrature");
+      axis([min(inphase)-1, max(inphase)+1, min(quadr)-1, max(quadr)+1]);
+      xd = 0.02 * max(inphase);
+      if (nargin == 2)
+	msg = msg(:);
+	for i=1:length(inphase)
+	  text(inphase(i)+xd,quadr(i),num2str(msg(i)));
+	end
+      else
+	for i=1:length(inphase)
+	  text(inphase(i)+xd,quadr(i),num2str(i-1));
+	end
+      endif
+      replot;
     else
       y = inphase(x+1) + 1i * quadr(x+1);
       if (size(x,2) == 1)
--- a/main/comm/inst/qaskenco.m	Fri Mar 23 16:14:46 2007 +0000
+++ b/main/comm/inst/qaskenco.m	Fri Mar 23 20:25:12 2007 +0000
@@ -153,45 +153,24 @@
   endif
 
   if (nargout == 0)
-    try ar = automatic_replot();
-    catch ar = 0;
-    end
-
-    unwind_protect
-      automatic_replot (0)
-      inphase = inphase(:);
-      quadr = quadr(:);
-      clearplot;
-      title("QASK Constellation");
-      xlabel("In-phase");
-      ylabel("Quadrature");
-      axis([min(inphase)-1, max(inphase)+1, min(quadr)-1, max(quadr)+1]);
-      legend("off");
-      hold off;
-      yy = [inphase, quadr];
-      __gnuplot_plot__ yy w p 1;
-      hold on;
-      xd = 0.02 * max(inphase);
-      if (nargin == 2)
-	msg = msg(:);
-	for i=1:length(inphase)
-	  text(inphase(i)+xd,quadr(i),num2str(msg(i)));
-	end
-      else
-	for i=1:length(inphase)
-	  text(inphase(i)+xd,quadr(i),num2str(i-1));
-	end
-      endif
-      replot;
-    unwind_protect_cleanup
-      xlabel("");
-      ylabel("");
-      title("");
-      axis();
-      hold off;
-      text();
-      automatic_replot (ar);
-    end_unwind_protect
+    inphase = inphase(:);
+    quadr = quadr(:);
+    plot (inphase, quadr, "r+");
+    title("QASK Constellation");
+    xlabel("In-phase");
+    ylabel("Quadrature");
+    axis([min(inphase)-1, max(inphase)+1, min(quadr)-1, max(quadr)+1]);
+    xd = 0.02 * max(inphase);
+    if (nargin == 2)
+      msg = msg(:);
+      for i=1:length(inphase)
+	text(inphase(i)+xd,quadr(i),num2str(msg(i)));
+      end
+    else
+      for i=1:length(inphase)
+	text(inphase(i)+xd,quadr(i),num2str(i-1));
+      end
+    endif
   elseif (nargout == 1)
     a = inphase + 1i * quadr;
   else
--- a/main/comm/inst/scatterplot.m	Fri Mar 23 16:14:46 2007 +0000
+++ b/main/comm/inst/scatterplot.m	Fri Mar 23 20:25:12 2007 +0000
@@ -54,7 +54,7 @@
 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com>
 ##     * modified for new gnuplot interface (octave > 2.9.0)
 
-function hout = scatterplot (x, n, _off, str, h)
+function varargout = scatterplot (x, n, _off, str, h)
 
   if ((nargin < 1) || (nargin > 5))
     usage (" h = scatterplot (x, n [, off [, str [, h]]]])");
@@ -64,6 +64,7 @@
     if (min(size(x)) == 1)
       signal = "real";
       xr = x(:);
+      xi = zeros(size(xr));
     elseif (size(x,2) == 2)
       signal = "complex";
       xr = x(:,1);
@@ -104,63 +105,55 @@
 
   if (nargin > 3)
     if (isempty(str))
-      fmt = "w p 1";
+      fmt = "-r";
     elseif (ischar(str))
-      fmt = __pltopt__ ("scatterplot", str);
+      fmt = str;
     else
       error ("scatterplot: plot format must be a string");
     endif
   else
-    fmt = "w p 1";
+    fmt = "-r";
   endif
 
   if (nargin > 4)
-    if (!isscalar(h) || !isreal(h) || (floor(h) != h) || (h < 0))
-      error ("scatterplot: figure handle must be a positive integer");
-    endif
-    if (!gnuplot_has_frames)
-      error ("scatterplot: gnuplot must have frames for figure handles");
-    endif
     hout = figure (h);
-    hold on;
   else
-    if (!gnuplot_has_frames)
-      hout = figure ();
-    else
-      hout = 0;
-    endif
-    hold off;
+    hout = figure ();
   endif
 
-  if (strcmp(signal,"complex"))
-    spts = [xr,xi];
-  else
-    spts = [xr,zeros(length(xr),1)];
-  endif
-  spts = spts(off+1:n:rows(xr),:);
-
-  try ar = automatic_replot();
-  catch ar = 0;
-  end
+  xr = xr(off+1:n:rows(xr));
+  xi = xi(off+1:n:rows(xi));
 
-  unwind_protect
-    title("Scatter plot");
-    xlabel("In-phase");
-    ylabel("Quadrature");
-    legend("off");
-    if (!strcmp(signal,"complex"))
-      __gnuplot_raw__ ("set yrange [-1:1];\n")
-    endif
-    
-    cmd = sprintf("__gnuplot_plot__ spts %s", fmt);
-    eval(cmd);
+  plot(xr,xi,fmt);
+  if (!strcmp(signal,"complex"))
+    ## FIXME: What is the appropriate xrange
+    xmax = max(xr);
+    xmin = min(xr);
+    xran = xmax - xmin
+    xmax =  ceil(2 * xmax / xran) / 2 * xran;
+    xmin = floor(2 * xmin / xran) / 2 * xran;
+    axis([xmin, xmax, -1, 1]);
+  endif
+  title("Scatter plot");
+  xlabel("In-phase");
+  ylabel("Quadrature");
+  legend("off");
 
-  unwind_protect_cleanup
-##    xlabel("");
-##    ylabel("");
-##    axis();
-##    title("");
-    automatic_replot(ar);
-  end_unwind_protect
+  if (nargout > 0)
+    varargout{1} = hout;
+  endif
 
 endfunction
+
+%!demo
+%! n = 200;
+%! ovsp=5;
+%! x = 1:n;
+%! xi = [1:1/ovsp:n-0.1];
+%! y = randsrc(1,n,[1 + 1i, 1 - 1i, -1 - 1i, -1 + 1i]) ;
+%! yi = interp1(x,y,xi);
+%! noisy = awgn(yi,15,"measured");
+%! hold off;
+%! h = scatterplot(noisy,1,0,"b",1);
+%! hold on;
+%! scatterplot(noisy,ovsp,0,"r+",h);