r256: *** empty log message ***
[ctsim.git] / libctsim / procsignal.cpp
index 70d759cbacc471f96ab39b3d8fb3ea3dd990e378..cd44cf834d8bd0d2b776c1a0a48f958229114329 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: procsignal.cpp,v 1.2 2000/08/22 07:02:48 kevin Exp $
+**  $Id: procsignal.cpp,v 1.9 2000/12/16 02:44:26 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -77,7 +77,7 @@ const int ProcessSignal::s_iFilterGenerationCount = sizeof(s_aszFilterGeneration
 // CLASS IDENTIFICATION
 //   ProcessSignal
 //
-ProcessSignal::ProcessSignal (const char* szFilterName, const char* szFilterMethodName, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const char* szDomainName, const char* szFilterGenerationName, int iZeropad = 0, int iPreinterpolationFactor = 1, int iTraceLevel = TRACE_NONE)
+ProcessSignal::ProcessSignal (const char* szFilterName, const char* szFilterMethodName, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const char* szDomainName, const char* szFilterGenerationName, int iZeropad, int iPreinterpolationFactor, int iTraceLevel, int iGeometry, double dFocalLength, SGP* pSGP)
     : m_adFourierCosTable(NULL), m_adFourierSinTable(NULL), m_adFilter(NULL), m_fail(false)
 {
   m_idFilterMethod = convertFilterMethodNameToID (szFilterMethodName);
@@ -109,17 +109,21 @@ ProcessSignal::ProcessSignal (const char* szFilterName, const char* szFilterMeth
     return;
   }
 
-  init (m_idFilter, m_idFilterMethod, dBandwidth, dSignalIncrement, nSignalPoints, dFilterParam, m_idDomain, m_idFilterGeneration, iZeropad, iPreinterpolationFactor, iTraceLevel);
+  init (m_idFilter, m_idFilterMethod, dBandwidth, dSignalIncrement, nSignalPoints, dFilterParam, m_idDomain, m_idFilterGeneration, iZeropad, iPreinterpolationFactor, iTraceLevel, iGeometry, dFocalLength, pSGP);
 }
 
 
 void
-ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const int idDomain, const int idFilterGeneration, const int iZeropad, const int iPreinterpolationFactor, int iTraceLevel)
-{
+ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const int idDomain, const int idFilterGeneration, const int iZeropad, const int iPreinterpolationFactor, int iTraceLevel, int iGeometry, double dFocalLength, SGP* pSGP)
+{\r
+  int i;
   m_idFilter = idFilter;
   m_idDomain = idDomain;
   m_idFilterMethod = idFilterMethod;
   m_idFilterGeneration = idFilterGeneration;
+  m_idGeometry = iGeometry;
+  m_dFocalLength = dFocalLength;
+
   if (m_idFilter == SignalFilter::FILTER_INVALID || m_idDomain == SignalFilter::DOMAIN_INVALID || m_idFilterMethod == FILTER_METHOD_INVALID || m_idFilterGeneration == FILTER_GENERATION_INVALID) {
     m_fail = true;
     return;
@@ -134,6 +138,13 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
   m_iZeropad = iZeropad;
   m_iPreinterpolationFactor = iPreinterpolationFactor;
 
+  // scale signalInc/BW to signalInc/2 to adjust for imaginary detector
+  // through origin of phantom, see Kak-Slaney Fig 3.22, for Collinear
+  if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+    m_dSignalInc /= 2;
+    m_dBandwidth *= 2;
+  }
+
   if (m_idFilterMethod == FILTER_METHOD_FFT) {
 #if HAVE_FFTW
     m_idFilterMethod = FILTER_METHOD_RFFTW;
@@ -166,64 +177,72 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
        m_dFilterInc = (m_dFilterMax - m_dFilterMin) / (m_nFilterPoints - 1);
        SignalFilter filter (m_idFilter, m_dFilterMin, m_dFilterMax, m_nFilterPoints, m_dBandwidth, m_dFilterParam, SignalFilter::DOMAIN_FREQUENCY);
        m_adFilter = new double[ m_nFilterPoints ];
-       double adFrequencyFilter [m_nFilterPoints];
+       double* adFrequencyFilter = new double [m_nFilterPoints];
        filter.copyFilterData (adFrequencyFilter, 0, m_nFilterPoints);
-       if (m_traceLevel >= TRACE_PLOT) {
-         SGPDriver sgpDriver ("Frequency Filter: Natural Order");
-         SGP sgp (sgpDriver);
-         EZPlot ezplot (sgp);
-
-         ezplot.ezset ("title Filter Response: Natural Order");
-         ezplot.addCurve (adFrequencyFilter, m_nFilterPoints);
-         ezplot.plot();
-         cio_put_str ("Press any key to continue");
-         cio_kb_getc ();
+#ifdef HAVE_SGP
+       EZPlot* pEZPlot = NULL;
+       if (pSGP && m_traceLevel >= Trace::TRACE_PLOT) {
+         pEZPlot = new EZPlot (*pSGP);
+         pEZPlot->ezset ("title Filter Response: Natural Order");
+         pEZPlot->ezset ("ylength 0.25");
+         pEZPlot->addCurve (adFrequencyFilter, m_nFilterPoints);
+         pEZPlot->plot();
        }
-           
+#endif     
        shuffleNaturalToFourierOrder (adFrequencyFilter, m_nFilterPoints);
-       if (m_traceLevel >= TRACE_PLOT) {
-         SGPDriver sgpDriver ("Frequency Filter: Fourier Order");
-         SGP sgp (sgpDriver);
-         EZPlot ezplot (sgp);
-
-         ezplot.ezset ("title Filter Response: Fourier Order");
-         ezplot.addCurve (adFrequencyFilter, m_nFilterPoints);
-         ezplot.plot();
-         cio_put_str ("Press any key to continue");
-         cio_kb_getc ();
+#ifdef HAVE_SGP
+       if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+         pEZPlot->ezset ("title Filter Response: Fourier Order");
+         pEZPlot->ezset ("ylength 0.25");
+         pEZPlot->ezset ("yporigin 0.25");
+         pEZPlot->addCurve (adFrequencyFilter, m_nFilterPoints);
+         pEZPlot->plot();
        }
+#endif
        ProcessSignal::finiteFourierTransform (adFrequencyFilter, m_adFilter, m_nFilterPoints, -1);
-       if (m_traceLevel >= TRACE_PLOT) {
-         SGPDriver sgpDriver ("Inverse Fourier Frequency: Fourier Order");
-         SGP sgp (sgpDriver);
-         EZPlot ezplot (sgp);
-
-         ezplot.ezset ("title Inverse Fourier Frequency: Fourier Order");
-         ezplot.addCurve (m_adFilter, m_nFilterPoints);
-         ezplot.plot();
-         cio_put_str ("Press any key to continue");
-         cio_kb_getc ();
+       delete adFrequencyFilter;\r
+#ifdef HAVE_SGP
+       if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+         pEZPlot->ezset ("title Inverse Fourier Frequency: Fourier Order");
+         pEZPlot->ezset ("ylength 0.25");
+         pEZPlot->ezset ("yporigin 0.50");
+         pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+         pEZPlot->plot();
        }
+#endif
        shuffleFourierToNaturalOrder (m_adFilter, m_nFilterPoints);
-       if (m_traceLevel >= TRACE_PLOT) {
-         SGPDriver sgpDriver ("Inverse Fourier Frequency: Natural Order");
-         SGP sgp (sgpDriver);
-         EZPlot ezplot (sgp);
-
-         ezplot.ezset ("title Inverse Fourier Frequency: Natural Order");
-         ezplot.addCurve (m_adFilter, m_nFilterPoints);
-         ezplot.plot();
-         cio_put_str ("Press any key to continue");
-         cio_kb_getc ();
+#ifdef HAVE_SGP
+       if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+         pEZPlot->ezset ("title Inverse Fourier Frequency: Natural Order");
+         pEZPlot->ezset ("ylength 0.25");
+         pEZPlot->ezset ("yporigin 0.75");
+         pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+         pEZPlot->plot();
+         delete pEZPlot;
        }
-       for (int i = 0; i < m_nFilterPoints; i++) {
+#endif
+       for (i = 0; i < m_nFilterPoints; i++) {
            m_adFilter[i] /= m_dSignalInc;
        }
     }
-  } 
+    if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+       for (i = 0; i < m_nFilterPoints; i++)
+           m_adFilter[i] *= 0.5;
+    } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+       for (i = 0; i < m_nFilterPoints; i++) {
+         int iDetFromZero = i - ((m_nFilterPoints - 1) / 2);
+         double sinScale = sin (iDetFromZero * m_dSignalInc);
+         if (fabs(sinScale) < 1E-7)
+             sinScale = 1;
+         else
+             sinScale = (iDetFromZero * m_dSignalInc) / sinScale;
+         double dScale = 0.5 * sinScale * sinScale;
+         m_adFilter[i] *= dScale;
+       }
+    } // if (geometry)
+  } // if (spatial filtering)
 
-  // Frequency-based filtering
-  else if (m_bFrequencyFiltering) {
+  else if (m_bFrequencyFiltering) {  // Frequency-based filtering
 
     if (m_idFilterGeneration == FILTER_GENERATION_DIRECT) {
       // calculate number of filter points with zeropadding
@@ -235,8 +254,10 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
          nextPowerOf2++;
        nextPowerOf2 += (m_iZeropad - 1);
        m_nFilterPoints = 1 << nextPowerOf2;
-       if (m_traceLevel >= TRACE_TEXT)
-       cout << "nFilterPoints = " << m_nFilterPoints << endl;
+#ifdef DEBUG
+       if (m_traceLevel >= Trace::TRACE_CONSOLE)
+         cout << "nFilterPoints = " << m_nFilterPoints << endl;
+#endif
       }
       m_nOutputPoints = m_nFilterPoints * m_iPreinterpolationFactor;
 
@@ -254,29 +275,46 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
       SignalFilter filter (m_idFilter, m_dFilterMin, m_dFilterMax, m_nFilterPoints, m_dBandwidth, m_dFilterParam, SignalFilter::DOMAIN_FREQUENCY);
       m_adFilter = new double [m_nFilterPoints];
       filter.copyFilterData (m_adFilter, 0, m_nFilterPoints);
-      if (m_traceLevel >= TRACE_PLOT) {
-       SGPDriver sgpDriver ("Frequency Filter: Natural Order");
-       SGP sgp (sgpDriver);
-       EZPlot ezplot (sgp);
-       
-       ezplot.ezset ("title Filter Filter: Natural Order");
-       ezplot.addCurve (m_adFilter, m_nFilterPoints);
-         ezplot.plot();
-         cio_put_str ("Press any key to continue");
-         cio_kb_getc ();
+
+      // This doesn't work!
+      // Need to add filtering for divergent geometries & Frequency/Direct filtering
+      if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+       for (i = 0; i < m_nFilterPoints; i++)
+         m_adFilter[i] *= 0.5;
+      } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+       for (i = 0; i < m_nFilterPoints; i++) {
+         int iDetFromZero = i - ((m_nFilterPoints - 1) / 2);
+         double sinScale = sin (iDetFromZero * m_dSignalInc);
+         if (fabs(sinScale) < 1E-7)
+           sinScale = 1;
+         else
+           sinScale = (iDetFromZero * m_dSignalInc) / sinScale;
+         double dScale = 0.5 * sinScale * sinScale;
+         m_adFilter[i] *= dScale;
+       }
+      }
+#ifdef HAVE_SGP
+      EZPlot* pEZPlot = NULL;
+      if (pSGP && m_traceLevel >= Trace::TRACE_PLOT) {
+       pEZPlot = new EZPlot (*pSGP);
+       pEZPlot->ezset ("title Filter Filter: Natural Order");
+       pEZPlot->ezset ("ylength 0.50");
+       pEZPlot->ezset ("yporigin 0.00");
+       pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+       pEZPlot->plot();
       }
+#endif
       shuffleNaturalToFourierOrder (m_adFilter, m_nFilterPoints);
-       if (m_traceLevel >= TRACE_PLOT) {
-         SGPDriver sgpDriver ("Frequency Filter: Fourier Order");
-         SGP sgp (sgpDriver);
-         EZPlot ezplot (sgp);
-
-         ezplot.ezset ("title Filter Filter: Fourier Order");
-         ezplot.addCurve (m_adFilter, m_nFilterPoints);
-         ezplot.plot();
-         cio_put_str ("Press any key to continue");
-         cio_kb_getc ();
-       }
+#ifdef HAVE_SGP
+      if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+       pEZPlot->ezset ("title Filter Filter: Fourier Order");
+       pEZPlot->ezset ("ylength 0.50");
+       pEZPlot->ezset ("yporigin 0.50");
+       pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+       pEZPlot->plot();
+       delete pEZPlot;
+      }
+#endif
     } else if (m_idFilterGeneration == FILTER_GENERATION_INVERSE_FOURIER) {
       // calculate number of filter points with zeropadding
       int nSpatialPoints = 2 * (m_nSignalPoints - 1) + 1;
@@ -293,52 +331,71 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
        m_nFilterPoints = 1 << nextPowerOf2;
       }
       m_nOutputPoints = m_nFilterPoints * m_iPreinterpolationFactor;
-      if (m_traceLevel >= TRACE_TEXT)
+#ifdef DEBUG
+      if (m_traceLevel >= Trace::TRACE_CONSOLE)
        cout << "nFilterPoints = " << m_nFilterPoints << endl;
-      double adSpatialFilter [m_nFilterPoints];
+#endif
+      double* adSpatialFilter = new double [m_nFilterPoints];\r
       SignalFilter filter (m_idFilter, m_dFilterMin, m_dFilterMax, nSpatialPoints, m_dBandwidth, m_dFilterParam, SignalFilter::DOMAIN_SPATIAL);
       filter.copyFilterData (adSpatialFilter, 0, nSpatialPoints);
-      if (m_traceLevel >= TRACE_PLOT) {
-       SGPDriver sgpDriver ("Spatial Filter: Natural Order");
-       SGP sgp (sgpDriver);
-       EZPlot ezplot (sgp);
-       
-       ezplot.ezset ("title Spatial Filter: Natural Order");
-       ezplot.addCurve (adSpatialFilter, nSpatialPoints);
-       ezplot.plot();
-       cio_put_str ("Press any key to continue");
-       cio_kb_getc ();
+#ifdef HAVE_SGP
+      EZPlot* pEZPlot = NULL;
+      if (pSGP && m_traceLevel >= Trace::TRACE_PLOT) {
+       pEZPlot = new EZPlot (*pSGP);
+       pEZPlot->ezset ("title Spatial Filter: Natural Order");
+       pEZPlot->ezset ("ylength 0.50");
+       pEZPlot->ezset ("yporigin 0.00");
+       pEZPlot->addCurve (adSpatialFilter, nSpatialPoints);
+       pEZPlot->plot();
+       delete pEZPlot;
       }
-      for (int i = nSpatialPoints; i < m_nFilterPoints; i++)
+#endif
+      if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+       for (i = 0; i < m_nFilterPoints; i++)
+         adSpatialFilter[i] *= 0.5;
+      } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+       for (i = 0; i < m_nFilterPoints; i++) {
+         int iDetFromZero = i - ((m_nFilterPoints - 1) / 2);
+         double sinScale = sin (iDetFromZero * m_dSignalInc);
+         if (fabs(sinScale) < 1E-7)
+           sinScale = 1;
+         else
+           sinScale = (iDetFromZero * m_dSignalInc) / sinScale;
+         double dScale = 0.5 * sinScale * sinScale;
+         adSpatialFilter[i] *= dScale;
+       }
+      }\r
+      for (i = nSpatialPoints; i < m_nFilterPoints; i++)
        adSpatialFilter[i] = 0;
 
       m_adFilter = new double [m_nFilterPoints];
