Update to wx3.0, add SSE optimizations based on target_cpu, fix compile warnings
[ctsim.git] / libctsim / filter.cpp
index e8038aad7203790f5beb15462dcf96272401abd0..397f8a204120926ed04516653b5e1b2ca1d0f654 100644 (file)
@@ -1,15 +1,13 @@
 /*****************************************************************************
-** FILE IDENTIFICATION
-** 
+** File IDENTIFICATION
+**
 **     Name:                   filter.cpp
 **     Purpose:                Routines for signal-procesing filters
-**     Progammer:             Kevin Rosenberg
+**     Progammer:              Kevin Rosenberg
 **     Date Started:           Aug 1984
 **
 **  This is part of the CTSim program
-**  Copyright (C) 1983-2000 Kevin Rosenberg
-**
-**  $Id: filter.cpp,v 1.4 2000/06/25 17:32:24 kevin Exp $
+**  Copyright (c) 1983-2009 Kevin Rosenberg
 **
 **  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
 
 #include "ct.h"
 
+int SignalFilter::N_INTEGRAL=500;  //static member
+
+const int SignalFilter::FILTER_INVALID = -1 ;
+const int SignalFilter::FILTER_ABS_BANDLIMIT = 0;       // filter times |x|
+const int SignalFilter::FILTER_ABS_G_HAMMING = 1;
+const int SignalFilter::FILTER_ABS_HANNING = 2;
+const int SignalFilter::FILTER_ABS_COSINE = 3;
+const int SignalFilter::FILTER_ABS_SINC = 4;
+const int SignalFilter::FILTER_SHEPP = 5;
+const int SignalFilter::FILTER_BANDLIMIT = 6;
+const int SignalFilter::FILTER_SINC = 7;
+const int SignalFilter::FILTER_G_HAMMING = 8;
+const int SignalFilter::FILTER_HANNING = 9;
+const int SignalFilter::FILTER_COSINE = 10;
+const int SignalFilter::FILTER_TRIANGLE = 11;
+
+const int SignalFilter::s_iReconstructFilterCount = 4;
+
+const char* const SignalFilter::s_aszFilterName[] = {
+  "abs_bandlimit",
+  "abs_hamming",
+  "abs_hanning",
+  "abs_cosine",
+  "shepp",
+  "abs_sinc",
+  "bandlimit",
+  "sinc",
+  "hamming",
+  "hanning",
+  "cosine",
+  "triangle"
+};
+
+const char* const SignalFilter::s_aszFilterTitle[] = {
+  "Abs(w) * Bandlimit",
+  "Abs(w) * Hamming",
+  "Abs(w) * Hanning",
+  "Abs(w) * Cosine",
+  "Shepp",
+  "Abs(w) * Sinc",
+  "Bandlimit",
+  "Sinc",
+  "Hamming",
+  "Hanning",
+  "Cosine",
+  "Triangle"
+};
+
+const int SignalFilter::s_iFilterCount = sizeof(s_aszFilterName) / sizeof(const char*);
+
+
+const int SignalFilter::DOMAIN_INVALID = -1;
+const int SignalFilter::DOMAIN_FREQUENCY = 0;
+const int SignalFilter::DOMAIN_SPATIAL = 1;
+
+const char* const SignalFilter::s_aszDomainName[] = {
+  "frequency",
+  "spatial",
+};
+
+const char* const SignalFilter::s_aszDomainTitle[] = {
+  "Frequency",
+  "Spatial",
+};
+
+const int SignalFilter::s_iDomainCount = sizeof(s_aszDomainName) / sizeof(const char*);
+
 
 /* NAME
- *   SignalFilter::SignalFilter     Construct a signal
- *
- * SYNOPSIS
- *   f = SignalFilter (filt_type, bw, xmin, xmax, n, param, domain, analytic)
- *   double f          Generated filter vector
- *   int filt_type     Type of filter wanted
- *   double bw         Bandwidth of filter
- *   double xmin, xmax Filter limits
- *   int n             Number of points in filter
- *   double param      General input parameter to filters
- *   int domain                FREQ or SPATIAL domain wanted
- *   int numint                Number if intervals for calculating discrete inverse fourier xform
- *                     for spatial domain filters.  For ANALYTIC solutions, use numint = 0
- */
-
-SignalFilter::SignalFilter (const char* filterName, double bw, double xmin, double xmax, int n, double param, const char* domainName, int numIntegral = 0)
+*   SignalFilter::SignalFilter     Construct a signal
+*
+* SYNOPSIS
+*   f = SignalFilter (filt_type, bw, filterMin, filterMax, n, param, domain, analytic)
+*   double f            Generated filter vector
+*   int filt_type       Type of filter wanted
+*   double bw           Bandwidth of filter
+*   double filterMin, filterMax Filter limits
+*   int nFilterPoints   Number of points in signal
+*   double param        General input parameter to filters
+*   int domain          FREQUENCY or SPATIAL domain wanted
+*/
+
+SignalFilter::SignalFilter (const char* szFilterName, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const char* szDomainName)
+: m_adFilter(NULL), m_fail(false)
 {
-  m_vecFilter = NULL;
-  m_idFilter = convertFilterNameToID (filterName);
+  m_idFilter = convertFilterNameToID (szFilterName);
   if (m_idFilter == FILTER_INVALID) {
     m_fail = true;
     m_failMessage = "Invalid Filter name ";
-    m_failMessage += filterName;
+    m_failMessage += szFilterName;
     return;
   }
-  m_idDomain = convertDomainNameToID (domainName);
+  m_idDomain = convertDomainNameToID (szDomainName);
   if (m_idDomain == DOMAIN_INVALID) {
     m_fail = true;
     m_failMessage = "Invalid domain name ";
-    m_failMessage += domainName;
+    m_failMessage += szDomainName;
     return;
   }
-  init (m_idFilter, bw, xmin, xmax, n, param, m_idDomain, numIntegral);
+  init (m_idFilter, dFilterMinimum, dFilterMaximum, nFilterPoints, dBandwidth, dFilterParam, m_idDomain);
 }
 
