gtsam 4.1.1 gtsam
Fourier.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
9
10 * -------------------------------------------------------------------------- */
11
20#pragma once
21
22#include <gtsam/basis/Basis.h>
23
24namespace gtsam {
25
27class GTSAM_EXPORT 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 = 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
Compute an interpolating basis.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
CRTP Base class for function bases.
Definition: Basis.h:95
Fourier basis.
Definition: Fourier.h:27
static DiffMatrix DifferentiationMatrix(size_t N)
Compute D = differentiation matrix.
Definition: Fourier.h:73
static Weights DerivativeWeights(size_t N, double x)
Get weights at a given x that calculate the derivative.
Definition: Fourier.h:92
static Weights CalculateWeights(size_t N, double x)
Evaluate Real Fourier Weights of size N in interval [a, b], e.g.
Definition: Fourier.h:40
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
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.
Definition: Fourier.h:64