FFTW信号频谱

时间:2017-04-04 13:45:30

标签: c++ signals fft fftw spectrum

我目前正致力于实施信号频谱图。 我的输入数据:1.051,1.365,1.837,2.334,2.486,2.688,2.878,2.579,2.11,1.660,0.936,0.73,1.036,1.356,1.796,2.043,2.462,2.935,2.892,2.609,2.151,1.641,0.961, 0.738,0.767,1.303,1.503,2.004,2.435,2.931,2.908,2.641,1.935,1.423,0.988,0.774,0.755,1.018,1.465,1.966,2.662,2.919,2.918,2.669,1.976,1.462,1.017,0.775, 0.746,0.989,1.452,1.927,2.637,2.908,2.927,2.441,2.015,1.501,1.302,1.025,0.739,0.962,1.644,2.144,2.605,2.895,2.935,2.467,2.304,1.779,1.331,1.039,0.732, 0.936,1.608,2.103,2.575,2.88,2.688,2.449,2.334,1.835,1.365,1.054,0.725,0.913,1.568,2.067,2.288,2.867,2.69,2.516,2.379,1.877,1.397,1.072,0.721,1.144, 1.277,1.77

您可以在我的屏幕截图中看到此数据。这是底图。它只包含100分。并且不可能增加它的数量。

输入信号频率为1000 Hz。它可以改变。

我使用FFTW来获取频谱。

输入信号频率为1000 Hz。在顶部图表上,它仅显示约200 Hz。这是主要问题。我想也许我的代码错了或分数不够。

我的数据分析代码:

    QVectorDouble points(100);
    points = this->reader->ReadCOM(100);
    double timePassed = this->reader->timePassed;
    unsigned int n = points.count();
    double timeShift = timePassed / n;

    QVectorDouble signalX(n), signalY(n);

    for (unsigned int i = 0; i < n; i++)
    {
        signalX[i] = i*timeShift; // x goes from 0 to  timePassed to take points amount
        signalY[i] = points[i];
    }

    fftw::maxthreads = get_max_threads();
    unsigned int np = n / 2 + 1;
    size_t align = sizeof(Complex);

    array1<Complex> F(np, align);
    array1<double> f(n, align);

    rcfft1d Forward(n, f, F);

    for(unsigned int i = 0; i < n; i++) {
        f[i] = points[i];
    }

    Forward.fft(f, F);

    QVectorDouble spectrX(np), spectrY(np);
    for (int i = 0; i < np; i++)
    {
      spectrX[i] = i * 20; //multiply by 20 because np is (100/2 + 1) and chart maximum xOrigin is 1000
      spectrY[i] = abs(F[i]) / np;
    }

enter image description here

1 个答案:

答案 0 :(得分:0)

以下几件事情并不恰当:

  • 在时域图中,采样率为1000Hz的100个点应该给你0.1秒的总持续时间。假设signalX为0.1秒,用于timePassed的公式是正确的。您应该查看为什么该变量实际上大约为0.4秒。
  • 由于您在0.1秒内有8个完整周期,因此您应该获得8 * 1 / 0.1 = 80Hz的峰值频率。因此,显然光谱图的x轴缩放有问题。更具体地说,频率增量应设置为1000/np或10 np == 10。这将产生高达500Hz的图,这是采样率的一半(与奈奎斯特定理一致),其中峰值将以正确的80Hz频率出现。