为 apache commons 快速傅立叶变换算法构建示例数据 [英] Build sample data for apache commons Fast Fourier Transform algorithm

查看:26
本文介绍了为 apache commons 快速傅立叶变换算法构建示例数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Apache math commons 实现 FFT(FastFourierTransformer 类)来处理一些虚拟数据,其中 8 个数据样本对一个完整的正弦波有贡献.最大幅度为 230.我尝试的代码片段如下:

I wanted to use Apache math commons implementation for FFT (FastFourierTransformer class) to process some dummy data whose 8 data samples are contributing to one complete sinusoidal wave. The maximum being amplitude 230. The code snippet that I tried is below :

private double[] transform() 
{   
    double [] input = new double[8];
    input[0] = 0.0;
    input[1] = 162.6345596729059;
    input[2] = 230.0;
    input[3] = 162.63455967290594;
    input[4] = 2.8166876380389125E-14;
    input[5] = -162.6345596729059;
    input[6] = -230.0;
    input[7] = -162.63455967290597;

    double[] tempConversion = new double[input.length];

    FastFourierTransformer transformer = new FastFourierTransformer();
    try {           
        Complex[] complx = transformer.transform(input);

        for (int i = 0; i < complx.length; i++) {               
            double rr = (complx[i].getReal());
            double ri = (complx[i].getImaginary());

            tempConversion[i] = Math.sqrt((rr * rr) + (ri * ri));
        }

    } catch (IllegalArgumentException e) {
        System.out.println(e);
    }

    return tempConversion;
}

1) 现在transform方法返回的数据是一个复数数组.该数组是否包含有关输入数据的频率分量信息?或者我创建的 tempConversion 数组将包含频率信息?tempConversion 数组中的值是:

1) Now the data returned by method transform is an array of complex number. Does that array contains the frequency component information about input data? or the tempConversion array that I created will contain the frequency information? The values in tempConversion array is :

 2.5483305001488234E-16
 920.0
 4.0014578493024757E-14
 2.2914314707516465E-13
 5.658858581079313E-14
 2.2914314707516465E-13
 4.0014578493024757E-14
 920.0

2) 我搜索了很多,但在大多数地方都没有关于数据算法期望什么格式的明确文档(在示例代码方面可以更好地理解)以及我如何使用结果数组来计算频率包含在信号中?

2) I searched a lot but at most of the places there is no clear documentation on what format of data algorithm expects (in terms of sample code to understand better) and how do I use the array of results to calculate the frequencies contained in the signal?

推荐答案

您的输出数据看起来正确.您已经计算了每个频率仓的复数 FFT 输出的幅度,这对应于该仓对应频率处的输入信号中的能量.由于您的输入是纯实数,因此输出是复共轭对称的,最后 3 个输出值是冗余的.

Your output data looks correct. You've calculated the magnitude of the complex FFT output at each frequency bin which corresponds to the energy in the input signal at the corresponding frequency for that bin. Since your input is purely real, the output is complex conjugate symmetric, and the last 3 output values are redundant.

所以你有:

Bin     Freq        Magnitude
  0     0 (DC)        2.5483305001488234E-16
  1     Fs/8        920.0
  2     Fs/4          4.0014578493024757E-14
  3     3Fs/8         2.2914314707516465E-13
  4     Fs/2 (Nyq)    5.658858581079313E-14
  5     3Fs/8         2.2914314707516465E-13  # redundant - mirror image of bin 3
  6     Fs/4          4.0014578493024757E-14  # redundant - mirror image of bin 2
  7     Fs/8        920.0                     # redundant - mirror image of bin 1

除了 bin 1(和 bin 6)之外,所有值实际上都是 0,这对应于预期的 Fs/8 频率.

All the values are effectively 0 apart from bin 1 (and bin 6) which corresponds to a frequency of Fs/8 as expected.

这篇关于为 apache commons 快速傅立叶变换算法构建示例数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