gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
IIR.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16 */
17 
18 #ifndef IIR_H
19 #define IIR_H
20 
21 // Debug
22 #include "Debug.H"
23 #define IIR_A0_ERROR IIR_ERROR_OFFSET-1
24 #define IIR_CH_CNT_ERROR IIR_ERROR_OFFSET-2
25 #define IIR_N_CNT_ERROR IIR_ERROR_OFFSET-3
26 #define IIR_REQUIRE_COL_ERROR IIR_ERROR_OFFSET-4
27 #define IIR_REQUIRE_MATRIX_ERROR IIR_ERROR_OFFSET-5
28 
29 class IIRDebug : virtual public Debug {
30 public:
32 #ifndef NDEBUG
33  errors[IIR_A0_ERROR]=std::string("IIR feedback coefficient a0 != 1. ");
34  errors[IIR_CH_CNT_ERROR]=std::string("The channel counts aren't the same. ");
35  errors[IIR_N_CNT_ERROR]=std::string("The sample counts aren't the same. ");
36  errors[IIR_REQUIRE_COL_ERROR]=std::string("The Matrix must be defined as a single col matrix, not dynamic. ");
37  errors[IIR_REQUIRE_MATRIX_ERROR]=std::string("The Matrix must be defined as a Matrix, not Array. ");
38 
39 #endif // NDEBUG
40  }
41 };
42 
43 #include <Eigen/Dense>
44 #include <strstream>
45 
49 class IIR {
50 protected:
51  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> B; // feed forward
52  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> A; // feed back
53  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> yTemp; // temporary output variables
54  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> mem; // memory
55 
56 public:
57  IIR();
58  virtual ~IIR();
59  int reset(const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &Bin, const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &Ain);
60  // int reset(const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &Bin, const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &Ain, Eigen::Dynamic, Eigen::Dynamic> &memIn);
61  int reset(){
62  mem.setZero();
63  return 0;
64  }
65  int setMem(const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &memIn);
66  int setMem(const IIR &iir);
67  void resetMem(){mem.setZero();}
68 
70  int process(const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> &x, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> const &y);
71  int process(const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> &x, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> const &y,
72  const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &BStep, const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &AStep);
73  int getChannelCount(){return B.cols();}
74 
77  // int IIR::copyTo(IIR iirIn);
78 
79  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> getB(){return B;}
80  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> getA(){return A;}
81  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> getMem(){return mem;}
82 };
83 #endif // IIR_H
int reset()
Definition: IIR.H:61
float * x
#define IIR_REQUIRE_COL_ERROR
Channel count mismatch error.
Definition: IIR.H:26
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > getA()
Definition: IIR.H:80
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > getMem()
Definition: IIR.H:81
Definition: IIR.H:29
std::map< int, std::string > errors
This will contain a map between error numbers and descriptive std::strings for the errors...
Definition: Debug.H:115
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > A
Definition: IIR.H:52
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > getB()
Definition: IIR.H:79
Definition: IIR.H:49
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > B
Definition: IIR.H:51
IIRDebug()
Definition: IIR.H:31
float * y
#define IIR_CH_CNT_ERROR
Channel count mismatch error.
Definition: IIR.H:24
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > yTemp
Definition: IIR.H:53
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > mem
Definition: IIR.H:54
Definition: Debug.H:112
#define IIR_A0_ERROR
Error when feedback coefficient A0 is not = 1.
Definition: IIR.H:23
void resetMem()
Definition: IIR.H:67
#define IIR_REQUIRE_MATRIX_ERROR
Channel count mismatch error.
Definition: IIR.H:27
#define IIR_N_CNT_ERROR
Channel count mismatch error.
Definition: IIR.H:25
int getChannelCount()
Definition: IIR.H:73
gtkIOStream: /tmp/gtkiostream/include/DSP/IIR.H Source File
GTK+ IOStream  Beta