本文整理汇总了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;
}