来自 jTransforms DoubleFFT_1D 的功率谱密度
我正在使用 Jtransforms java 库对给定的数据集执行分析。
数据示例如下:
980,988,1160,1080,928,1068,1156,1152,1176,1264
我在 jTransforms 中使用 DoubleFFT_1D 函数。 数据输出如下:
10952, -152, 80.052, 379.936, -307.691, 12.734, -224.052, 427.607, -48.308, 81.472
我无法解释输出。据我了解,输出数组中的第一个元素是 10 个输入的总和 (10952)。这是
我不理解的输出数组的其他元素。最终,我想在图表上绘制输入数据的功率谱密度,并找到 0 到 0.5 Hz 之间的量。
jTransform 函数的文档指出(其中 a 是数据集):
public void realForward(double[] a)
计算实数的一维前向 DFT 数据将结果保留在 .输出数据的物理布局 如下:如果 n 是偶数,则
a[2*k] = Re[k], 0 <= k < n / 2 a[2*k+1] = Im[k], 0 < k< n / 2 a[1] = Re[n/2]
如果 n 是奇数则
a[2*k] = Re[k], 0 <= k < (n+1)/2 a[2*k+1] = Im[k], 0 < k< (n-1)/2 a[1] = Im[(n-1)/2]
此方法仅计算实际变换的一半元素。 另一半满足对称条件。如果你想要完整的 真正的前向变换,使用realForwardFull。为了取回原始数据, 在此方法的输出上使用 realInverse。
参数:a - 要转换的数据
现在使用上面的方法:(由于我的数据数组的长度是10,所以使用“n是偶数”方法)
Re[0] = 10952
Re[1] = 80.052
Re[2] = -307.691
Re[3] = -224.052
Re[4] = -48.308
Re[5] = 12.734
Im[0] = -152
Im[1] = 379.936
Im[2] = 12.734
Im[3] = 427.607
Im[4] = 81.472
所以有一些问题: 这个输出看起来正确吗?在我看来,Re[0] 不应该是 10952,它是原始数组中所有元素的总和。
似乎输出应该稍微更正:(我错了吗?)
Re[0] = 80.052
Re[1] = -307.691
Re[2] = -224.052
Re[3] = -48.308
Re[4] = -152
Im[0] = 379.936
Im[1] = 12.734
Im[2] = 427.607
Im[3] = 81.472
现在使用论坛中发布的以下方法:
要获得 bin k 的大小,您需要计算 sqrt(re * re + im * im)< /code>,其中 re、im 是 bin k 的 FFT 输出中的实部和虚部。
对于您的特定 FFT re[k] = a[2*k] 和 im[k] = a[2*k+1]
。因此计算功率谱:
for k in 0 to N/2 - 1
{
spectrum[k] = sqrt(sqr(a[2*k]) + sqr(a[2*k+1]))
}
因此:
spectrum[0] = 388.278
spectrum[1] = 307.955
spectrum[2] = 482.75
spectrum[3] = 94.717
一些问题。这个数据看起来正确吗?我走在正确的轨道上吗? 然后,这些频谱数据会绘制出这样的结果:
388.278 at .125 Hz
307.955 at .25 Hz
482.75 at .375 Hz
94.717 at .5 Hz
我离题还远吗?我的目标是生成 0 到 0.5Hz 的功率谱密度条形图
I'm using Jtransforms java library to perform analysis on a given dataset.
An example of the data is as follows:
980,988,1160,1080,928,1068,1156,1152,1176,1264
I'm using the DoubleFFT_1D function in jTransforms.
The data output is as follows:
10952, -152, 80.052, 379.936, -307.691, 12.734, -224.052, 427.607, -48.308, 81.472
I'm having trouble interpreting the output. I understand that the first element in the output array is the total of the 10 inputs (10952). It's
the other elements of the output array that i don't understand. Ultimately, I want to plot the Power Spectral Density of the input data on a graph and find amounts between 0 and .5 Hz.
The documentation for the jTransform functions states (where a is the data set):
public void realForward(double[] a)
computes 1D forward DFT of real
data leaving the result in a . The physical layout of the output data
is as follows:if n is even then
a[2*k] = Re[k], 0 <= k < n / 2 a[2*k+1] = Im[k], 0 < k < n / 2 a[1] = Re[n/2]
if n is odd then
a[2*k] = Re[k], 0 <= k < (n+1)/2 a[2*k+1] = Im[k], 0 < k< (n-1)/2 a[1] = Im[(n-1)/2]
This method computes only half of the elements of the real transform.
The other half satisfies the symmetry condition. If you want the full
real forward transform, use realForwardFull. To get back the original data,
use realInverse on the output of this method.Parameters: a - data to transform
Now using the methods above: (since the length of my data array is 10, the "n is even" methods are used)
Re[0] = 10952
Re[1] = 80.052
Re[2] = -307.691
Re[3] = -224.052
Re[4] = -48.308
Re[5] = 12.734
Im[0] = -152
Im[1] = 379.936
Im[2] = 12.734
Im[3] = 427.607
Im[4] = 81.472
So some questions:
Does this output look correct? It seems to me that Re[0] should not be 10952 which is the sum of all elements in the original array.
Seems like the output should be slightly corrected: (am I wrong?)
Re[0] = 80.052
Re[1] = -307.691
Re[2] = -224.052
Re[3] = -48.308
Re[4] = -152
Im[0] = 379.936
Im[1] = 12.734
Im[2] = 427.607
Im[3] = 81.472
Now using the following method posted in the forum:
To get the magnitude of bin k you need to calculate sqrt(re * re + im * im)
, where re, im are the real and imaginary components in the FFT output for bin k.
For your particular FFT re[k] = a[2*k] and im[k] = a[2*k+1]
. Therefore to calculate the power spectrum:
for k in 0 to N/2 - 1
{
spectrum[k] = sqrt(sqr(a[2*k]) + sqr(a[2*k+1]))
}
Thus:
spectrum[0] = 388.278
spectrum[1] = 307.955
spectrum[2] = 482.75
spectrum[3] = 94.717
Some questions. Does this data look correct? Am I on the right track?
Would this spectrum data then plot out something like this:
388.278 at .125 Hz
307.955 at .25 Hz
482.75 at .375 Hz
94.717 at .5 Hz
Am I way off? My goal is to produce a Power Spectral Density bar chart from 0 to .5Hz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您需要按如下方式解释输出数据:
因此,幅度为:
[抱歉,我现在有两个单独的答案 - 我认为在我研究新答案时,两个相关的问题被合并了]
I think you need to interpret the output data as follows:
The magnitudes are therefore:
[Sorry about there being two separate answers from me now - I think two related questions got merged while I was working on the new answer]
变换中的每个条目代表样本中频率的(复数)幅度。
给定频率下的功率密度只是该频率下变换的复振幅的大小。复数的大小是根据其分量计算的,获得此值应该不会有问题。
每一列表示频率增加的幅度,从 0(第一个条目)开始,然后是 2 Pi/T(其中 T 是复数的长度)样本),直到最后一个样本 2*Pi*N /T(其中 N 是样本数)
,还有其他约定,其中返回 -Pi * N /T 频率直至 Pi * N / T 的变换,并且0 频率分量位于阵列的中间
希望这有帮助
Each entry in the transform represent the (complex) magnitude of the frequency in the sample.
the power density in a given frequency is just the magnitude of the complex amplitude of the transform in that frequency. the magnitude of a complex number is computed from its components and you should not have a problem obtaining this
Each column represents amplitudes for increasing frequencies, starting from 0 (the first entry), then 2 Pi/T (where T is the length of your sample), until the last sample 2*Pi*N /T (where N is the number of samples)
there are other conventions where the transform is returned for the -Pi * N /T frequency up to Pi * N / T, and the 0 frequency component is in the middle of the array
hope this helps
要获得 bin k 的幅度,您需要计算 sqrt(re * re + im * im),其中 re、im 是 bin k 的 FFT 输出中的实部和虚部。
对于您的特定 FFT
re[k] = a[2*k]
和im[k] = a[2*k+1]
。因此计算功率谱:To get the magnitude of bin k you need to calculate sqrt(re * re + im * im), wheer re, im are the real and imaginary components in the FFT output for bin k.
For your particular FFT
re[k] = a[2*k]
andim[k] = a[2*k+1]
. Therefore to calculate the power spectrum: