gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
IIRCascade.C
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 #include "DSP/IIRCascade.H"
18 
20 {
21  //ctor
22 }
23 
25 {
26  //dtor
27 }
28 
29 int IIRCascade::process(const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> &x, Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> const &y){
31 }
32 
34  for (int j=0; j<A.cols(); j++){
35  for (int i=0; i<xTemp.rows(); i++){
36  mem(0,j)=-xTemp(i,0);
37  mem(0,j)=-(A.col(j)*mem.col(j).topRows(A.rows())).sum();
38  yTemp(i,0)=(B.col(j)*mem.col(j).topRows(B.rows())).sum();
39  for (int k=mem.rows()-1; k>0; k--)
40  mem(k,j)=mem(k-1,j);
41  }
42  xTemp=yTemp;
43  }
44 }
45 
46 int IIRCascade::process(const Eigen::Matrix<double, Eigen::Dynamic, 1> &x, Eigen::Matrix<double, Eigen::Dynamic, 1> const &y){
47  if (x.rows()!=y.rows()){
48  printf("Input sample count %lld not equal to output sample count %lld", (long long)x.rows(), (long long)y.rows());
50  }
51 
52  if (x.rows() != yTemp.rows())
53  yTemp.resize(x.rows(), 1);
54  if (x.rows() != xTemp.rows())
55  xTemp.resize(x.rows(), 1);
56  xTemp=x;
57 
58  process();
59 
60  const_cast< Eigen::Matrix<double, Eigen::Dynamic, 1>& >(y)=xTemp;
61  return 0;
62 }
63 
64 int IIRCascade::process(const Eigen::Matrix<float, Eigen::Dynamic, 1> &x, Eigen::Matrix<float, Eigen::Dynamic, 1> const &y){
65  if (x.rows()!=y.rows()){
66  printf("Input sample count %lld not equal to output sample count %lld", (long long)x.rows(), (long long)y.rows());
68  }
69 
70  if (x.rows() != xTemp.rows())
71  xTemp.resize(x.rows(), 1);
72  if (x.rows() != yTemp.rows())
73  yTemp.resize(x.rows(), 1);
74  xTemp=x.cast<double>();
75  process();
76 
77  const_cast< Eigen::Matrix<float, Eigen::Dynamic, 1>& >(y)=xTemp.cast<float>();
78  return 0;
79 }
80 
81 int IIRCascade::processStepped(const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &BStep, const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &AStep){
82  if ((BStep.cols()!=B.cols()) || (AStep.cols()!=A.cols()) || (B.cols()!=A.cols())){
83  printf("BStep or AStep channel count (%lld, %lld) mismatch to filter channel count %lld", (long long)BStep.cols(), (long long)AStep.cols(), (long long)A.cols());
85  }
86 
87  if ((BStep.rows()!=B.rows()) || (AStep.rows()!=A.rows())){
88  printf("BStep order %lld not equal to B order %lld", (long long)BStep.rows(), (long long)B.rows());
89  printf("OR AStep order %lld not equal to A order %lld", (long long)AStep.rows(), (long long)A.rows());
91  }
92 
93  for (int j=0; j<A.cols(); j++){
94  for (int i=0; i<xTemp.rows(); i++){
95  mem(0,j)=-xTemp(i,0);
96  mem(0,j)=-(A.col(j)*mem.col(j).topRows(A.rows())).sum();
97  yTemp(i,0)=(B.col(j)*mem.col(j).topRows(B.rows())).sum();
98  for (int k=mem.rows()-1; k>0; k--)
99  mem(k,j)=mem(k-1,j);
100  B.col(j)+=BStep.col(j); // step the filter coefficients on
101  A.col(j)+=AStep.col(j);
102  }
103  xTemp=yTemp;
104  }
105  return 0;
106 }
107 
108 int IIRCascade::process(const Eigen::Matrix<double, Eigen::Dynamic, 1> &x, Eigen::Matrix<double, Eigen::Dynamic, 1> const &y,
109  const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &BStep, const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &AStep){
110  if (x.rows()!=y.rows()){
111  printf("Input sample count %lld not equal to output sample count %lld", (long long)x.rows(), (long long)y.rows());
113  }
114 
115  if (x.rows() != yTemp.rows())
116  yTemp.resize(x.rows(), 1);
117  if (x.rows() != xTemp.rows())
118  xTemp.resize(x.rows(), 1);
119  xTemp=x;
120 
121  processStepped(BStep, AStep);
122 
123  const_cast< Eigen::Matrix<double, Eigen::Dynamic, 1>& >(y)=xTemp;
124  return 0;
125 }
126 
127 int IIRCascade::process(const Eigen::Matrix<float, Eigen::Dynamic, 1> &x, Eigen::Matrix<float, Eigen::Dynamic, 1> const &y,
128  const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &BStep, const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic> &AStep){
129  if (x.rows()!=y.rows()){
130  printf("Input sample count %lld not equal to output sample count %lld", (long long)x.rows(), (long long)y.rows());
132  }
133 
134  if (x.rows() != yTemp.rows())
135  yTemp.resize(x.rows(), 1);
136  if (x.rows() != xTemp.rows())
137  xTemp.resize(x.rows(), 1);
138  xTemp=x.cast<double>();
139 
140  processStepped(BStep, AStep);
141 
142  const_cast< Eigen::Matrix<float, Eigen::Dynamic, 1>& >(y)=xTemp.cast<float>();
143  return 0;
144 }
float * x
void process()
Inner process.
Definition: IIRCascade.C:33
virtual ~IIRCascade()
Definition: IIRCascade.C:24
#define IIR_REQUIRE_COL_ERROR
Channel count mismatch error.
Definition: IIR.H:26
virtual int evaluateError(int errorNum)
Definition: Debug.H:132
int processStepped(const Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > &BStep, const Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > &AStep)
Definition: IIRCascade.C:81
Definition: IIR.H:29
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > A
Definition: IIR.H:52
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > B
Definition: IIR.H:51
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
Eigen::Matrix< double, Eigen::Dynamic, 1 > xTemp
Temporary casecading signal.
Definition: IIRCascade.H:27
#define IIR_N_CNT_ERROR
Channel count mismatch error.
Definition: IIR.H:25
gtkIOStream: /tmp/gtkiostream/src/DSP/IIRCascade.C Source File
GTK+ IOStream  Beta