casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimButterworthBandpass.h
Go to the documentation of this file.
1 //# SimButterworthBandpass.h: Declares a Butterworth function
2 //# Copyright (C) 2000,2001,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef SCIMATH_SIMBUTTERWORTHBANDPASS_H
29 #define SCIMATH_SIMBUTTERWORTHBANDPASS_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 template<class T> class Vector;
40 
41 // <summary>
42 // a class for evaluating a Butterworth filter transfer function.
43 // </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="wbrouw" date="2001/11/14"
48 // tests="tSimButterworthBandpass" demos="">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class
53 // <li> <linkto class=Function1D>Function1D</linkto>
54 // </prerequisite>
55 //
56 // <etymology>
57 // "Butterworth" refers to the Butterworth function for describing
58 // filter transfer functions (Butterworth, S, "On the theory of filter
59 // amplifiers," Wireless Engineer, vol. 7 pp. 536-541, October 1930).
60 // "Bandpass" reflects that the transfer function is has both low and high
61 // frequency cutoffs.
62 // "Sim" indicates that this implementation is not necessarily appropriate
63 // characterizing real bandpass filters; in the future, there may be a
64 // more general class called simply "Butterworth".
65 // </etymology>
66 //
67 // <synopsis>
68 // This function class simulates the (amplitude) transfer function for a
69 // wideband bandpass filter constructed from the combination of a low-pass
70 // and a high-pass Butterworth filter.
71 //
72 // In analog electronic filter design, a Butterworth low-pass filter is
73 // one in which the amplitude transfer function, |H(jw)| (where j = sqrt(-1)
74 // and w is the angular frequency), is given by:
75 // <srcblock>
76 // |H(jw)| = 1 / sqrt(1 + (w/w_c)^(2*n))
77 // </srcblock>
78 // where n refers to the filter "order" and w_c is the "cutoff frequency".
79 // When w = w_c, the filter output is 1/sqrt(2) that of the input, and the
80 // higher the order, the steeper the drop off towards zero and the closer
81 // the approximation to a idealized step function.
82 //
83 // Filter theory provides transformations for deriving transfer functions
84 // of high-pass and band-pass filters which reflect how the electrical
85 // circuits actually work. However, to simplify this class's implementation
86 // and to make the transfer function behavior more predictable by the naive
87 // user, THIS CLASS DOES NOT ACTUALLY USE THE PROPER TRANSFORMATIONS (see
88 // Etymology section above).
89 // Instead, the Butterworth bandpass transfer function is approximated by
90 // low pass component, given above, combined with a pseudo high-pass function
91 // that is of the same form but with w substituted with -w. Both components
92 // are shifted such that its peak transfer point is at a given "center"
93 // position. The cutoff value and order can be set independently for both
94 // ends of the passband.
95 // </synopsis>
96 //
97 // <example>
98 // <srcblock>
99 // // Create a bandpass function centered on x=0.8 and cutoffs at 0 and 2.5.
100 // // The orders of the drop-offs will 4 at the low end and 5 at the high
101 // // end. The peak will by 1.0 by default.
102 // SimButterworthBandpass<Double> butt(4, 5, 0, 2.5, 0.8);
103 //
104 // Double z = butt(1); // z = 1.0
105 // z = butt(0); // z = 1/sqrt(2)
106 // z = butt(2.5); // z = 1/sqrt(2)
107 // z = butt(-25); // z ~ 9.24e-9 ~ 0
108 //
109 // // change the low-end cutoff to -25.0
110 // butt.setMinCutoff(-25);
111 // z = butt(-25); // z = 1/sqrt(2)
112 // </srcblock>
113 // </example>
114 //
115 // <motivation>
116 // This class was created to simulate systemtic Butterworth bandpasses
117 // within the simulator tool. It can used by the SimBJones class to vary the
118 // bandpass in a predictable way. However, it has limited value for real
119 // filter analysis, and it is not expected to be a realistic representation
120 // of real bandpass filters in use with radio telescopes backends.
121 // </motivation>
122 //
123 // <templating arg=T>
124 // <li> T should have standard numerical operators. Current
125 // implementation only tested for real types (and their AutoDiffs).
126 // </templating>
127 //
128 // <thrown>
129 // <li> Assertion if indices out-of-range
130 // </thrown>
131 //
132 // <todo asof="2001/11/14">
133 // <li> Nothing I know of
134 // </todo>
135 
136 template<class T>
138 {
139 public:
140  //# Enumerations
141  // Enumeration of the function parameters
143 
144  //# Constructors
145  // create a zero-th order (all-pass) Butterworth bandpass function.
147 
148  // create a Butterworth bandpass function.
149  SimButterworthBandpass(const uInt minord, const uInt maxord,
150  const T &mincut=T(-1), const T &maxcut=T(1),
151  const T &center=T(0), const T &peak=T(1));
152 
153  // create a fully specified Butterworth bandpass in which the
154  // low and high pass orders are stored in a Record
155  explicit SimButterworthBandpass(const RecordInterface& gr,
156  T mincut=T(-1), T maxcut=T(1),
157  T center=T(0), T peak=T(1));
158 
159  // create a copy of another Butterworth bandpass function
161 
162  // copy(deep) another Butterworth function
164  operator=(const SimButterworthBandpass<T> &other);
165 
166  // Destructor
167  virtual ~SimButterworthBandpass();
168 
169 
170  //# Operators
171  // Evaluate the bandpass at "x".
172  virtual T eval(const typename FunctionTraits<T>::ArgType *x) const;
173 
174  //# Member functions
175  // set the center of the bandpass. This is the x-ordinate value that
176  // evaluates to the peak of the function.
177  void setCenter(const T &x) { param_p[CENTER] = x; }
178 
179  // return the center of the bandpass. This is the x-ordinate value that
180  // evaluates to the peak of the function.
181  const T &getCenter() const { return param_p[CENTER]; }
182 
183  // set the characteristic minimum (high-pass) cutoff value. At this
184  // x-ordinate value, the function has a value reduced 30 dB from its
185  // peak.
186  void setMinCutoff(const T &x) { param_p[MINCUTOFF] = x; }
187 
188  // set the characteristic maximum (low-pass) cutoff value. At this
189  // x-ordinate value, the function has a value reduced 30 dB from its
190  // peak.
191  void setMaxCutoff(const T &x) { param_p[MAXCUTOFF] = x; }
192 
193  // set the order of the Butterworth function for the minimum (high-pass)
194  // portion of the bandpass
195  void setMinOrder(uInt order) { nl_p = order; }
196 
197  // set the order of the Butterworth function for the maximum (low-pass)
198  // portion of the bandpass
199  void setMaxOrder(uInt order) { nh_p = order; }
200 
201  // return the characteristic minimum (high-pass) cutoff value. At this
202  // x-ordinate value, the function has a value reduced 30 dB from its
203  // peak.
204  const T &getMinCutoff() const { return param_p[MINCUTOFF]; }
205 
206  // return the characteristic maximum (low-pass) cutoff value. At this
207  // x-ordinate value, the function has a value reduced 30 dB from its
208  // peak.
209  const T &getMaxCutoff() const { return param_p[MAXCUTOFF]; }
210 
211  // return the order of the Butterworth function for the minimum (high-pass)
212  // portion of the bandpass
213  uInt getMinOrder() const { return nl_p; }
214 
215  // return the order of the Butterworth function for the maximum (low-pass)
216  // portion of the bandpass
217  uInt getMaxOrder() const { return nh_p; }
218 
219  // set the scale of the function by setting its peak value. By default,
220  // the peak value is T(1);
221  void setPeak(T val) { param_p[PEAK] = val; }
222 
223  // return the scale of the function
224  const T &getPeak() const { return param_p[PEAK]; }
225 
226  // get/set the function mode. This is an alternate way to get/set the
227  // non-coefficient data for this function. The supported record fields
228  // are as follows:
229  // <pre>
230  // Field Name Type Role
231  // -------------------------------------------------------------------
232  // minOrder TpInt the order of the Butterworth function for the
233  // minimum (high-pass) portion of the bandpass
234  // maxOrder TpInt the order of the Butterworth function for the
235  // maximum (low-pass) portion of the bandpass
236  // An exception is thrown if either value is less than zero
237  // </pre>
238  // <group>
239  virtual void setMode(const RecordInterface& mode);
240  virtual void getMode(RecordInterface& mode) const;
241  // </group>
242 
243  // return True if the implementing function supports a mode. This
244  // implementation always returns True.
245  virtual Bool hasMode() const;
246 
247  // clone this function
248  virtual Function<T> *clone() const {
249  return new SimButterworthBandpass<T>(*this);
250  }
251 
252 private:
253  //# Non-parameter Data
254  // Minimum order
256  // Maximum order
258 
259  //# Make members of parent classes known.
260 protected:
261  using Function<T>::param_p;
262 public:
264 };
265 
266 
267 } //# NAMESPACE CASACORE - END
268 
269 #ifndef CASACORE_NO_AUTO_TEMPLATES
270 #include <casacore/scimath/Functionals/SimButterworthBandpass.tcc>
271 #endif //# CASACORE_NO_AUTO_TEMPLATES
272 #endif
FunctionParam< T > param_p
The parameters and masks.
Definition: Function.h:340
virtual T eval(const typename FunctionTraits< T >::ArgType *x) const
Evaluate the bandpass at &quot;x&quot;.
std::vector< double > Vector
Definition: ds9context.h:24
void setMinCutoff(const T &x)
set the characteristic minimum (high-pass) cutoff value.
uInt getMinOrder() const
return the order of the Butterworth function for the minimum (high-pass) portion of the bandpass ...
const T & getCenter() const
return the center of the bandpass.
virtual Bool hasMode() const
return True if the implementing function supports a mode.
SimButterworthBandpass< T > & operator=(const SimButterworthBandpass< T > &other)
copy(deep) another Butterworth function
const T & getMinCutoff() const
return the characteristic minimum (high-pass) cutoff value.
void setPeak(T val)
set the scale of the function by setting its peak value.
virtual void setMode(const RecordInterface &mode)
get/set the function mode.
void setMaxOrder(uInt order)
set the order of the Butterworth function for the maximum (low-pass) portion of the bandpass ...
const T & getMaxCutoff() const
return the characteristic maximum (low-pass) cutoff value.
a class for evaluating a Butterworth filter transfer function.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
SimButterworthBandpass()
create a zero-th order (all-pass) Butterworth bandpass function.
virtual ~SimButterworthBandpass()
Destructor.
void setMinOrder(uInt order)
set the order of the Butterworth function for the minimum (high-pass) portion of the bandpass ...
T ArgType
Type for arguments.
virtual void getMode(RecordInterface &mode) const
Numerical functional interface class for 1 dimension.
Definition: Function1D.h:75
const T & getPeak() const
return the scale of the function
uInt getMaxOrder() const
return the order of the Butterworth function for the maximum (low-pass) portion of the bandpass ...
Abstract base class for Record classes.
void setCenter(const T &x)
set the center of the bandpass.
virtual Function< T > * clone() const
clone this function
void setMaxCutoff(const T &x)
set the characteristic maximum (low-pass) cutoff value.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42