Open Ephys GUI
 All Classes Functions Variables
Custom.h
1 /*******************************************************************************
2 
3 "A Collection of Useful C++ Classes for Digital Signal Processing"
4  By Vincent Falco
5 
6 Official project location:
7 http://code.google.com/p/dspfilterscpp/
8 
9 See Documentation.cpp for contact information, notes, and bibliography.
10 
11 --------------------------------------------------------------------------------
12 
13 License: MIT License (http://www.opensource.org/licenses/mit-license.php)
14 Copyright (c) 2009 by Vincent Falco
15 
16 Permission is hereby granted, free of charge, to any person obtaining a copy
17 of this software and associated documentation files (the "Software"), to deal
18 in the Software without restriction, including without limitation the rights
19 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 copies of the Software, and to permit persons to whom the Software is
21 furnished to do so, subject to the following conditions:
22 
23 The above copyright notice and this permission notice shall be included in
24 all copies or substantial portions of the Software.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 THE SOFTWARE.
33 
34 *******************************************************************************/
35 
36 #ifndef DSPFILTERS_CUSTOM_H
37 #define DSPFILTERS_CUSTOM_H
38 
39 #include "Common.h"
40 #include "Biquad.h"
41 #include "Design.h"
42 #include "Filter.h"
43 
44 namespace Dsp {
45 
46 /*
47  * Single pole and Biquad with parameters allowing
48  * for directly setting the poles and zeros
49  *
50  */
51 
52 namespace Custom {
53 
54 //
55 // Raw filters
56 //
57 
58 struct OnePole : Biquad
59 {
60  void setup (double scale,
61  double pole,
62  double zero);
63 };
64 
65 struct TwoPole : Biquad
66 {
67  void setup (double scale,
68  double poleRho,
69  double poleTheta,
70  double zeroRho,
71  double zeroTheta);
72 };
73 
74 //------------------------------------------------------------------------------
75 
76 //
77 // Gui-friendly Design layer
78 //
79 
80 namespace Design {
81 
83 {
84  enum
85  {
86  NumParams = 4
87  };
88 
89  static int getNumParams ()
90  {
91  return 4;
92  }
93 
94  static const ParamInfo getParamInfo_1 ()
95  {
96  return ParamInfo::defaultGainParam ();
97  }
98 
99  static const ParamInfo getParamInfo_2 ()
100  {
101  return ParamInfo::defaultPoleRealParam ();
102  }
103 
104  static const ParamInfo getParamInfo_3 ()
105  {
106  return ParamInfo::defaultZeroRealParam ();
107  }
108 
109  static Kind getKind () { return kindOther; }
110  static const char* getName() { return "Custom One-Pole"; }
111 
112  void setParams (const Params& params)
113  {
114  setup (pow (10., params[1]/20),
115  params[2],
116  params[3]);
117  }
118 };
119 
121 {
122  enum
123  {
124  NumParams = 6
125  };
126 
127  static int getNumParams ()
128  {
129  return 6;
130  }
131 
132  static const ParamInfo getParamInfo_1 ()
133  {
134  return ParamInfo::defaultGainParam ();
135  }
136 
137  static const ParamInfo getParamInfo_2 ()
138  {
139  return ParamInfo::defaultPoleRhoParam ();
140  }
141 
142  static const ParamInfo getParamInfo_3 ()
143  {
144  return ParamInfo::defaultPoleThetaParam ();
145  }
146 
147  static const ParamInfo getParamInfo_4 ()
148  {
149  return ParamInfo::defaultZeroRhoParam ();
150  }
151 
152  static const ParamInfo getParamInfo_5 ()
153  {
154  return ParamInfo::defaultZeroThetaParam ();
155  }
156 
157 
158  static Kind getKind () { return kindOther; }
159  static const char* getName() { return "Custom Two-Pole"; }
160 
161  void setParams (const Params& params)
162  {
163  setup (pow (10., params[1]/20),
164  params[2],
165  params[3],
166  params[4],
167  params[5]);
168  }
169 };
170 
171 }
172 
173 }
174 
175 }
176 
177 #endif