Open Ephys GUI
 All Classes Functions Variables
Types.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_TYPES_H
37 #define DSPFILTERS_TYPES_H
38 
39 #include "Common.h"
40 #include "MathSupplement.h"
41 
42 namespace Dsp {
43 
44 // A conjugate or real pair
45 struct ComplexPair : complex_pair_t
46 {
47  ComplexPair ()
48  {
49  }
50 
51  explicit ComplexPair (const complex_t& c1)
52  : complex_pair_t (c1, 0.)
53  {
54  assert (isReal());
55  }
56 
57  ComplexPair (const complex_t& c1,
58  const complex_t& c2)
59  : complex_pair_t (c1, c2)
60  {
61  }
62 
63  bool isConjugate () const
64  {
65  return second == std::conj (first);
66  }
67 
68  bool isReal () const
69  {
70  return first.imag() == 0 && second.imag() == 0;
71  }
72 
73  // Returns true if this is either a conjugate pair,
74  // or a pair of reals where neither is zero.
75  bool isMatchedPair () const
76  {
77  if (first.imag() != 0)
78  return second == std::conj (first);
79  else
80  return second.imag () == 0 &&
81  second.real () != 0 &&
82  first.real () != 0;
83  }
84 
85  bool is_nan () const
86  {
87  return Dsp::is_nan (first) || Dsp::is_nan (second);
88  }
89 };
90 
91 // A pair of pole/zeros. This fits in a biquad (but is missing the gain)
93 {
94  ComplexPair poles;
95  ComplexPair zeros;
96 
97  PoleZeroPair () { }
98 
99  // single pole/zero
100  PoleZeroPair (const complex_t& p, const complex_t& z)
101  : poles (p), zeros (z)
102  {
103  }
104 
105  // pole/zero pair
106  PoleZeroPair (const complex_t& p1, const complex_t& z1,
107  const complex_t& p2, const complex_t& z2)
108  : poles (p1, p2)
109  , zeros (z1, z2)
110  {
111  }
112 
113  bool isSinglePole () const
114  {
115  return poles.second == 0. && zeros.second == 0.;
116  }
117 
118  bool is_nan () const
119  {
120  return poles.is_nan() || zeros.is_nan();
121  }
122 };
123 
124 // Identifies the general class of filter
125 enum Kind
126 {
127  kindLowPass,
128  kindHighPass,
129  kindBandPass,
130  kindBandStop,
131  kindLowShelf,
132  kindHighShelf,
133  kindBandShelf,
134  kindOther
135 };
136 
137 }
138 
139 #endif