当前位置: 首页>>代码示例>>C++>>正文


C++ TimeSeries::getYs方法代码示例

本文整理汇总了C++中TimeSeries::getYs方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeSeries::getYs方法的具体用法?C++ TimeSeries::getYs怎么用?C++ TimeSeries::getYs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeSeries的用法示例。


在下文中一共展示了TimeSeries::getYs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calculate

double AnalyticSignal::calculate(const TimeSeries& ts, int modeNo, const string& prefix) {
	const vector<double>& xs = ts.getXs();
	const vector<double>& realSignal = ts.getYs();
	unsigned n = realSignal.size();
	double 	xStep = xs[1] - xs[0]; // Assuming even sampling
    fftw_complex* conjugatedSignal = (fftw_complex*) malloc(sizeof(fftw_complex) * n);
    for (unsigned i = 0; i < n; i++) {
    	conjugatedSignal[i][0] = realSignal[i];
    	conjugatedSignal[i][1] = 0;
    }
	fft(true, realSignal.size(), conjugatedSignal, 0);
	fft(false, realSignal.size(), conjugatedSignal, M_PI_2);
	//double* amplitude = (double*) malloc(sizeof(double) * n);
	//double* phase = (double*) malloc(sizeof(double) * n);
	//double* frequency = (double*) malloc(sizeof(double) * (n - 2));
	ofstream imfStream(prefix + "_imf_" + to_string(modeNo) + ".csv");
	ofstream ampStream(prefix + "_amp_" + to_string(modeNo) + ".csv");
	ofstream freqStream(prefix + "_freq_" + to_string(modeNo) + ".csv");
	ofstream perStream(prefix + "_per_" + to_string(modeNo) + ".csv");
	double totalEnergy = 0;
	double prevZeroCross = xs[0];
	for (unsigned i = 0; i < n; i++) {
		double x = xs[i];
		double u = realSignal[i];
		double v = conjugatedSignal[i][0] / n; // the fft is unnormalized
		double u2v2 = u * u + v * v;
		double amplitude = sqrt(u2v2);
		totalEnergy += u2v2;
		//double phase = atan(v / u);
		imfStream << x << " " << u << endl;
		ampStream << x << " " << amplitude << endl;
		if (i > 0 && i < n - 1) {
			double frequency = (getRealTangent(i, conjugatedSignal) * u / n - getTangent(i, realSignal) * v) / u2v2 / xStep;
			freqStream << x << " " << frequency << endl;
		}
		// Calculating average period based on zero-crossings (not part of Analytic signal calculation actually)
		if (i > 0) {
			if ((u > 0 && realSignal[i - 1] < 0) || (u < 0 && realSignal[i - 1] > 0)) {
				double zeroCross = (x + xs[i - 1]) / 2;
				if (prevZeroCross > xs[0]) {
					perStream << (zeroCross + prevZeroCross) / 2 << " " << 2 * (zeroCross - prevZeroCross) << endl;
				}
				prevZeroCross = zeroCross;
			}
		}
	}
	imfStream.close();
	ampStream.close();
	freqStream.close();
	perStream.close();
	return totalEnergy / n;
}
开发者ID:nigulo,项目名称:cpp,代码行数:52,代码来源:AnalyticSignal.cpp


注:本文中的TimeSeries::getYs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。