casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef SCIMATH_SIMBUTTERWORTHBANDPASS_H
27#define SCIMATH_SIMBUTTERWORTHBANDPASS_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/Containers/Block.h>
33#include <casacore/scimath/Functionals/Function1D.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// a class for evaluating a Butterworth filter transfer function.
39// </summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="wbrouw" date="2001/11/14"
44// tests="tSimButterworthBandpass" demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class="FunctionParam">FunctionParam</linkto> class
49// <li> <linkto class=Function1D>Function1D</linkto>
50// </prerequisite>
51//
52// <etymology>
53// "Butterworth" refers to the Butterworth function for describing
54// filter transfer functions (Butterworth, S, "On the theory of filter
55// amplifiers," Wireless Engineer, vol. 7 pp. 536-541, October 1930).
56// "Bandpass" reflects that the transfer function is has both low and high
57// frequency cutoffs.
58// "Sim" indicates that this implementation is not necessarily appropriate
59// characterizing real bandpass filters; in the future, there may be a
60// more general class called simply "Butterworth".
61// </etymology>
62//
63// <synopsis>
64// This function class simulates the (amplitude) transfer function for a
65// wideband bandpass filter constructed from the combination of a low-pass
66// and a high-pass Butterworth filter.
67//
68// In analog electronic filter design, a Butterworth low-pass filter is
69// one in which the amplitude transfer function, |H(jw)| (where j = sqrt(-1)
70// and w is the angular frequency), is given by:
71// <srcblock>
72// |H(jw)| = 1 / sqrt(1 + (w/w_c)^(2*n))
73// </srcblock>
74// where n refers to the filter "order" and w_c is the "cutoff frequency".
75// When w = w_c, the filter output is 1/sqrt(2) that of the input, and the
76// higher the order, the steeper the drop off towards zero and the closer
77// the approximation to a idealized step function.
78//
79// Filter theory provides transformations for deriving transfer functions
80// of high-pass and band-pass filters which reflect how the electrical
81// circuits actually work. However, to simplify this class's implementation
82// and to make the transfer function behavior more predictable by the naive
83// user, THIS CLASS DOES NOT ACTUALLY USE THE PROPER TRANSFORMATIONS (see
84// Etymology section above).
85// Instead, the Butterworth bandpass transfer function is approximated by
86// low pass component, given above, combined with a pseudo high-pass function
87// that is of the same form but with w substituted with -w. Both components
88// are shifted such that its peak transfer point is at a given "center"
89// position. The cutoff value and order can be set independently for both
90// ends of the passband.
91// </synopsis>
92//
93// <example>
94// <srcblock>
95// // Create a bandpass function centered on x=0.8 and cutoffs at 0 and 2.5.
96// // The orders of the drop-offs will 4 at the low end and 5 at the high
97// // end. The peak will by 1.0 by default.
98// SimButterworthBandpass<Double> butt(4, 5, 0, 2.5, 0.8);
99//
100// Double z = butt(1); // z = 1.0
101// z = butt(0); // z = 1/sqrt(2)
102// z = butt(2.5); // z = 1/sqrt(2)
103// z = butt(-25); // z ~ 9.24e-9 ~ 0
104//
105// // change the low-end cutoff to -25.0
106// butt.setMinCutoff(-25);
107// z = butt(-25); // z = 1/sqrt(2)
108// </srcblock>
109// </example>
110//
111// <motivation>
112// This class was created to simulate systemtic Butterworth bandpasses
113// within the simulator tool. It can used by the SimBJones class to vary the
114// bandpass in a predictable way. However, it has limited value for real
115// filter analysis, and it is not expected to be a realistic representation
116// of real bandpass filters in use with radio telescopes backends.
117// </motivation>
118//
119// <templating arg=T>
120// <li> T should have standard numerical operators. Current
121// implementation only tested for real types (and their AutoDiffs).
122// </templating>
123//
124// <thrown>
125// <li> Assertion if indices out-of-range
126// </thrown>
127//
128// <todo asof="2001/11/14">
129// <li> Nothing I know of
130// </todo>
131
132template <class T>
134 public:
135 // # Enumerations
136 // Enumeration of the function parameters
138
139 // # Constructors
140 // create a zero-th order (all-pass) Butterworth bandpass function.
142
143 // create a Butterworth bandpass function.
144 SimButterworthBandpass(const uInt minord, const uInt maxord, const T &mincut = T(-1),
145 const T &maxcut = T(1), const T &center = T(0), const T &peak = T(1));
146
147 // create a fully specified Butterworth bandpass in which the
148 // low and high pass orders are stored in a Record
149 explicit SimButterworthBandpass(const RecordInterface &gr, T mincut = T(-1), T maxcut = T(1),
150 T center = T(0), T peak = T(1));
151
152 // create a copy of another Butterworth bandpass function
154
155 // copy(deep) another Butterworth function
157
158 // Destructor
160
161 // # Operators
162 // Evaluate the bandpass at "x".
163 virtual T eval(const typename FunctionTraits<T>::ArgType *x) const;
164
165 // # Member functions
166 // set the center of the bandpass. This is the x-ordinate value that
167 // evaluates to the peak of the function.
168 void setCenter(const T &x) { param_p[CENTER] = x; }
169
170 // return the center of the bandpass. This is the x-ordinate value that
171 // evaluates to the peak of the function.
172 const T &getCenter() const { return param_p[CENTER]; }
173
174 // set the characteristic minimum (high-pass) cutoff value. At this
175 // x-ordinate value, the function has a value reduced 30 dB from its
176 // peak.
177 void setMinCutoff(const T &x) { param_p[MINCUTOFF] = x; }
178
179 // set the characteristic maximum (low-pass) cutoff value. At this
180 // x-ordinate value, the function has a value reduced 30 dB from its
181 // peak.
182 void setMaxCutoff(const T &x) { param_p[MAXCUTOFF] = x; }
183
184 // set the order of the Butterworth function for the minimum (high-pass)
185 // portion of the bandpass
187
188 // set the order of the Butterworth function for the maximum (low-pass)
189 // portion of the bandpass
191
192 // return the characteristic minimum (high-pass) cutoff value. At this
193 // x-ordinate value, the function has a value reduced 30 dB from its
194 // peak.
195 const T &getMinCutoff() const { return param_p[MINCUTOFF]; }
196
197 // return the characteristic maximum (low-pass) cutoff value. At this
198 // x-ordinate value, the function has a value reduced 30 dB from its
199 // peak.
200 const T &getMaxCutoff() const { return param_p[MAXCUTOFF]; }
201
202 // return the order of the Butterworth function for the minimum (high-pass)
203 // portion of the bandpass
204 uInt getMinOrder() const { return nl_p; }
205
206 // return the order of the Butterworth function for the maximum (low-pass)
207 // portion of the bandpass
208 uInt getMaxOrder() const { return nh_p; }
209
210 // set the scale of the function by setting its peak value. By default,
211 // the peak value is T(1);
212 void setPeak(T val) { param_p[PEAK] = val; }
213
214 // return the scale of the function
215 const T &getPeak() const { return param_p[PEAK]; }
216
217 // get/set the function mode. This is an alternate way to get/set the
218 // non-coefficient data for this function. The supported record fields
219 // are as follows:
220 // <pre>
221 // Field Name Type Role
222 // -------------------------------------------------------------------
223 // minOrder TpInt the order of the Butterworth function for the
224 // minimum (high-pass) portion of the bandpass
225 // maxOrder TpInt the order of the Butterworth function for the
226 // maximum (low-pass) portion of the bandpass
227 // An exception is thrown if either value is less than zero
228 // </pre>
229 // <group>
230 virtual void setMode(const RecordInterface &mode);
231 virtual void getMode(RecordInterface &mode) const;
232 // </group>
233
234 // return True if the implementing function supports a mode. This
235 // implementation always returns True.
236 virtual Bool hasMode() const;
237
238 // clone this function
239 virtual Function<T> *clone() const { return new SimButterworthBandpass<T>(*this); }
240
241 private:
242 // # Non-parameter Data
243 // Minimum order
245 // Maximum order
247
248 // # Make members of parent classes known.
249 protected:
250 using Function<T>::param_p;
251
252 public:
253 using Function<T>::nparameters;
254};
255
256} // namespace casacore
257
258#ifndef CASACORE_NO_AUTO_TEMPLATES
259#include <casacore/scimath/Functionals/SimButterworthBandpass.tcc>
260#endif // # CASACORE_NO_AUTO_TEMPLATES
261#endif
Function1D()
Constructors.
Definition Function1D.h:81
T ArgType
Type for arguments.
FunctionParam< T > param_p
Definition Function.h:337
virtual Bool hasMode() const
return True if the implementing function supports a mode.
SimButterworthBandpass(const uInt minord, const uInt maxord, const T &mincut=T(-1), const T &maxcut=T(1), const T &center=T(0), const T &peak=T(1))
create a Butterworth bandpass function.
const T & getMaxCutoff() const
return the characteristic maximum (low-pass) cutoff value.
void setMinCutoff(const T &x)
set the characteristic minimum (high-pass) cutoff value.
void setCenter(const T &x)
set the center of the bandpass.
void setMaxOrder(uInt order)
set the order of the Butterworth function for the maximum (low-pass) portion of the bandpass
void setMaxCutoff(const T &x)
set the characteristic maximum (low-pass) cutoff value.
SimButterworthBandpass(const RecordInterface &gr, T mincut=T(-1), T maxcut=T(1), T center=T(0), T peak=T(1))
create a fully specified Butterworth bandpass in which the low and high pass orders are stored in a R...
virtual void getMode(RecordInterface &mode) const
void setMinOrder(uInt order)
set the order of the Butterworth function for the minimum (high-pass) portion of the bandpass
SimButterworthBandpass()
create a zero-th order (all-pass) Butterworth bandpass function.
virtual T eval(const typename FunctionTraits< T >::ArgType *x) const
Evaluate the bandpass at "x".
const T & getMinCutoff() const
return the characteristic minimum (high-pass) cutoff value.
virtual ~SimButterworthBandpass()
Destructor.
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.
void setPeak(T val)
set the scale of the function by setting its peak value.
virtual Function< T > * clone() const
clone this function
virtual void setMode(const RecordInterface &mode)
get/set the function mode.
SimButterworthBandpass(const SimButterworthBandpass &other)
create a copy of another Butterworth bandpass function
const T & getPeak() const
return the scale of the function
SimButterworthBandpass< T > & operator=(const SimButterworthBandpass< T > &other)
copy(deep) another Butterworth function
uInt getMaxOrder() const
return the order of the Butterworth function for the maximum (low-pass) portion of the bandpass
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
uInt order() const
What is the order of the polynomial, i.e.
RecordInterface()
The default constructor creates an empty record with a variable structure.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40