关于FFTW3 fftw_plan_dft_r2c_2d输出

时间:2018-10-25 07:29:07

标签: 2d fftw dft

我正在使用FFTW3库获取2D数组的DFT。与开放式CV DFT输出相比,我面临的问题是输出面临的差异。这是我使用FFTW3库使用的代码。

int main()
{
    int i;

    int j;
    int nx = 24;
    int ny = 24;
    int nyh;
    fftw_complex *out;

    fftw_plan plan_forward;


    double array[24][24] = { { 228, 225.9631653,    226.5006409,    229.0000153,    227.9999847,    228,    229,    230.0000153,    229.9999847,    230,    230,    230.9211731,    151.9324799,    82.85941315,    63.72341156,    83.98603058,    103.0576096,    113.7489166,    108.9631729,    106.9631653,    110.72612,  0,  0,   0 },
    { 228, 227, 228, 228, 229.9999847412109, 229, 230, 230.9999847412109, 231, 232, 232, 230.6470489501953, 90.30031585693359, 77.18020629882813, 92.95713043212891, 103.3548355102539, 119.7345275878906, 118.7857360839844, 112.5069274902344, 116.7649230957031, 130.2093811035156, 0, 0, 0 },
    { 229, 226.1988220214844, 226, 228.1717224121094, 230.0000152587891, 230.8751220703125, 231, 231.1988220214844, 231.1988220214844, 227.8264312744141, 234.1071472167969, 227.4921264648438, 69.67898559570313, 77.37232971191406, 92.71088409423828, 123.7904357910156, 129.0333862304688, 114.5575866699219, 114.5450973510742, 93.75933074951172, 119.8855133056641, 0, 0, 0 },
    { 218.6332702636719, 216.8977966308594, 219.0265350341797, 221.4499053955078, 223.4499053955078, 223.4499053955078, 221.6332550048828, 220.8423461914063, 221.2658538818359, 127.2683563232422, 134.3556365966797, 195.9505157470703, 67.68015289306641, 47.73678207397461, 114.9389877319336, 128.3674011230469, 126.5191040039063, 83.31300354003906, 66.71846008300781, 69.90415954589844, 66.81472015380859, 0, 0, 0 },
    { 204.868896484375, 204.9682922363281, 209.4344635009766, 210.868896484375, 210.1642761230469, 207.6752624511719, 207.4344635009766, 208.7610778808594, 178.4485473632813, 101.5294799804688, 85.89687347412109, 101.8148193359375, 84.56836700439453, 87.0897216796875, 124.3299102783203, 120.269889831543, 108.7416687011719, 75.86738586425781, 43.86585235595703, 42.20047760009766, 38.1141357421875, 0, 0, 0 },
    { 200, 202.0993957519531, 207.027099609375, 202.0593872070313, 195.8586273193359, 193.1045532226563, 191.2608184814453, 193.4969482421875, 144.0751647949219, 118.3891067504883, 107.0893707275391, 100.2089004516602, 88.18731689453125, 79.69484710693359, 127.4902648925781, 121.2930755615234, 117.0175552368164, 66.00584411621094, 58.14738464355469, 93.51354217529297, 80.06235504150391, 0, 0, 0 },
    { 202.3299102783203, 205.0993957519531, 206.1710510253906, 197.8513031005859, 185.9294738769531, 179.083984375, 168.9931182861328, 170.7659759521484, 148.5190734863281, 111.1565628051758, 123.8586273193359, 92.45366668701172, 87.59461975097656, 82.62408447265625, 129.8645629882813, 119.4688110351563, 93.39018249511719, 79.18632507324219, 74.29071807861328, 73.31881713867188, 81.46488189697266, 0, 0, 0 },
    { 211.6306762695313, 212.4527740478516, 209.5184326171875, 197.8483428955078, 183.5081634521484, 167.9563598632813, 152.8710632324219, 155.0436859130859, 152.2613830566406, 109.8752136230469, 137.6752624511719, 96.71597290039063, 80.64554595947266, 113.3730010986328, 129.1329650878906, 105.2225189208984, 84.58676147460938, 68.12571716308594, 26.71034622192383, 22.62581634521484, 6.504122734069824, 0, 0, 0 },
    { 216.3667755126953, 217, 210.5184326171875, 199.1362609863281, 184.2622375488281, 165.3719024658203, 153.1045532226563, 154.619384765625, 143.5562591552734, 130.773681640625, 149.299072265625, 122.6694641113281, 107.4041519165039, 125.2531433105469, 126.7354888916016, 99.12162780761719, 77.36798095703125, 62.61947631835938, 46.0507698059082, 54.52013397216797, 55.01191711425781, 0, 0, 0 },
    { 210.2878723144531, 212.0000152587891, 207.7949829101563, 197.1362609863281, 181.426513671875, 166.6791687011719, 152.9582824707031, 162.3196105957031, 138.9593048095703, 153.1326141357422, 129.0850372314453, 101.1606597900391, 93.55055236816406, 133.7596435546875, 132.6110992431641, 118.3563232421875, 107.8467864990234, 93.84966278076172, 80.805419921875, 74.59872436523438, 93.96941375732422, 0, 0, 0 },
    { 204.8585815429688, 206.099365234375, 204.1413726806641, 199.994873046875, 189.2601776123047, 181.0891418457031, 173.2725830078125, 174.1761322021484, 135.7809753417969, 152.0060119628906, 114.3461151123047, 88.03327178955078, 113.6788024902344, 133.8586273193359, 131.2054443359375, 127.5534591674805, 128.458251953125, 127.6992645263672, 105.2247467041016, 76.65969085693359, 73.62815093994141, 0, 0, 0 },
    { 205, 204.0993804931641, 208, 206.4815979003906, 199.0540924072266, 197.722412109375, 196.7199249267578, 197.1406097412109, 132.4895324707031, 143.9039459228516, 105.0517959594727, 91.59484100341797, 117.1388168334961, 134.9822235107422, 125.1935501098633, 128.7678985595703, 138.2003631591797, 138.3784332275391, 128.251953125, 124.1878051757813, 126.6193466186523, 0, 0, 0 },
    { 208.6229858398438, 208.0993804931641, 211.9230041503906, 214.2459716796875, 212.1532592773438, 211.4776611328125, 208.2459716796875, 209.2320098876953, 131.4188385009766, 131.4317779541016, 98.71723937988281, 88.91685485839844, 116.3848037719727, 118.7540283203125, 108.0343399047852, 125.0651550292969, 128.9365692138672, 142.0699920654297, 142.6689605712891, 141.1951751708984, 138.3932189941406, 0, 0, 0 },
    { 220.0103149414063, 220.0103302001953, 221.0051727294922, 223.8689117431641, 227.0116119384766, 225.0051727294922, 223.0051727294922, 222.0206756591797, 131.902587890625, 130.3474578857422, 135.5620422363281, 98.10881805419922, 117.2134552001953, 115.2336196899414, 99.79096984863281, 96.57593536376953, 120.1604080200195, 139.4130096435547, 152.5933532714844, 148.0103302001953, 143.2802581787109, 0, 0, 0 },
    { 229.1620483398438, 229.5493927001953, 229.1620483398438, 230.3873596191406, 234.2253112792969, 232.0025329589844, 232, 232.1033782958984, 135.4168395996094, 113.3188629150391, 135.4292602539063, 93.73445892333984, 105.2431869506836, 94.83783721923828, 89.38047790527344, 104.3125152587891, 126.10302734375, 131.3762969970703, 136.3644409179688, 153.9777526855469, 153.4420928955078, 0, 0, 0 },
    { 231, 229.23046875, 231, 231, 231, 231, 229.2304840087891, 229.4455413818359, 151.8515472412109, 144.8070373535156, 129.8264923095703, 86.47013854980469, 92.91008758544922, 92.09573364257813, 86.26690673828125, 102.4905700683594, 109.1489562988281, 127.9508514404297, 126.8159484863281, 144.1071472167969, 142.8967437744141, 0, 0, 0 },
    { 229, 229.0000152587891, 227.8482818603516, 227.8482971191406, 229, 227.8482971191406, 226.8482971191406, 229.8156585693359, 148.6229248046875, 138.6812438964844, 115.3771133422852, 86.84798431396484, 70.56075286865234, 77.927001953125, 73.79084014892578, 80.77005767822266, 94.87143707275391, 114.3271560668945, 123.5233001708984, 116.3697128295898, 112.9974594116211, 0, 0, 0 },
    { 228, 227, 227, 227, 227, 226, 225, 222.8015747070313, 134.0615692138672, 128.9269104003906, 100.3426742553711, 105.1386108398438, 69.01123046875, 77.64430236816406, 80.12620544433594, 90.58251953125, 91.08965301513672, 100.4503860473633, 105.9778671264648, 110.8943405151367, 105.3174743652344, 0, 0, 0 },
    { 227.0000152587891, 227, 227, 227, 227.0000152587891, 224, 222, 220.6914672851563, 206.6996154785156, 150.7881622314453, 116.0428924560547, 100.1986083984375, 59.56113815307617, 71.75279235839844, 76.78220367431641, 74.99972534179688, 73.69229888916016, 98.76775360107422, 98.41807556152344, 98.4180908203125, 103.8507537841797, 0, 0, 0 },
    { 227, 224.2982788085938, 224, 224, 223.9266510009766, 221.5144195556641, 218.7017517089844, 214.5928955078125, 217.5579223632813, 206.4084320068359, 103.6927490234375, 118.4897308349609, 54.65142440795898, 77.71870422363281, 78.09490203857422, 76.04106903076172, 91.35556030273438, 96.2769775390625, 50.42835235595703, 56.3187255859375, 86.85477447509766, 0, 0, 0 },
    { 224.319580078125, 223.319580078125, 221.9999847412109, 222, 221.2409820556641, 218.1188354492188, 216.9897308349609, 209.8445434570313, 183.3976135253906, 127.3233489990234, 74.70269775390625, 101.8262176513672, 57.21710205078125, 65.06453704833984, 73.40766906738281, 91.81818389892578, 88.33279418945313, 52.33296585083008, 46.03059768676758, 44.02536773681641, 58.63919830322266, 0, 0, 0 },
    {0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0},
    {0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0},
    {0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   0 } };



    out = fftw_malloc(sizeof(fftw_complex) * nx * ny);

    plan_forward = fftw_plan_dft_r2c_2d(nx, ny, array, out, FFTW_ESTIMATE);

    fftw_execute(plan_forward);

    for (i = 0; i < nx; i++)
    {
        for (j = 0; j < ny; j++)
        {
            printf("  %4d  %4d  %24f  %24f \n",
                i, j, out[i*ny + j][0], out[i*ny + j][1]);
        }
    }


    fftw_destroy_plan(plan_forward);



    fftw_free(out);

    getch();
    return;




}

相同输入的OPEN CV DFT的初始输出是这样的[66353.1229391098 2192.233012 -17811.22824 -4372.646447 -10210.01061 2646.278929 -7102.745821 2908.691138 -5636.270418 ...]并已完全填充。同时,相同输入的FFTW3的输出是这样的[66353.122939 0.000000 2192.233012 -17811.228243 -4372.646447 -10210.010612 2646.278929 -7102.745821 2908.691138 -5636.270418 ...]这是半填充的,表示填充到i = 0到12,然后从i = 13到24,则为零。从输出中可以看出,第一个元素后有 0.000000 ,这在OPEN CV输出中并不明显。我在这里做错什么了。

PS:我确实知道经过r2c转换后,输出是按行大顺序排列的fftw_complex值的n0×n1×n2×…×(nd-1 / 2 + 1)个数组。 FFTW3输出相同。

0 个答案:

没有答案