Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从CSV文件计算功率谱_C++_Csv_Dft - Fatal编程技术网

C++ 从CSV文件计算功率谱

C++ 从CSV文件计算功率谱,c++,csv,dft,C++,Csv,Dft,我需要在CSV文件中计算非线性振荡器的功率谱(CSV文件有两列来绘制振荡器随时间的位移)。我已经用下面的代码获得了一个输出,但它是不正确的。我已经排除了故障,并且非常确定问题在于应用离散傅里叶变换的两个for循环。欢迎提供任何帮助/提示 我有一个CSV文件,我将其中一列指定给一个数组 while (fileInput.good()){ getline( fileInput, value, ',' ); istringstream iss(value); // string

我需要在CSV文件中计算非线性振荡器的功率谱(CSV文件有两列来绘制振荡器随时间的位移)。我已经用下面的代码获得了一个输出,但它是不正确的。我已经排除了故障,并且非常确定问题在于应用离散傅里叶变换的两个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;

    }
每个输出元素的(k=0;k 长双sumreal=0; 长双sumimag=0; int t; 对于(t=0;tDFT输出角度计算看起来可疑,最大值约为n*2*pi。
sumimag+=-inData…
您如何知道您的输出不正确?您的测试用例是什么?它是@MarkSetchell和第一个注释器的混合。我将第一个for循环的最大值改为n/2(在上面的代码中,功率谱反映在绘图中心周围)。我还需要更改虚数和上的符号。谢谢您的帮助!