-SignalFilter::SignalFilter (const FilterID filterID, double bw, double xmin, double xmax, int n, double param, const DomainID domainID, int numIntegral = 0)
+SignalFilter::SignalFilter (const int idFilter, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain)
+: m_adFilter(NULL), m_fail(false)
 {
-  init (filterID, bw, xmin, xmax, n, param, domainID, numIntegral);
+  init (idFilter, dFilterMinimum, dFilterMaximum, nFilterPoints, dBandwidth, dFilterParam, idDomain);
 }
 
-SignalFilter::SignalFilter (const char* filterName, const char* domainName, double bw, double param, int numIntegral = 0)
+SignalFilter::SignalFilter (const char* szFilterName, const char* szDomainName, double dBandwidth, double dFilterParam)
+: m_adFilter(NULL), m_fail(false)
 {
-  m_bw = bw;
-  m_nPoints = 0;
-  m_vecFilter = NULL;
-  m_filterParam = param;  
-  m_numIntegral = numIntegral;
-  m_idFilter = convertFilterNameToID (filterName);
+  m_nFilterPoints = 0;
+  m_dBandwidth = dBandwidth;
+  m_dFilterParam = dFilterParam;
+  m_idFilter = convertFilterNameToID (szFilterName);
   if (m_idFilter == FILTER_INVALID) {
     m_fail = true;
     m_failMessage = "Invalid Filter name ";
-    m_failMessage += filterName;
+    m_failMessage += szFilterName;
     return;
   }
-  m_idDomain = convertDomainNameToID (domainName);
+  m_idDomain = convertDomainNameToID (szDomainName);
   if (m_idDomain == DOMAIN_INVALID) {
     m_fail = true;
     m_failMessage = "Invalid domain name ";
-    m_failMessage += domainName;
+    m_failMessage += szDomainName;
     return;
   }
 }
 
 void
