filters.cc 3.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*! \file filter.cc
 * \brief filter types (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 05/01/2003
 * 
 * filter types (implementation)
 * 
 * Copyright (c) 2003 by Thomas Forbriger (IMG Frankfurt) 
 *
 * ----
14
 * libfourier is free software; you can redistribute it and/or modify
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
 *
 * 
 * REVISIONS and CHANGES 
 *  - 05/01/2003   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TF_FILTER_CC_VERSION \
36
  "TF_FILTER_CC   V1.0"
37 38 39

#include <fourier/filters.h>
#include <fourier/error.h>
40
#include <cmath>
41 42 43

namespace fourier {

44
  const double Filter::pi=M_PI;
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  const Filter::Tcvalue Filter::ime=Tcvalue(0.,1.);

  /*----------------------------------------------------------------------*/

  Filter::Tcvalue Filter::omega(const Filter::Tcvalue& par) const 
  {
    Tcvalue retval;
    if (isfreqmod()) { retval=2.*pi*par; } else { retval=2.*pi/par; }
    return(retval);
  }

  /*----------------------------------------------------------------------*/

  void Filter::setint()
  {
     this->Tbase::setpole(Tcvalue(0.,0.));
     this->Tbase::denfactor(Tcvalue(0.,1.));
  }

  /*----------------------------------------------------------------------*/

  void Filter::setdif()
  {
     this->Tbase::setzero(Tcvalue(0.,0.));
     this->Tbase::numfactor(Tcvalue(0.,1.));
  }

  /*----------------------------------------------------------------------*/

  void Filter::sethpb(const Filter::Tcvalue& par, const int& ord) 
  {
    Tcvalue om=omega(par);
    FOURIER_assert((ord>0), "ERROR (Filter hpb): illegal order!");
    for (int i=1; i<=ord; ++i)
    {
      this->Tbase::setzero(Tcvalue(0.,0.));
      Tcvalue pole=om*std::exp(ime*pi*(2.*i-1.)/(2.*ord));
      this->Tbase::setpole(pole);
    }
  }

  /*----------------------------------------------------------------------*/

  void Filter::setlpb(const Filter::Tcvalue& par, const int& ord) 
  {
    Tcvalue om=omega(par);
    FOURIER_assert((ord>0), "ERROR (Filter lpb): illegal order!");
    for (int i=1; i<=ord; ++i)
    {
      this->Tbase::numfactor(-ime*om);
      Tcvalue pole=om*std::exp(ime*pi*(2.*i-1.)/(2.*ord));
      this->Tbase::setpole(pole);
    }
  }

  /*----------------------------------------------------------------------*/

  void Filter::sethp2(const Filter::Tcvalue& par, const double& h) 
  {
    Tcvalue om=omega(par);
    this->Tbase::setzero(Tcvalue(0.,0.));
    this->Tbase::setzero(Tcvalue(0.,0.));
    Tcvalue pole=om*(ime*h+std::sqrt(1.-h*h));
    this->Tbase::setpole(pole);
    pole=om*(ime*h-std::sqrt(1.-h*h));
    this->Tbase::setpole(pole);
  }

  /*----------------------------------------------------------------------*/

  void Filter::setlp2(const Filter::Tcvalue& par, const double& h) 
  {
    Tcvalue om=omega(par);
    this->Tbase::numfactor(-ime*om);
    this->Tbase::numfactor(-ime*om);
    Tcvalue pole=om*(ime*h+std::sqrt(1.-h*h));
    this->Tbase::setpole(pole);
    pole=om*(ime*h-std::sqrt(1.-h*h));
    this->Tbase::setpole(pole);
  }

} // namespace fourier

/* ----- END OF filter.cc ----- */