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{
135public:
136 //# Enumerations
137 // Enumeration of the function parameters
139
140 //# Constructors
141 // create a zero-th order (all-pass) Butterworth bandpass function.
143
144 // create a Butterworth bandpass function.
145 SimButterworthBandpass(const uInt minord, const uInt maxord,
146 const T &mincut=T(-1), const T &maxcut=T(1),
147 const T &center=T(0), const T &peak=T(1));
148
149 // create a fully specified Butterworth bandpass in which the
150 // low and high pass orders are stored in a Record
152 T mincut=T(-1), T maxcut=T(1),
153 T center=T(0), T peak=T(1));
154
155 // create a copy of another Butterworth bandpass function
157
158 // copy(deep) another Butterworth function
161
162 // Destructor
164
165
166 //# Operators
167 // Evaluate the bandpass at "x".
168 virtual T eval(const typename FunctionTraits<T>::ArgType *x) const;
169
170 //# Member functions
171 // set the center of the bandpass. This is the x-ordinate value that
172 // evaluates to the peak of the function.
173 void setCenter(const T &x) { param_p[CENTER] = x; }
174
175 // return the center of the bandpass. This is the x-ordinate value that
176 // evaluates to the peak of the function.
177 const T &getCenter() const { return param_p[CENTER]; }
178
179 // set the characteristic minimum (high-pass) cutoff value. At this
180 // x-ordinate value, the function has a value reduced 30 dB from its
181 // peak.
182 void setMinCutoff(const T &x) { param_p[MINCUTOFF] = x; }
183
184 // set the characteristic maximum (low-pass) cutoff value. At this
185 // x-ordinate value, the function has a value reduced 30 dB from its
186 // peak.
187 void setMaxCutoff(const T &x) { param_p[MAXCUTOFF] = x; }
188
189 // set the order of the Butterworth function for the minimum (high-pass)
190 // portion of the bandpass
191 void setMinOrder(uInt order) { nl_p = order; }
192
193 // set the order of the Butterworth function for the maximum (low-pass)
194 // portion of the bandpass
195 void setMaxOrder(uInt order) { nh_p = order; }
196
197 // return the characteristic minimum (high-pass) cutoff value. At this
198 // x-ordinate value, the function has a value reduced 30 dB from its
199 // peak.
200 const T &getMinCutoff() const { return param_p[MINCUTOFF]; }
201
202 // return the characteristic maximum (low-pass) cutoff value. At this
203 // x-ordinate value, the function has a value reduced 30 dB from its
204 // peak.
205 const T &getMaxCutoff() const { return param_p[MAXCUTOFF]; }
206
207 // return the order of the Butterworth function for the minimum (high-pass)
208 // portion of the bandpass
209 uInt getMinOrder() const { return nl_p; }
210
211 // return the order of the Butterworth function for the maximum (low-pass)
212 // portion of the bandpass
213 uInt getMaxOrder() const { return nh_p; }
214
215 // set the scale of the function by setting its peak value. By default,
216 // the peak value is T(1);
217 void setPeak(T val) { param_p[PEAK] = val; }
218
219 // return the scale of the function
220 const T &getPeak() const { return param_p[PEAK]; }
221
222 // get/set the function mode. This is an alternate way to get/set the
223 // non-coefficient data for this function. The supported record fields
224 // are as follows:
225 // <pre>
226 // Field Name Type Role
227 // -------------------------------------------------------------------
228 // minOrder TpInt the order of the Butterworth function for the
229 // minimum (high-pass) portion of the bandpass
230 // maxOrder TpInt the order of the Butterworth function for the
231 // maximum (low-pass) portion of the bandpass
232 // An exception is thrown if either value is less than zero
233 // </pre>
234 // <group>
235 virtual void setMode(const RecordInterface& mode);
236 virtual void getMode(RecordInterface& mode) const;
237 // </group>
238
239 // return True if the implementing function supports a mode. This
240 // implementation always returns True.
241 virtual Bool hasMode() const;
242
243 // clone this function
244 virtual Function<T> *clone() const {
245 return new SimButterworthBandpass<T>(*this);
246 }
247
248private:
249 //# Non-parameter Data
250 // Minimum order
252 // Maximum order
254
255 //# Make members of parent classes known.
256protected:
257 using Function<T>::param_p;
258public:
259 using Function<T>::nparameters;
260};
261
262
263} //# NAMESPACE CASACORE - END
264
265#ifndef CASACORE_NO_AUTO_TEMPLATES
266#include <casacore/scimath/Functionals/SimButterworthBandpass.tcc>
267#endif //# CASACORE_NO_AUTO_TEMPLATES
268#endif
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:330
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:228
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
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40