GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
Fourier.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #pragma once
21 
22 #include <gtsam/basis/Basis.h>
23 
24 namespace gtsam {
25 
27 class FourierBasis : public Basis<FourierBasis> {
28  public:
29  using Parameters = Eigen::Matrix<double, /*Nx1*/ -1, 1>;
30  using DiffMatrix = Eigen::Matrix<double, /*NxN*/ -1, -1>;
31 
40  static Weights CalculateWeights(size_t N, double x) {
41  Weights b(N);
42  b[0] = 1;
43  for (size_t i = 1, n = 1; i < N; i++) {
44  if (i % 2 == 1) {
45  b[i] = cos(n * x);
46  } else {
47  b[i] = sin(n * x);
48  n++;
49  }
50  }
51  return b;
52  }
53 
64  static Weights CalculateWeights(size_t N, double x, double a, double b) {
65  // TODO(Varun) How do we enforce an interval for Fourier series?
66  return CalculateWeights(N, x);
67  }
68 
73  static DiffMatrix DifferentiationMatrix(size_t N) {
74  DiffMatrix D = DiffMatrix::Zero(N, N);
75  double k = 1;
76  for (size_t i = 1; i < N; i += 2) {
77  D(i, i + 1) = k; // sin'(k*x) = k*cos(k*x)
78  D(i + 1, i) = -k; // cos'(k*x) = -k*sin(k*x)
79  k += 1;
80  }
81 
82  return D;
83  }
84 
92  static Weights DerivativeWeights(size_t N, double x) {
93  return CalculateWeights(N, x) * DifferentiationMatrix(N);
94  }
95 
106  static Weights DerivativeWeights(size_t N, double x, double a, double b) {
107  return CalculateWeights(N, x, a, b) * DifferentiationMatrix(N);
108  }
109 
110 }; // FourierBasis
111 
112 } // namespace gtsam
static Weights CalculateWeights(size_t N, double x, double a, double b)
Evaluate Real Fourier Weights of size N in interval [a, b], e.g. N=5 yields bases: 1...
Definition: Fourier.h:64
Definition: Basis.h:100
static DiffMatrix DifferentiationMatrix(size_t N)
Definition: Fourier.h:73
Compute an interpolating basis.
static Weights CalculateWeights(size_t N, double x)
Evaluate Real Fourier Weights of size N in interval [a, b], e.g. N=5 yields bases: 1...
Definition: Fourier.h:40
Definition: chartTesting.h:28
static Weights DerivativeWeights(size_t N, double x, double a, double b)
Get derivative weights at a given x that calculate the derivative, in the interval [a...
Definition: Fourier.h:106
Fourier basis.
Definition: Fourier.h:27
static Weights DerivativeWeights(size_t N, double x)
Get weights at a given x that calculate the derivative.
Definition: Fourier.h:92