-SignalFilter::init (const FilterID filterID, double bw, double xmin, double xmax, int n, double param, const DomainID domainID, int numint)
+SignalFilter::init (const int idFilter, double dFilterMinimum, double dFilterMaximum, int nFilterPoints, double dBandwidth, double dFilterParam, const int idDomain)
 {
-  m_bw = bw;
-  m_idFilter = filterID;
-  m_idDomain = domainID;
+  m_idFilter = idFilter;
+  m_idDomain = idDomain;
   if (m_idFilter == FILTER_INVALID || m_idDomain == DOMAIN_INVALID) {
     m_fail = true;
     return;
   }
+  if (nFilterPoints < 2) {
+    m_fail = true;
+    m_failMessage = "Number of filter points ";
+    m_failMessage += nFilterPoints;
+    m_failMessage = " less than 2";
+    return;
+  }
+
   m_nameFilter = convertFilterIDToName (m_idFilter);
   m_nameDomain = convertDomainIDToName (m_idDomain);
-  m_fail = false;
-  m_nPoints = n;
-  m_xmin = xmin;
-  m_xmax = xmax;
-  m_numIntegral = numint;
-  m_filterParam = param;  
-  m_vecFilter = new double[n];
+  m_nFilterPoints = nFilterPoints;
+  m_dFilterParam = dFilterParam;
+  m_dBandwidth = dBandwidth;
+  m_dFilterMin = dFilterMinimum;
+  m_dFilterMax = dFilterMaximum;
+
+  m_dFilterInc = (m_dFilterMax - m_dFilterMin) / (m_nFilterPoints - 1);
+  m_adFilter = new double [m_nFilterPoints];
+
+  if (m_idDomain == DOMAIN_FREQUENCY)
+    createFrequencyFilter (m_adFilter);
+  else if (m_idDomain == DOMAIN_SPATIAL)
+    createSpatialFilter (m_adFilter);
+}
+
+
+SignalFilter::~SignalFilter (void)
+{
+  delete [] m_adFilter;
+}
+
+void
+SignalFilter::createFrequencyFilter (double* adFilter) const
+{
+  double x;
+  int i;
+  for (x = m_dFilterMin, i = 0; i < m_nFilterPoints; x += m_dFilterInc, i++)
+    adFilter[i] = frequencyResponse (x);
+}
 
-  double xinc = (m_xmax - m_xmin) / (m_nPoints - 1);
 
+void
+SignalFilter::createSpatialFilter (double* adFilter) const
+{
   if (m_idFilter == FILTER_SHEPP) {
-    double a = 2 * m_bw;
+    double a = 2 * m_dBandwidth;
     double c = - 4. / (a * a);
-    int center = (m_nPoints - 1) / 2;
+    int center = (m_nFilterPoints - 1) / 2;
     int sidelen = center;
-    m_vecFilter[center] = 4. / (a * a);
+    m_adFilter[center] = 4. / (a * a);
 
     for (int i = 1; i <= sidelen; i++ )
-      m_vecFilter [center + i] = m_vecFilter [center - i] = c / (4 * (i * i) - 1);
-  } else if (m_idDomain == DOMAIN_FREQ) {
-    double x;
-    int i;
-    for (x = m_xmin, i = 0; i < m_nPoints; x += xinc, i++)
-      m_vecFilter[i] = frequencyResponse (x, param);
-  } else if (m_idDomain == DOMAIN_SPATIAL) {
-    double x;
-    int i;
-    for (x = m_xmin, i = 0; i < m_nPoints; x += xinc, i++)
-      if (numint == 0)
-       m_vecFilter[i] = spatialResponseAnalytic (x, param);
-      else
-       m_vecFilter[i] = spatialResponseCalc (x, param, numint);
+      m_adFilter [center + i] = m_adFilter [center - i] = c / (4 * (i * i) - 1);
   } else {
-      m_failMessage = "Illegal domain name ";
-      m_failMessage += m_idDomain;
-      m_fail = true;
+    double x = m_dFilterMin;
+    for (int i = 0; i < m_nFilterPoints; i++, x += m_dFilterInc) {
+      if (haveAnalyticSpatial(m_idFilter))
+        m_adFilter[i] = spatialResponseAnalytic (x);
+      else
+        m_adFilter[i] = spatialResponseCalc (x);
+    }
   }
 }
 