-      complex<double> acInverseFilter [m_nFilterPoints];
+      complex<double>* acInverseFilter = new complex<double> [m_nFilterPoints];\r
       finiteFourierTransform (adSpatialFilter, acInverseFilter, m_nFilterPoints, 1);
-      for (int i = 0; i < m_nFilterPoints; i++)
-       m_adFilter[i] = abs(acInverseFilter[i]) * m_dSignalInc;
-      if (m_traceLevel >= TRACE_PLOT) {
-       SGPDriver sgpDriver ("Spatial Filter: Inverse");
-       SGP sgp (sgpDriver);
-       EZPlot ezplot (sgp);
-       
-       ezplot.ezset ("title Spatial Filter: Inverse");
-       ezplot.addCurve (m_adFilter, m_nFilterPoints);
-       ezplot.plot();
-       cio_put_str ("Press any key to continue");
-       cio_kb_getc ();
+       delete adSpatialFilter;\r
+       for (i = 0; i < m_nFilterPoints; i++)
+         m_adFilter[i] = abs(acInverseFilter[i]) * m_dSignalInc;
+       delete acInverseFilter;\r
+#ifdef HAVE_SGP
+      if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+       pEZPlot->ezset ("title Spatial Filter: Inverse");
+       pEZPlot->ezset ("ylength 0.50");
+       pEZPlot->ezset ("yporigin 0.50");
+       pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+       pEZPlot->plot();
+       delete pEZPlot;\r
       }
