从CSV文件

时间:2015-09-06 06:39:52

标签: c++ csv dft

我需要在CSV文件中计算非线性振荡器的功率谱(CSV文件有2列用于绘制振荡器随时间的位移)。我已设法使用下面的代码获得输出,但它不正确。我已经排除故障并且很确定问题在于应用离散傅立叶变换的两个for循环。任何帮助/提示都表示赞赏。

我有一个CSV文件,我将其中一列分配给数组

while (fileInput.good()){
      getline( fileInput, value, ',' );
      istringstream iss(value); // string stream
      getline(iss, time, ','); // read first part up to comma, ignore the comma
      iss >> disp; // read the second part

      inData[columnSize] = atof(disp.c_str());
      columnSize++;
        }

然后假定使用

对其应用离散傅里叶变换
for (k = 0; k < n; k++) {  // For each output element 
        long double sumreal = 0;
        long double sumimag = 0;
        int t;
        for (t = 0; t < n; t++) {  // For each input element 

            double angle = ( 2.0 * 3.141593 * t * k )/ n;
            sumreal += inData[t]  * cos(angle);
            sumimag += inData[t]  * sin(angle);
        }


        DFToutput << k << ',' << (pow(sumreal,2) + pow(sumimag, 2)) << endl;

    }

由于我的输入数组纯粹是真实的,我省略了DFT上this link中的虚构输入。

0 个答案:

没有答案