-SignalFilter::~SignalFilter (void)
+int
+SignalFilter::convertFilterNameToID (const char *filterName)
 {
-    delete m_vecFilter;
-}
+  int filterID = FILTER_INVALID;
 
+  for (int i = 0; i < s_iFilterCount; i++) {
+    if (strcasecmp (filterName, s_aszFilterName[i]) == 0) {
+      filterID = i;
+      break;
+    }
+  }
 
-SignalFilter::FilterID
-SignalFilter::convertFilterNameToID (const char *filterName)
-{
-  FilterID filterID = FILTER_INVALID;
-
-  if (strcasecmp (filterName, FILTER_BANDLIMIT_STR) == 0)
-    filterID = FILTER_BANDLIMIT;
-  else if (strcasecmp (filterName, FILTER_HAMMING_STR) == 0)
-    filterID = FILTER_G_HAMMING;
-  else if (strcasecmp (filterName, FILTER_SINC_STR) == 0)
-    filterID = FILTER_SINC;
-  else if (strcasecmp (filterName, FILTER_COS_STR) == 0)
-    filterID = FILTER_COSINE;
-  else if (strcasecmp (filterName, FILTER_TRIANGLE_STR) == 0)
-    filterID = FILTER_TRIANGLE;
-  else if (strcasecmp (filterName, FILTER_ABS_BANDLIMIT_STR) == 0)
-    filterID = FILTER_ABS_BANDLIMIT;
-  else if (strcasecmp (filterName, FILTER_ABS_HAMMING_STR) == 0)
-    filterID = FILTER_ABS_G_HAMMING;
-  else if (strcasecmp (filterName, FILTER_ABS_SINC_STR) == 0)
-    filterID = FILTER_ABS_SINC;
-  else if (strcasecmp (filterName, FILTER_ABS_COS_STR) == 0)
-    filterID = FILTER_ABS_COSINE;
-  else if (strcasecmp (filterName, FILTER_SHEPP_STR) == 0)
-    filterID = FILTER_SHEPP;
-
-  return (filterID);
+    return (filterID);
 }
 
 const char *
-SignalFilter::convertFilterIDToName (const FilterID filterID)
+SignalFilter::convertFilterIDToName (const int filterID)
 {
-  const char *name = "";
-
-  if (filterID == FILTER_SHEPP)
-    name = FILTER_SHEPP_STR;
-  else if (filterID == FILTER_ABS_COSINE)
-    name = FILTER_ABS_COS_STR;
-  else if (filterID == FILTER_ABS_SINC)
-    name = FILTER_ABS_SINC_STR;
-  else if (filterID == FILTER_ABS_G_HAMMING)
-    name = FILTER_ABS_HAMMING_STR;
-  else if (filterID == FILTER_ABS_BANDLIMIT)
-    name = FILTER_ABS_BANDLIMIT_STR;
-  else if (filterID == FILTER_COSINE)
-    name = FILTER_COS_STR;
-  else if (filterID == FILTER_SINC)
-    name = FILTER_SINC_STR;
-  else if (filterID == FILTER_G_HAMMING)
-    name = FILTER_HAMMING_STR;
-  else if (filterID == FILTER_BANDLIMIT)
-    name = FILTER_BANDLIMIT_STR;
-  else if (filterID == FILTER_TRIANGLE)
-    name = FILTER_TRIANGLE_STR;
-           
+  static const char *name = "";
+
+  if (filterID >= 0 && filterID < s_iFilterCount)
+    return (s_aszFilterName [filterID]);
+
   return (name);
 }
-      
-const SignalFilter::DomainID
-SignalFilter::convertDomainNameToID (const char* const domainName)
+
+const char *
+SignalFilter::convertFilterIDToTitle (const int filterID)
 {
-  DomainID dID = DOMAIN_INVALID;
+  static const char *title = "";
 
-  if (strcasecmp (domainName, DOMAIN_SPATIAL_STR) == 0)
-    dID = DOMAIN_SPATIAL;
-  else if (strcasecmp (domainName, DOMAIN_FREQ_STR) == 0)
-    dID = DOMAIN_FREQ;
+  if (filterID >= 0 && filterID < s_iFilterCount) {
+    return (s_aszFilterTitle [filterID]);
+  }
+  return (title);
+}
 
