PSD using FFTW Halfcomplex transformation

旧城冷巷雨未停 提交于 2019-12-02 03:47:49

As described in Numerical Recipes, the normalization of the power-spectrum density (PSD) may vary depending on your exact definition of PSD. One possible definition which makes the sum of spectrum estimates correspond to the mean squared amplitude of the time domain function:

where P(k) is related to the FFT outputs X(k) through:


for some scaling factor S.

This seems to be the definition you are using based on your expected results.

Applying Parseval's theorem:


to the definition yields:


Or S=1/N2.

This of course assumes that you work with the entire spectrum. FFTW's Half-complex format on the other hand, as the name implies, gives you only half the spectrum (the other half being symmetric for real-valued inputs). You get the total power of a frequency component by adding in the equal-valued squared-magnitude of that symmetric spectrum value. This is where you get the factor of 2 from. Note that there are no corresponding symmetric outputs for real-valued index 0 and numberOfSamples/2, so you should not multiply by 2 in these cases.

So, your PSD should be computed as:

powVal = outputValues[0]*outputValues[0];
powVal /= (numberOfSamples*numberOfSamples);
for (index =1; index<numberOfSamples/2;index++){
  powVal = outputValues[index]*outputValues[index]+outputValues[numberOfSamples-index]*outputValues[numberOfSamples-index];
  powVal /= (numberOfSamples*numberOfSamples)/2;
}
powVal = outputValues[numberOfSamples/2]*outputValues[numberOfSamples/2];
powVal /= (numberOfSamples*numberOfSamples);

Note: the mean squared amplitude of your DC component should be 0.2*0.2 = 0.04 (not 0.2 which you indicated as your expected value for index 0).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!