在PHP中计算FFT以获取数字数组 [英] Compute FFT in PHP for array of numbers

查看:114
本文介绍了在PHP中计算FFT以获取数字数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数字数组,显示在下面的代码中.我想做的是在数组中的每个数字上用PHP计算FFT.我在网络上遵循了一些示例

I have a set of array of numbers shown in the codes below. What I wanted to do is that to compute FFT in PHP on each number in the array. I followed some examples in the web http://www.phpclasses.org/package/6193-PHP-Compute-the-Fast-Fourier-Transform-of-sampled-data.html and http://www.jasonbailey.net/stuff/php-fast-fourier-transform-fft-brighton-php-october-2013/ as part of my FFT computation codes.

    $result_data = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);

    for ($index = 0; $index < $arrayCount; $index++)
    {   
            $nfft = 256; // n point FFT

            // initiate FFT
            $fft = new FFT($nfft);
            // Calculate the FFT of the function $f
            $w = $fft->fft($result_data);
            $power = $fft->getAbsFFT($w); //ABS value of real and complex data

            echo json_encode($power);
            echo ("\n");
        }       

    }   

但是它向我返回了下面的数字块,这些数字块似乎重复了20次.有人知道如何解决这个问题吗?

But it returns me the following block of numbers that seemed to be repeated 20 times. Anyone knows how to solve this?

[210,208.53525574236,204.18989508213,197.10896668339,187.52910862495,175.77129358889,162.23150701411,147.3702286466,131.70187234164,115.78556186989,100.21844753863,85.631056295302,72.677748658381,61.998470581045,54.103020393308,49.148739721174,46.740037447983,46.012499351762,45.994703056701,45.92155254764,45.333151076301,44.039448549754,42.052284866333,39.525751338284,36.709391389415,33.906333247199,31.424750102821,29.513942535491,28.29366310998,27.7131610516,27.576916611977,27.6253720222,27.618541561269,27.386265448914,26.844382258082,25.99086533894,24.892934386868,23.669400662346,22.46779309482,21.434317125714,20.678014755774,20.239047255644,20.077463933306,20.091065003015,20.15230314329,20.144810323036,19.987323887149,19.643895245903,19.124273021326,18.477928096736,17.783092203984,17.130707467578,16.603640507275,16.254692449065,16.091219222815,16.074353807967,16.133714979787,16.189832387664,16.174592641358,16.044515093534,15.786512758993,15.417729244569,14.980757544263,14.534680096924,14.142135623731,13.853829187667,13.694445050864,13.655658992898,13.69986932928,13.772808720243,13.819111934091,13.795344425854,13.678051366229,13.466834348967,13.183232698382,12.865933801679,12.562524220338,12.318385729813,12.164783192548,12.10994731181,12.137035762934,12.2100245488,12.284706160539,12.320296086784,12.288354057811,12.177842128102,11.996445141301,11.768549806494,11.530104072448,11.320631072721,11.173436386132,11.10644553079,11.117041385459,11.183244299697,11.270684904022,11.342295041292,11.367328711198,11.327706227833,11.221132399844,11.061124138288,10.87413792719,10.693937046176,10.553691043927,10.47728962383,10.472517527795,10.528852113515,10.620900961901,10.715911149236,10.782373459958,10.797208691204,10.750328899821,10.646342223011,10.503496734715,10.349943817846,10.217518662194,10.13386179962,10.114800937014,10.159682185456,10.251666138297,10.362853752103,10.462042810414,10.522413342999,10.527325386443,10.473531752002,10.371721260981,10.244426297884,10.121338391339,10.032409410072,10,10.032409410072,10.121338391339,10.244426297884,10.371721260981,10.473531752002,10.527325386443,10.522413342999,10.462042810414,10.362853752103,10.251666138297,10.159682185456,10.114800937014,10.13386179962,10.217518662194,10.349943817846,10.503496734715,10.646342223011,10.75032889982,10.797208691204,10.782373459958,10.715911149236,10.620900961901,10.528852113515,10.472517527795,10.47728962383,10.553691043927,10.693937046176,10.87413792719,11.061124138288,11.221132399844,11.327706227834,11.367328711198,11.342295041291,11.270684904022,11.183244299697,11.117041385459,11.10644553079,11.173436386132,11.320631072721,11.530104072448,11.768549806494,11.996445141301,12.177842128102,12.288354057811,12.320296086784,12.284706160539,12.2100245488,12.137035762934,12.10994731181,12.164783192548,12.318385729813,12.562524220338,12.865933801679,13.183232698382,13.466834348967,13.678051366229,13.795344425854,13.819111934091,13.772808720243,13.69986932928,13.655658992898,13.694445050864,13.853829187667,14.142135623731,14.534680096924,14.980757544263,15.417729244569,15.786512758993,16.044515093534,16.174592641358,16.189832387664,16.133714979787,16.074353807967,16.091219222815,16.254692449065,16.603640507275,17.130707467578,17.783092203984,18.477928096736,19.124273021326,19.643895245903,19.987323887149,20.144810323036,20.15230314329,20.091065003015,20.077463933306,20.239047255643,20.678014755773,21.434317125714,22.46779309482,23.669400662346,24.892934386868,25.990865338941,26.844382258082,27.386265448915,27.61854156127,27.6253720222,27.576916611977,27.7131610516,28.29366310998,29.513942535491,31.424750102821,33.906333247199,36.709391389415,39.525751338284,42.052284866333,44.039448549755,45.333151076301,45.921552547641,45.994703056702,46.012499351763,46.740037447984,49.148739721174,54.103020393308,61.998470581045,72.677748658382,85.631056295303,100.21844753863,115.7855618699,131.70187234164,147.3702286466,162.23150701411,175.77129358889,187.52910862495,197.1089666834,204.18989508213,208.53525574236]
[210,208.53525574236,204.18989508213,197.10896668339,187.52910862495,175.77129358889,162.23150701411,147.3702286466,131.70187234164,115.78556186989,100.21844753863,85.631056295302,72.677748658381,61.998470581045,54.103020393308,49.148739721174,46.740037447983,46.012499351762,45.994703056701,45.92155254764,45.333151076301,44.039448549754,42.052284866333,39.525751338284,36.709391389415,33.906333247199,31.424750102821,29.513942535491,28.29366310998,27.7131610516,27.576916611977,27.6253720222,27.618541561269,27.386265448914,26.844382258082,25.99086533894,24.892934386868,23.669400662346,22.46779309482,21.434317125714,20.678014755774,20.239047255644,20.077463933306,20.091065003015,20.15230314329,20.144810323036,19.987323887149,19.643895245903,19.124273021326,18.477928096736,17.783092203984,17.130707467578,16.603640507275,16.254692449065,16.091219222815,16.074353807967,16.133714979787,16.189832387664,16.174592641358,16.044515093534,15.786512758993,15.417729244569,14.980757544263,14.534680096924,14.142135623731,13.853829187667,13.694445050864,13.655658992898,13.69986932928,13.772808720243,13.819111934091,13.795344425854,13.678051366229,13.466834348967,13.183232698382,12.865933801679,12.562524220338,12.318385729813,12.164783192548,12.10994731181,12.137035762934,12.2100245488,12.284706160539,12.320296086784,12.288354057811,12.177842128102,11.996445141301,11.768549806494,11.530104072448,11.320631072721,11.173436386132,11.10644553079,11.117041385459,11.183244299697,11.270684904022,11.342295041292,11.367328711198,11.327706227833,11.221132399844,11.061124138288,10.87413792719,10.693937046176,10.553691043927,10.47728962383,10.472517527795,10.528852113515,10.620900961901,10.715911149236,10.782373459958,10.797208691204,10.750328899821,10.646342223011,10.503496734715,10.349943817846,10.217518662194,10.13386179962,10.114800937014,10.159682185456,10.251666138297,10.362853752103,10.462042810414,10.522413342999,10.527325386443,10.473531752002,10.371721260981,10.244426297884,10.121338391339,10.032409410072,10,10.032409410072,10.121338391339,10.244426297884,10.371721260981,10.473531752002,10.527325386443,10.522413342999,10.462042810414,10.362853752103,10.251666138297,10.159682185456,10.114800937014,10.13386179962,10.217518662194,10.349943817846,10.503496734715,10.646342223011,10.75032889982,10.797208691204,10.782373459958,10.715911149236,10.620900961901,10.528852113515,10.472517527795,10.47728962383,10.553691043927,10.693937046176,10.87413792719,11.061124138288,11.221132399844,11.327706227834,11.367328711198,11.342295041291,11.270684904022,11.183244299697,11.117041385459,11.10644553079,11.173436386132,11.320631072721,11.530104072448,11.768549806494,11.996445141301,12.177842128102,12.288354057811,12.320296086784,12.284706160539,12.2100245488,12.137035762934,12.10994731181,12.164783192548,12.318385729813,12.562524220338,12.865933801679,13.183232698382,13.466834348967,13.678051366229,13.795344425854,13.819111934091,13.772808720243,13.69986932928,13.655658992898,13.694445050864,13.853829187667,14.142135623731,14.534680096924,14.980757544263,15.417729244569,15.786512758993,16.044515093534,16.174592641358,16.189832387664,16.133714979787,16.074353807967,16.091219222815,16.254692449065,16.603640507275,17.130707467578,17.783092203984,18.477928096736,19.124273021326,19.643895245903,19.987323887149,20.144810323036,20.15230314329,20.091065003015,20.077463933306,20.239047255643,20.678014755773,21.434317125714,22.46779309482,23.669400662346,24.892934386868,25.990865338941,26.844382258082,27.386265448915,27.61854156127,27.6253720222,27.576916611977,27.7131610516,28.29366310998,29.513942535491,31.424750102821,33.906333247199,36.709391389415,39.525751338284,42.052284866333,44.039448549755,45.333151076301,45.921552547641,45.994703056702,46.012499351763,46.740037447984,49.148739721174,54.103020393308,61.998470581045,72.677748658382,85.631056295303,100.21844753863,115.7855618699,131.70187234164,147.3702286466,162.23150701411,175.77129358889,187.52910862495,197.1089666834,204.18989508213,208.53525574236]
 ....
 ....

推荐答案

您不使用$index.

$w = $fft->fft($result_data);

应替换为:

$w = $fft->fft($result_data[$index]);

这篇关于在PHP中计算FFT以获取数字数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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