+int
+SignalFilter::convertDomainNameToID (const char* const domainName)
+{
+  int dID = DOMAIN_INVALID;
+
+  for (int i = 0; i < s_iDomainCount; i++) {
+    if (strcasecmp (domainName, s_aszDomainName[i]) == 0) {
+      dID = i;
+      break;
+    }
+  }
   return (dID);
 }
 
 const char *
-SignalFilter::convertDomainIDToName (const DomainID domain)
+SignalFilter::convertDomainIDToName (const int domainID)
 {
-  const char *name = "";
+  static const char *name = "";
 
-  if (domain == DOMAIN_SPATIAL)
-    return (DOMAIN_SPATIAL_STR);
-  else if (domain == DOMAIN_FREQ)
-    return (DOMAIN_FREQ_STR);
+  if (domainID >= 0 && domainID < s_iDomainCount)
+    return (s_aszDomainName [domainID]);
 
   return (name);
 }
 
+const char *
+SignalFilter::convertDomainIDToTitle (const int domainID)
+{
+  static const char *title = "";
+
+  if (domainID >= 0 && domainID < s_iDomainCount)
+    return (s_aszDomainTitle [domainID]);
+
+  return (title);
+}
+
 
 double
 SignalFilter::response (double x)
@@ -240,46 +308,56 @@ SignalFilter::response (double x)
   double response = 0;
 
   if (m_idDomain == DOMAIN_SPATIAL)
-    response = spatialResponse (m_idFilter, m_bw, x, m_filterParam, m_numIntegral);
-  else if (m_idDomain == DOMAIN_FREQ)
-    response = frequencyResponse (m_idFilter, m_bw, x, m_filterParam);
+    response = spatialResponse (m_idFilter, m_dBandwidth, x, m_dFilterParam);
+  else if (m_idDomain == DOMAIN_FREQUENCY)
+    response = frequencyResponse (m_idFilter, m_dBandwidth, x, m_dFilterParam);
 
   return (response);
 }
 
 
-double 
-SignalFilter::spatialResponse (FilterID filterID, double bw, double x, double param, int nIntegral = 0)
+double
+SignalFilter::spatialResponse (int filterID, double bw, double x, double param)
 {
-  if (nIntegral == 0)
+  if (haveAnalyticSpatial(filterID))
     return spatialResponseAnalytic (filterID, bw, x, param);
   else
-    return spatialResponseCalc (filterID, bw, x, param, nIntegral);
+    return spatialResponseCalc (filterID, bw, x, param, N_INTEGRAL);
+}
+
+void
+SignalFilter::copyFilterData (double* pdFilter, const int iStart, const int nPoints) const
+{
+  int iFirst = clamp (iStart, 0, m_nFilterPoints - 1);
+  int iLast = clamp (iFirst + nPoints - 1, 0, m_nFilterPoints - 1);
+
+  for (int i = iFirst; i <= iLast; i++)
+    pdFilter[i - iFirst] = m_adFilter[i];
 }
 
 /* NAME
- *   filter_spatial_response_calc      Calculate filter by discrete inverse fourier
- *                                     transform of filters's frequency
- *                                     response
- *
- * SYNOPSIS
- *   y = filter_spatial_response_calc (filt_type, x, m_bw, param, n)
- *   double y                  Filter's response in spatial domain
- *   int filt_type             Type of filter (definitions in ct.h)
- *   double x                  Spatial position to evaluate filter
- *   double m_bw                       Bandwidth of window
- *   double param              General parameter for various filters
- *   int n                     Number of points to calculate integrations
- */
-
-double 
-SignalFilter::spatialResponseCalc (double x, double param, int nIntegral) const
+*   filter_spatial_response_calc        Calculate filter by discrete inverse fourier
+*                                       transform of filters's frequency
+*                                       response
+*
+* SYNOPSIS
+*   y = filter_spatial_response_calc (filt_type, x, m_bw, param, n)
+*   double y                    Filter's response in spatial domain
+*   int filt_type               Type of filter (definitions in ct.h)
+*   double x                    Spatial position to evaluate filter
+*   double m_bw                 Bandwidth of window
+*   double param                General parameter for various filters
+*   int n                       Number of points to calculate integrations
+*/
+
+double
+SignalFilter::spatialResponseCalc (double x) const
 {
-  return (spatialResponseCalc (m_idFilter, m_bw, x, param, nIntegral));
+  return (spatialResponseCalc (m_idFilter, m_dBandwidth, x, m_dFilterParam, N_INTEGRAL));
 }
 
