File: polynomialchannelfitter.h

package info (click to toggle)
wsclean 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,196 kB
  • sloc: cpp: 34,504; ansic: 234; python: 174; makefile: 10
file content (44 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef POLYNOMIAL_CHANNEL_FITTER_H
#define POLYNOMIAL_CHANNEL_FITTER_H

#include "uvector.h"

class PolynomialChannelFitter
{
public:
	void Clear() { _channels.clear(); _dataPoints.clear(); }
	
	void AddChannel(double startFrequency, double endFrequency)
	{
		_channels.push_back(std::make_pair(startFrequency, endFrequency));
	}
	
	void AddDataPoint(size_t channel, double y)
	{
		_dataPoints.push_back(std::make_pair(channel, y));
	}
	
	void Fit(ao::uvector<double>& terms, size_t nTerms);
	
	static double Evaluate(double x, const ao::uvector<double>& terms)
	{
		double val = terms[0];
		double f = 1.0;
		for(size_t i=1; i!=terms.size(); ++i)
		{
			f *= x;
			val += f * terms[i];
		}
		return val;
	}

private:
	/**
	 * Start and end frequencies of the channels
	 */
	ao::uvector<std::pair<double, double>> _channels;
	ao::uvector<std::pair<size_t,double>> _dataPoints;
};

#endif