+#endif
     }
   }
   
   // precalculate sin and cosine tables for fourier transform
   if (m_idFilterMethod == FILTER_METHOD_FOURIER_TABLE) {
-    int nFourier = max(m_nFilterPoints,m_nOutputPoints) * max(m_nFilterPoints, m_nOutputPoints) + 1;
+    int nFourier = imax (m_nFilterPoints,m_nOutputPoints) * imax (m_nFilterPoints, m_nOutputPoints) + 1;
     double angleIncrement = (2. * PI) / m_nFilterPoints;
     m_adFourierCosTable = new double[ nFourier ];
     m_adFourierSinTable = new double[ nFourier ];
     double angle = 0;
-    for (int i = 0; i < nFourier; i++) {
+    for (i = 0; i < nFourier; i++) {
       m_adFourierCosTable[i] = cos (angle);
       m_adFourierSinTable[i] = sin (angle);
       angle += angleIncrement;
@@ -347,7 +404,7 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
 
 #if HAVE_FFTW
   if (m_idFilterMethod == FILTER_METHOD_FFTW || m_idFilterMethod == FILTER_METHOD_RFFTW) {
-    for (int i = 0; i < m_nFilterPoints; i++)  //fftw uses unnormalized fft
+    for (i = 0; i < m_nFilterPoints; i++)  //fftw uses unnormalized fft
       m_adFilter[i] /= m_nFilterPoints;
   }
 
@@ -356,16 +413,16 @@ ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandw
     m_realPlanBackward = rfftw_create_plan (m_nOutputPoints, FFTW_COMPLEX_TO_REAL, FFTW_ESTIMATE);
     m_adRealFftInput = new fftw_real [ m_nFilterPoints ];
     m_adRealFftSignal = new fftw_real [ m_nOutputPoints ];
-    for (int i = 0; i < m_nFilterPoints; i++) 
+    for (i = 0; i < m_nFilterPoints; i++) 
       m_adRealFftInput[i] = 0;
   } else if (m_idFilterMethod == FILTER_METHOD_FFTW) {
     m_complexPlanForward = fftw_create_plan (m_nFilterPoints, FFTW_FORWARD, FFTW_ESTIMATE);
     m_complexPlanBackward = fftw_create_plan (m_nOutputPoints, FFTW_BACKWARD, FFTW_ESTIMATE);
     m_adComplexFftInput = new fftw_complex [ m_nFilterPoints ];
     m_adComplexFftSignal = new fftw_complex [ m_nOutputPoints ];
-    for (int i = 0; i < m_nFilterPoints; i++) 
+    for (i = 0; i < m_nFilterPoints; i++) 
       m_adComplexFftInput[i].re = m_adComplexFftInput[i].im = 0;
-    for (int i = 0; i < m_nOutputPoints; i++) 
+    for (i = 0; i < m_nOutputPoints; i++) 
       m_adComplexFftSignal[i].re = m_adComplexFftSignal[i].im = 0;
   }
 #endif
@@ -468,72 +525,99 @@ ProcessSignal::convertFilterGenerationIDToTitle (const int fgID)
 }
 
 void
-ProcessSignal::filterSignal (const float input[], double output[]) const
+ProcessSignal::filterSignal (const float constInput[], double output[]) const
 {
+  double* input = new double [m_nSignalPoints];
+  int i;\r
+  for (i = 0; i < m_nSignalPoints; i++)
+    input[i] = constInput[i];
+
+  if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+    for (int i = 0; i < m_nSignalPoints; i++) {
+      int iDetFromCenter = i - (m_nSignalPoints / 2);
+      input[i] *= m_dFocalLength / sqrt (m_dFocalLength * m_dFocalLength + iDetFromCenter * iDetFromCenter * m_dSignalInc * m_dSignalInc);
+    }
+  } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+    for (int i = 0; i < m_nSignalPoints; i++) {
+      int iDetFromCenter = i - (m_nSignalPoints / 2);
+      input[i] *= m_dFocalLength * cos (iDetFromCenter * m_dSignalInc);
+    }
+  }\r
   if (m_idFilterMethod == FILTER_METHOD_CONVOLUTION) {
-    for (int i = 0; i < m_nSignalPoints; i++)
-      output[i] = convolve (input, m_dSignalInc, i, m_nSignalPoints);
+      for (i = 0; i < m_nSignalPoints; i++)
+       output[i] = convolve (input, m_dSignalInc, i, m_nSignalPoints);
   } else if (m_idFilterMethod == FILTER_METHOD_FOURIER) {
-    double inputSignal[m_nFilterPoints];
-    for (int i = 0; i < m_nSignalPoints; i++)
+    double* inputSignal = new double [m_nFilterPoints];
+    for (i = 0; i < m_nSignalPoints; i++)
       inputSignal[i] = input[i];
-    for (int i = m_nSignalPoints; i < m_nFilterPoints; i++)
+    for (i = m_nSignalPoints; i < m_nFilterPoints; i++)
       inputSignal[i] = 0;  // zeropad
-    complex<double> fftSignal[m_nFilterPoints];
-    finiteFourierTransform (inputSignal, fftSignal, m_nFilterPoints, -1);
-    for (int i = 0; i < m_nFilterPoints; i++)
+    complex<double>* fftSignal = new complex<double> [m_nFilterPoints];
+    finiteFourierTransform (inputSignal, fftSignal, m_nFilterPoints, -1);\r
+       delete inputSignal;
+    for (i = 0; i < m_nFilterPoints; i++)
       fftSignal[i] *= m_adFilter[i];
-    double inverseFourier[m_nFilterPoints];
-    finiteFourierTransform (fftSignal, inverseFourier, m_nFilterPoints, 1);
-    for (int i = 0; i < m_nSignalPoints; i++) 
-      output[i] = inverseFourier[i];
+    double* inverseFourier = new double [m_nFilterPoints];
+    finiteFourierTransform (fftSignal, inverseFourier, m_nFilterPoints, 1);\r
+       delete fftSignal;
+    for (i = 0; i < m_nSignalPoints; i++) 
+      output[i] = inverseFourier[i];\r
+       delete inverseFourier;
   } else if (m_idFilterMethod == FILTER_METHOD_FOURIER_TABLE) {
-    double inputSignal[m_nFilterPoints];
-    for (int i = 0; i < m_nSignalPoints; i++)
+    double* inputSignal = new double [m_nFilterPoints];
+    for (i = 0; i < m_nSignalPoints; i++)
       inputSignal[i] = input[i];
-    for (int i = m_nSignalPoints; i < m_nFilterPoints; i++)
+    for (i = m_nSignalPoints; i < m_nFilterPoints; i++)
       inputSignal[i] = 0;  // zeropad
-    complex<double> fftSignal[m_nFilterPoints];
-    finiteFourierTransform (inputSignal, fftSignal, -1);
-    for (int i = 0; i < m_nFilterPoints; i++)
+    complex<double>* fftSignal = new complex<double> [m_nFilterPoints];
+    finiteFourierTransform (inputSignal, fftSignal, -1);\r
+       delete inputSignal;
+    for (i = 0; i < m_nFilterPoints; i++)
       fftSignal[i] *= m_adFilter[i];
-    double inverseFourier[m_nFilterPoints];
-    finiteFourierTransform (fftSignal, inverseFourier, 1);
-    for (int i = 0; i < m_nSignalPoints; i++) 
-      output[i] = inverseFourier[i];
+    double* inverseFourier = new double [m_nFilterPoints];
+    finiteFourierTransform (fftSignal, inverseFourier, 1);\r
+       delete fftSignal;
+    for (i = 0; i < m_nSignalPoints; i++) 
+      output[i] = inverseFourier[i];\r
+       delete inverseFourier;
   }
 #if HAVE_FFTW
   else if (m_idFilterMethod == FILTER_METHOD_RFFTW) {
-      for (int i = 0; i < m_nSignalPoints; i++)
+      for (i = 0; i < m_nSignalPoints; i++)
          m_adRealFftInput[i] = input[i];
 
-      fftw_real fftOutput [ m_nFilterPoints ];
+      fftw_real* fftOutput = new fftw_real [ m_nFilterPoints ];
       rfftw_one (m_realPlanForward, m_adRealFftInput, fftOutput);
-      for (int i = 0; i < m_nFilterPoints; i++)
-         m_adRealFftSignal[i] = m_adFilter[i] * fftOutput[i];
-      for (int i = m_nFilterPoints; i < m_nOutputPoints; i++)
-       m_adRealFftSignal[i] = 0;
+      for (i = 0; i < m_nFilterPoints; i++)
+           m_adRealFftSignal[i] = m_adFilter[i] * fftOutput[i];\r
+         delete [] fftOutput;
+      for (i = m_nFilterPoints; i < m_nOutputPoints; i++)
+            m_adRealFftSignal[i] = 0;
 
-      fftw_real ifftOutput [ m_nOutputPoints ];
+      fftw_real* ifftOutput = new fftw_real [ m_nOutputPoints ];
       rfftw_one (m_realPlanBackward, m_adRealFftSignal, ifftOutput);
-      for (int i = 0; i < m_nSignalPoints * m_iPreinterpolationFactor; i++)
-         output[i] = ifftOutput[i];
+      for (i = 0; i < m_nSignalPoints * m_iPreinterpolationFactor; i++)
+           output[i] = ifftOutput[i];\r
+         delete [] ifftOutput;
   } else if (m_idFilterMethod == FILTER_METHOD_FFTW) {
-      for (int i = 0; i < m_nSignalPoints; i++)
+      for (i = 0; i < m_nSignalPoints; i++)
          m_adComplexFftInput[i].re = input[i];
 
-      fftw_complex fftOutput [ m_nFilterPoints ];
+      fftw_complex* fftOutput = new fftw_complex [ m_nFilterPoints ];
       fftw_one (m_complexPlanForward, m_adComplexFftInput, fftOutput);
-      for (int i = 0; i < m_nFilterPoints; i++) {
+      for (i = 0; i < m_nFilterPoints; i++) {
          m_adComplexFftSignal[i].re = m_adFilter[i] * fftOutput[i].re;
          m_adComplexFftSignal[i].im = m_adFilter[i] * fftOutput[i].im;
-      }
-      fftw_complex ifftOutput [ m_nOutputPoints ];
+      }\r
+         delete [] fftOutput;
+      fftw_complex* ifftOutput = new fftw_complex [ m_nOutputPoints ];
       fftw_one (m_complexPlanBackward, m_adComplexFftSignal, ifftOutput);
-      for (int i = 0; i < m_nSignalPoints * m_iPreinterpolationFactor; i++) 
-         output[i] = ifftOutput[i].re;
+      for (i = 0; i < m_nSignalPoints * m_iPreinterpolationFactor; i++) 
+         output[i] = ifftOutput[i].re;\r
+         delete [] ifftOutput;
   }