-double 
-SignalFilter::spatialResponseCalc (FilterID filterID, double bw, double x, double param, int n)
+double
+SignalFilter::spatialResponseCalc (int filterID, double bw, double x, double param, int n)
 {
   double zmin, zmax;
 
@@ -293,122 +371,160 @@ SignalFilter::spatialResponseCalc (FilterID filterID, double bw, double x, doubl
   double zinc = (zmax - zmin) / (n - 1);
 
   double z = zmin;
-  double q [n];
+  double* q = new double [n];
   for (int i = 0; i < n; i++, z += zinc)
     q[i] = frequencyResponse (filterID, bw, z, param) * cos (TWOPI * z * x);
-  
+
   double y = 2 * integrateSimpson (zmin, zmax, q, n);
-  
+  delete q;
+
   return (y);
 }
 
 
 /* NAME
- *    filter_frequency_response                        Return filter frequency response
- *
- * SYNOPSIS
- *    h = filter_frequency_response (filt_type, u, m_bw, param)
- *    double h                 Filters frequency response at u
- *    int filt_type            Type of filter
- *    double u                 Frequency to evaluate filter at
- *    double m_bw                      Bandwidth of filter
- *    double param             General input parameter for various filters
- */
-
-double 
-SignalFilter::frequencyResponse (double u, double param) const
+*    filter_frequency_response                  Return filter frequency response
+*
+* SYNOPSIS
+*    h = filter_frequency_response (filt_type, u, m_bw, param)
+*    double h                   Filters frequency response at u
+*    int filt_type              Type of filter
+*    double u                   Frequency to evaluate filter at
+*    double m_bw                        Bandwidth of filter
+*    double param               General input parameter for various filters
+*/
+
+double
+SignalFilter::frequencyResponse (double u) const
 {
-  return frequencyResponse (m_idFilter, m_bw, u, param);
+  return frequencyResponse (m_idFilter, m_dBandwidth, u, m_dFilterParam);
 }
 
 
-double 
-SignalFilter::frequencyResponse (FilterID filterID, double bw, double u, double param)
+double
+SignalFilter::frequencyResponse (int filterID, double bw, double u, double param)
 {
   double q;
   double au = fabs (u);
+  double abw = fabs (bw);
 
   switch (filterID) {
   case FILTER_BANDLIMIT:
-    if (au >= bw / 2)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0.;
     else
       q = 1;
     break;
   case FILTER_ABS_BANDLIMIT:
-    if (au >= bw / 2)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0.;
     else
       q = au;
     break;
   case FILTER_TRIANGLE:
-    if (au >= bw)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0;
     else
-      q = 1 - au / bw;
+      q = 1 - au / abw;
     break;
   case FILTER_COSINE:
-    if (au >= bw / 2)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0;
     else
-      q = cos(PI * u / bw);
+      q = cos(PI * au / abw);
     break;
   case FILTER_ABS_COSINE:
-    if (au >= bw / 2)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0;
     else
-      q = au * cos(PI * u / bw);
+      q = au * cos(PI * au / abw);
     break;
   case FILTER_SINC:
-    q = bw * sinc (PI * bw * u, 1.);
+    q = abw * sinc (PI * abw * au, 1.);
     break;
   case FILTER_ABS_SINC:
-    q = au * bw * sinc (PI * bw * u, 1.);
+    if (au >= (abw / 2) + F_EPSILON)
+      q = 0;
+    else
+      q = au * abw * sinc (PI * abw * au, 1.);
     break;
+  case FILTER_HANNING:
+    param = 0.5;
+    // follow through to G_HAMMING
   case FILTER_G_HAMMING:
-    if (au >= bw / 2)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0;
     else
-      q = param + (1 - param) * cos (TWOPI * u / bw);
+      q = param + (1 - param) * cos (TWOPI * au / abw);
     break;
+  case FILTER_ABS_HANNING:
+    param = 0.5;
+    // follow through to ABS_G_HAMMING
   case FILTER_ABS_G_HAMMING:
-    if (au >= bw / 2)
+    if (au >= (abw / 2) + F_EPSILON)
       q = 0;
     else
-      q = au * (param + (1 - param) * cos(TWOPI * u / bw));
+      q = au * (param + (1 - param) * cos(TWOPI * au / abw));
     break;
   default:
     q = 0;
     sys_error (ERR_WARNING, "Frequency response for filter %d not implemented [filter_frequency_response]", filterID);
     break;
   }
+
   return (q);
 }
 
 
 
 /* NAME
- *   filter_spatial_response_analytic                  Calculate filter by analytic inverse fourier
- *                             transform of filters's frequency
- *                             response
- *
- * SYNOPSIS
- *   y = filter_spatial_response_analytic (filt_type, x, m_bw, param)
- *   double y                  Filter's response in spatial domain
- *   int filt_type             Type of filter (definitions in ct.h)
- *   double x                  Spatial position to evaluate filter
- *   double m_bw                       Bandwidth of window
- *   double param              General parameter for various filters
- */
-
-double 
-SignalFilter::spatialResponseAnalytic (double x, double param) const
+*   filter_spatial_response_analytic                    Calculate filter by analytic inverse fourier
+*                               transform of filters's frequency
+*                               response
+*
+* SYNOPSIS
+*   y = filter_spatial_response_analytic (filt_type, x, m_bw, param)
+*   double y                    Filter's response in spatial domain
+*   int filt_type               Type of filter (definitions in ct.h)
+*   double x                    Spatial position to evaluate filter
+*   double m_bw                 Bandwidth of window
+*   double param                General parameter for various filters
+*/
+
+double
+SignalFilter::spatialResponseAnalytic (double x) const
 {
-  return spatialResponseAnalytic (m_idFilter, m_bw, x, param);
+  return spatialResponseAnalytic (m_idFilter, m_dBandwidth, x, m_dFilterParam);
 }
 
-double 
-SignalFilter::spatialResponseAnalytic (FilterID filterID, double bw, double x, double param)
+const bool
+SignalFilter::haveAnalyticSpatial (int filterID)
+{
+  bool haveAnalytic = false;
+
+  switch (filterID) {
+  case FILTER_BANDLIMIT:
+  case FILTER_TRIANGLE:
+  case FILTER_COSINE:
+  case FILTER_G_HAMMING:
+  case FILTER_HANNING:
+  case FILTER_ABS_BANDLIMIT:
+  case FILTER_ABS_COSINE:
+  case FILTER_ABS_G_HAMMING:
+  case FILTER_ABS_HANNING:
+  case FILTER_SHEPP:
+  case FILTER_SINC:
+    haveAnalytic = true;
+    break;
+  default:
+    break;
+  }
+
+  return (haveAnalytic);
+}
+
+double
+SignalFilter::spatialResponseAnalytic (int filterID, double bw, double x, double param)
 {
   double q, temp;
   double u = TWOPI * x;
@@ -427,6 +543,9 @@ SignalFilter::spatialResponseAnalytic (FilterID filterID, double bw, double x, d
   case FILTER_COSINE:
     q = sinc(b-u,w) + sinc(b+u,w);
     break;
+  case FILTER_HANNING:
+    param = 0.5;
+    // follow through to G_HAMMING
   case FILTER_G_HAMMING:
     q = 2 * param * sin(u*w)/u + (1-param) * (sinc(b2-u, w) + sinc(b2+u, w));
     break;
@@ -436,6 +555,9 @@ SignalFilter::spatialResponseAnalytic (FilterID filterID, double bw, double x, d
   case FILTER_ABS_COSINE:
     q = integral_abscos(b-u,w) + integral_abscos(b+u,w);
     break;
+  case FILTER_ABS_HANNING:
+    param = 0.5;
+    // follow through to ABS_G_HAMMING
   case FILTER_ABS_G_HAMMING:
     q = 2 * param * integral_abscos(u,w) +
       (1-param)*(integral_abscos(u-b2,w)+integral_abscos(u+b2,w));
@@ -458,105 +580,26 @@ SignalFilter::spatialResponseAnalytic (FilterID filterID, double bw, double x, d
     q = 0;
     break;
   }
-  
+
   return (q);
 }
 
 
-/* NAME
- *   sinc                      Return sin(x)/x function
- *
- * SYNOPSIS
- *   v = sinc (x, mult)
- *   double v                  sinc value
- *   double x, mult
- *
- * DESCRIPTION
- *   v = sin(x * mult) / x;
- */
 
+// Functions that are inline in filter.h
 
-/* NAME
- *   integral_abscos                   Returns integral of u*cos(u)
- *
- * SYNOPSIS
- *   q = integral_abscos (u, w)
- *   double q                  Integral value
- *   double u                  Integration variable
- *   double w                  Upper integration boundary
- *
- * DESCRIPTION
- *   Returns the value of integral of u*cos(u)*dV for V = 0 to w
- */
-
-double 
-SignalFilter::integral_abscos (double u, double w)
-{
-  if (fabs (u) > F_EPSILON)
-    return (cos(u * w) - 1) / (u * u) + w / u * sin (u * w);
-  else
-    return (w * w / 2);
-}
 
+//  sinc                        Return sin(x)/x function
+//   v = sinc (x, mult)
+// Calculates sin(x * mult) / x;
 
-/* NAME
- *    convolve                 Discrete convolution of two functions
- *
- * SYNOPSIS
- *    r = convolve (f1, f2, dx, n, np, func_type)
- *    double r                 Convolved result
- *    double f1[], f2[]                Functions to be convolved
- *    double dx                        Difference between successive x values
- *    int n                    Array index to center convolution about
- *    int np                   Number of points in f1 array
- *    int func_type            EVEN or ODD or EVEN_AND_ODD function f2
- *
- * NOTES
- *    f1 is the projection data, its indices range from 0 to np - 1.
- *    The index for f2, the filter, ranges from -(np-1) to (np-1).
- *    There are 3 ways to handle the negative vertices of f2:
- *     1. If we know f2 is an EVEN function, then f2[-n] = f2[n].
- *        All filters used in reconstruction are even.
- *      2. If we know f2 is an ODD function, then f2[-n] = -f2[n] 
- *      3. If f2 is both ODD AND EVEN, then we must store the value of f2
- *        for negative indices.  Since f2 must range from -(np-1) to (np-1),
- *        if we add (np - 1) to f2's array index, then f2's index will
- *        range from 0 to 2 * (np - 1), and the origin, x = 0, will be
- *        stored at f2[np-1].
- */
-
-double 
-SignalFilter::convolve (const double func[], const double dx, const int n, const int np) const
-{
-  double sum = 0.0;
-
-#if UNOPTIMIZED_CONVOLUTION
-  for (int i = 0; i < np; i++)
-    sum += func[i] * m_vecFilter[n - i + (np - 1)];
-#else
-  double* f2 = m_vecFilter + n + (np - 1);
-  for (int i = 0; i < np; i++)
-    sum += *func++ * *f2--;
-#endif
-
-  return (sum * dx);
-}
+//  integral_abscos     Returns integral of u*cos(u)
+//
+//   q = integral_abscos (u, w)
+//   double q                   Integral value
+//   double u                   Integration variable
+//   double w                   Upper integration boundary
+// Returns the value of integral of u*cos(u)*dV for V = 0 to w
 
 
-double 
-SignalFilter::convolve (const float func[], const double dx, const int n, const int np) const
-{
-  double sum = 0.0;
-
-#if UNOPTIMIZED_CONVOLUTION
-for (int i = 0; i < np; i++)
-  sum += func[i] * m_vecFilter[n - i + (np - 1)];
-#else
-double* f2 = m_vecFilter + n + (np - 1);
-for (int i = 0; i < np; i++)
-  sum += *func++ * *f2--;
-#endif
-
-  return (sum * dx);
-}