diff liboctave/CMatrix.cc @ 677:01da6806197b

[project @ 1994-09-08 04:43:13 by jwe]
author jwe
date Thu, 08 Sep 1994 04:43:59 +0000
parents 883197c5ad75
children d8295febb0df
line wrap: on
line diff
--- a/liboctave/CMatrix.cc	Thu Sep 08 04:42:58 1994 +0000
+++ b/liboctave/CMatrix.cc	Thu Sep 08 04:43:59 1994 +0000
@@ -1021,6 +1021,115 @@
   return ComplexMatrix (tmp_data, nr, nc);
 }
 
+ComplexMatrix
+ComplexMatrix::fourier2d (void) const
+{
+  int nr = rows ();
+  int nc = cols ();
+  int npts, nsamples;
+  if (nr == 1 || nc == 1)
+    {
+      npts = nr > nc ? nr : nc;
+      nsamples = 1;
+    }
+  else
+    {
+      npts = nr;
+      nsamples = nc;
+    }
+
+  int nn = 4*npts+15;
+  Complex *wsave = new Complex [nn];
+  Complex *tmp_data = dup (data (), length ());
+
+  F77_FCN (cffti) (&npts, wsave);
+
+  for (int j = 0; j < nsamples; j++)
+    F77_FCN (cfftf) (&npts, &tmp_data[npts*j], wsave);
+
+  delete [] wsave;
+
+  npts = nc;
+  nsamples = nr;
+  nn = 4*npts+15;
+  wsave = new Complex [nn];
+  Complex *row = new Complex[npts];
+
+  F77_FCN (cffti) (&npts, wsave);
+
+  for (j = 0; j < nsamples; j++)
+    {
+      for (int i = 0; i < npts; i++)
+	row[i] = tmp_data[i*nr + j];
+
+      F77_FCN (cfftf) (&npts, row, wsave);
+
+      for (i = 0; i < npts; i++)
+	tmp_data[i*nr + j] = row[i];
+    }
+
+  delete [] wsave;
+  delete [] row;
+
+  return ComplexMatrix (tmp_data, nr, nc);
+}
+
+ComplexMatrix
+ComplexMatrix::ifourier2d (void) const
+{
+  int nr = rows ();
+  int nc = cols ();
+  int npts, nsamples;
+  if (nr == 1 || nc == 1)
+    {
+      npts = nr > nc ? nr : nc;
+      nsamples = 1;
+    }
+  else
+    {
+      npts = nr;
+      nsamples = nc;
+    }
+
+  int nn = 4*npts+15;
+  Complex *wsave = new Complex [nn];
+  Complex *tmp_data = dup (data (), length ());
+
+  F77_FCN (cffti) (&npts, wsave);
+
+  for (int j = 0; j < nsamples; j++)
+    F77_FCN (cfftb) (&npts, &tmp_data[npts*j], wsave);
+
+  delete [] wsave;
+
+  for (j = 0; j < npts*nsamples; j++)
+    tmp_data[j] = tmp_data[j] / (double) npts;
+
+  npts = nc;
+  nsamples = nr;
+  nn = 4*npts+15;
+  wsave = new Complex [nn];
+  Complex *row = new Complex[npts];
+
+  F77_FCN (cffti) (&npts, wsave);
+
+  for (j = 0; j < nsamples; j++)
+    {
+      for (int i = 0; i < npts; i++)
+	row[i] = tmp_data[i*nr + j];
+
+      F77_FCN (cfftb) (&npts, row, wsave);
+
+      for (i = 0; i < npts; i++)
+	tmp_data[i*nr + j] = row[i] / (double) npts;
+    }
+
+  delete [] wsave;
+  delete [] row;
+
+  return ComplexMatrix (tmp_data, nr, nc);
+}
+
 ComplexDET
 ComplexMatrix::determinant (void) const
 {