HOPS
HOPS class reference
MHO_MathUtilities.hh
Go to the documentation of this file.
1 #ifndef MHO_MathUtilities_HH__
2 #define MHO_MathUtilities_HH__
3 
4 #include <cmath>
5 #include <complex>
6 #include <string>
7 #include <vector>
8 
9 namespace hops
10 {
11 
25 {
26  public:
28  virtual ~MHO_MathUtilities(){};
29 
30  //ported from hops3 c libraries
31 
41  static double dwin(double value, double lower, double upper);
54  static int parabola(double y[3], double lower, double upper, double* x_max, double* amp_max, double q[3]);
55 
64  static int minvert3(double a[3][3], double ainv[3][3]);
65 
78  static int linterp (double coord1, double value1, double coord2, double value2, double coord, double *value);
79 
95  static int ap_mean(double start, double stop, double *coords, double *val1, double *val2, int n, int *nstart, double *result1, double *result2);
96 
97  //returns the average of the values in a vector
105  static double average(std::vector< double >& vec);
106 
107  //returns the average of the values in a vector assuming they are angles (radians)
115  static double angular_average(std::vector< double >& vec);
116 
127  static void DetermineChannelFrequencyLimits(double sky_freq, double bandwidth, std::string net_sideband,
128  double& lower_freq, double& upper_freq)
129  {
130  if(net_sideband == "U")
131  {
132  lower_freq = sky_freq;
133  upper_freq = sky_freq + bandwidth;
134  return;
135  }
136  if(net_sideband == "L")
137  {
138  upper_freq = sky_freq;
139  lower_freq = sky_freq - bandwidth;
140  return;
141  }
142  //not upper or lower sideband...assume double sideband (sky_freq is center)
143  upper_freq = sky_freq + bandwidth;
144  lower_freq = sky_freq - bandwidth;
145  }
146 
162  template< typename XValueType >
163  static int FindIntersection(XValueType a, XValueType b, XValueType c, XValueType d, XValueType result[2])
164  {
165 
166 
167  XValueType arr[4];
168  int index[4];
169 
170  arr[0] = a;
171  index[0] = 0;
172  arr[1] = b;
173  index[1] = 0;
174  arr[2] = c;
175  index[2] = 1;
176  arr[3] = d;
177  index[3] = 1;
178 
179  if(arr[1] > arr[3])
180  {
181  std::swap(arr[1], arr[3]);
182  std::swap(index[1], index[3]);
183  };
184  if(arr[0] > arr[2])
185  {
186  std::swap(arr[0], arr[2]);
187  std::swap(index[0], index[2]);
188  };
189  if(arr[0] > arr[1])
190  {
191  std::swap(arr[0], arr[1]);
192  std::swap(index[0], index[1]);
193  };
194  if(arr[2] > arr[3])
195  {
196  std::swap(arr[2], arr[3]);
197  std::swap(index[2], index[3]);
198  };
199  if(arr[1] > arr[2])
200  {
201  std::swap(arr[1], arr[2]);
202  std::swap(index[1], index[2]);
203  };
204 
205  //now the values in arr should be sorted in increasing order
206  //and the values in index should show which interval's end-points they belong to
207 
208  //if the values in index have the form:
209  //0011 or 1100 then there is no overlap...although the end points may
210  //just touch
211 
212  //if the values in the index have the form:
213  // 1001, 0110, 0101, or 1010 then there is overlap and the overlap interval
214  //is {arr[1], arr[2]}
215 
216  int sum;
217  sum = index[0] + index[1];
218 
219  if((sum == 0) || (sum == 2))
220  {
221  //there is no overlap, but we need to see if the end-points of the
222  //two intervals are the same number
223  if(arr[2] == arr[1])
224  {
225  //endpoints are the same value
226  //call this an intersection of 1 point
227  result[0] = arr[1];
228  return 1;
229  }
230  else
231  {
232  //no intersection at all
233  return 0;
234  }
235  }
236  else
237  {
238  //there is overlap, but check how big the overlap interval is
239  if(arr[2] == arr[1])
240  {
241  //the two overlapping points are the same value
242  //call this an intersection of 1 point
243  result[0] = arr[1];
244  return 1;
245  }
246  else
247  {
248  //overlap is larger than zero, return the interval of overlap
249  result[0] = arr[1];
250  result[1] = arr[2];
251  return 2;
252  }
253  }
254  }
255 };
256 
257 } // namespace hops
258 
259 #endif
Class MHO_MathUtilities.
Definition: MHO_MathUtilities.hh:25
static int ap_mean(double start, double stop, double *coords, double *val1, double *val2, int n, int *nstart, double *result1, double *result2)
Calculates average phase from start to stop using given coordinates and values.
Definition: MHO_MathUtilities.cc:159
MHO_MathUtilities()
Definition: MHO_MathUtilities.hh:27
static double angular_average(std::vector< double > &vec)
Calculates the average angle in radians from a vector of angles.
Definition: MHO_MathUtilities.cc:346
static int minvert3(double a[3][3], double ainv[3][3])
Calculates the inverse of a 3x3 matrix and stores it in ainv.
Definition: MHO_MathUtilities.cc:57
static int FindIntersection(XValueType a, XValueType b, XValueType c, XValueType d, XValueType result[2])
Function FindIntersection looks for overlap between the intervals [a,b) and [c,d) although if a,...
Definition: MHO_MathUtilities.hh:163
static void DetermineChannelFrequencyLimits(double sky_freq, double bandwidth, std::string net_sideband, double &lower_freq, double &upper_freq)
Calculates lower and upper frequency limits for a given channel based on sky frequency,...
Definition: MHO_MathUtilities.hh:127
static int parabola(double y[3], double lower, double upper, double *x_max, double *amp_max, double q[3])
Calculates parabola parameters and maximum x, amplitude values within a range.
Definition: MHO_MathUtilities.cc:22
static double dwin(double value, double lower, double upper)
Clamps a value between lower and upper bounds.
Definition: MHO_MathUtilities.cc:12
static double average(std::vector< double > &vec)
Calculates the average of values in a vector.
Definition: MHO_MathUtilities.cc:330
virtual ~MHO_MathUtilities()
Definition: MHO_MathUtilities.hh:28
static int linterp(double coord1, double value1, double coord2, double value2, double coord, double *value)
Performs linear interpolation between two points and returns the interpolated value.
Definition: MHO_MathUtilities.cc:110
Definition: MHO_ChannelLabeler.hh:17
Definition: vex.h:175