-#endif
+#endif\r
+  delete input;
 }
 
 
@@ -602,11 +686,12 @@ for (int i = 0; i < np; i++)
 void
 ProcessSignal::finiteFourierTransform (const double input[], double output[], const int n, int direction)
 {
-    complex<double> complexOutput[n];
+    complex<double>* complexOutput = new complex<double> [n];
 
     finiteFourierTransform (input, complexOutput, n, direction);
     for (int i = 0; i < n; i++)
-       output[i] = complexOutput[i].real();
+       output[i] = complexOutput[i].real();\r
+       delete [] complexOutput;
 }
 
 void
@@ -780,25 +865,26 @@ ProcessSignal::finiteFourierTransform (const complex<double> input[], double out
 void
 ProcessSignal::shuffleNaturalToFourierOrder (double* pdVector, const int n)
 {
-  double* pdTemp = new double [n];
+  double* pdTemp = new double [n];\r
+  int i;
   if (n % 2) { // Odd
     int iHalfN = (n - 1) / 2;
     
     pdTemp[0] = pdVector[iHalfN];
-    for (int i = 0; i < iHalfN; i++)
+    for (i = 0; i < iHalfN; i++)
       pdTemp[i + 1] = pdVector[i + 1 + iHalfN];
-    for (int i = 0; i < iHalfN; i++)
+    for (i = 0; i < iHalfN; i++)
       pdTemp[i + iHalfN + 1] = pdVector[i];
   } else {     // Even
       int iHalfN = n / 2;
       pdTemp[0] = pdVector[iHalfN];
-      for (int i = 0; i < iHalfN; i++)
+      for (i = 0; i < iHalfN; i++)
        pdTemp[i + 1] = pdVector[i + iHalfN];
-      for (int i = 0; i < iHalfN - 1; i++)
+      for (i = 0; i < iHalfN - 1; i++)
        pdTemp[i + iHalfN + 1] = pdVector[i];
   }
 
-  for (int i = 0; i < n; i++)
+  for (i = 0; i < n; i++)
     pdVector[i] = pdTemp[i];
   delete pdTemp;
 }
@@ -807,25 +893,26 @@ ProcessSignal::shuffleNaturalToFourierOrder (double* pdVector, const int n)
 void
 ProcessSignal::shuffleFourierToNaturalOrder (double* pdVector, const int n)
 {
-  double* pdTemp = new double [n];
+  double* pdTemp = new double [n];\r
+  int i;
   if (n % 2) { // Odd
     int iHalfN = (n - 1) / 2;
     
-    pdTemp[iHalfN] = pdVector[0];
-    for (int i = 0; i < iHalfN; i++)
+    pdTemp[iHalfN] = pdVector[0];\r
+       for (i = 0; i < iHalfN; i++)
       pdTemp[i + 1 + iHalfN] = pdVector[i + 1];
-    for (int i = 0; i < iHalfN; i++)
+    for (i = 0; i < iHalfN; i++)
       pdTemp[i] = pdVector[i + iHalfN + 1];
   } else {     // Even
       int iHalfN = n / 2;
       pdTemp[iHalfN] = pdVector[0];
-      for (int i = 0; i < iHalfN; i++)
+      for (i = 0; i < iHalfN; i++)
        pdTemp[i] = pdVector[i + iHalfN];
-      for (int i = 0; i < iHalfN - 1; i++)
+      for (i = 0; i < iHalfN - 1; i++)
        pdTemp[i + iHalfN + 1] = pdVector[i+1];
   }
 
-  for (int i = 0; i < n; i++)
+  for (i = 0; i < n; i++)
     pdVector[i] = pdTemp[i];
   delete pdTemp;
 }