MathTL
numerics/goertzel_reinsch.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_GOERTZEL_REINSCH_H
00011 #define _MATHTL_GOERTZEL_REINSCH_H
00012 
00013 #include <cmath>
00014 #include <algebra/vector.h>
00015 #include <geometry/point.h>
00016 #include <utils/function.h>
00017 
00018 namespace MathTL
00019 {
00020   // point evaluation of sine (and cosine) series according to Goertsch
00021   // (adjoint summmation for p_{2k}=cos(k.), p_{2k+1}=sin(k.))
00022   //
00023   // Note that this is potentially unstable for x\in l\mathbb Z!
00024   template <class C>
00025   class Goertzel : public Function<1,C>
00026   {
00027   public:
00028     Goertzel(const Vector<C>& coeffs, const bool sine = true)
00029       : coeffs_(coeffs), sine_(sine)
00030     {
00031     }
00032     
00033     C value(const Point<1,C>&p, const unsigned int component = 0) const;
00034     
00035     void vector_value(const Point<1,C> &p, Vector<C>& values) const {
00036       values.resize(1, false);
00037       values[0] = value(p);
00038     }
00039 
00040   protected:
00041     Vector<C> coeffs_;
00042     bool sine_;
00043   };
00044 
00045   // stable point evaluation of sine (or cosine) series
00046   //
00047   // references:
00048   // * Stoer, Numerische Mathematik 1
00049   // * Deuflhard/Bornemann, Numerische Mathematik 1
00050 
00051   template <class C>
00052   class GoertzelReinsch : public Function<1,C>
00053   {
00054   public:
00055     GoertzelReinsch(const Vector<C>& coeffs, const bool sine = true)
00056       : coeffs_(coeffs), sine_(sine)
00057     {
00058     }
00059     
00060     C value(const Point<1,C>&p, const unsigned int component = 0) const;
00061     
00062     void vector_value(const Point<1,C> &p, Vector<C>& values) const {
00063       values.resize(1, false);
00064       values[0] = value(p);
00065     }
00066 
00067     void set_coefficients(const Vector<C>& coeffs)
00068     {
00069       coeffs_ = coeffs;
00070     }
00071 
00072   protected:
00073     Vector<C> coeffs_;
00074     bool sine_;
00075   };
00076 }
00077 
00078 // include implementation of inline functions
00079 #include <numerics/goertzel_reinsch.cpp>
00080 
00081 #endif
 All Classes Functions Variables Typedefs Enumerations