Kiss FFT:逆向2D变换后跟正向变换会产生错误的结果

时间:2019-06-10 17:29:07

标签: fft kissfft

下面的代码对4x4频率数组(设置为谐波数)进行逆2D FFT,然后对结果进行正向FFT。按比例缩小结果,它应等于原始频率。其中一些确实匹配,但其中一些明显不同。我在做什么错了?

class MainScaffold extends StatefulWidget {
  @override
  _MainScaffoldState createState() => _MainScaffoldState();
}

class _MainScaffoldState extends State<MainScaffold> with SingleTickerProviderStateMixin {
  TabController tabController;

  /// Just for the example
  ActiveProductModel activeProductModel = ActiveProductModel();

  @override
  void initState() {
    // Initiate the tabController
    tabController = TabController(vsync: this, length: 3);

    activeProductModel.addListener(() {
       if (mounted)
         /// Here you can do whatever you want, just going to page 2 for the example.
         tabController.animateTo(2);
    });

    super.initState();
  }

  @override
  void dispose() {
    tabController.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: TabBarView(
        controller: tabController,
        children: <Widget>[
          Text("hello! abc"),
          Text("hello! sdsadsa"),
          Text("hello! 231321"),
        ],
      ),
    );
  }
}

输出为

#include <stdio.h>
#include "kiss_fftndr.h"

// function to print FFT output
void print_freq(kiss_fft_cpx* in, int n0, int n1){

    printf("\n");
    for(int y = 0; y < n0; y++){
        for(int x = 0; x < n1; x++){
            printf(" (%f, %f) ", in[y*n1+x].r, in[y*n1+x].i);
        }
        printf("\n");
    }
}

int main(){

    int dims[2] = {4,4};
    kiss_fftndr_cfg f_cfg = kiss_fftndr_alloc(dims, 2, 0, NULL, NULL);
    kiss_fftndr_cfg i_cfg = kiss_fftndr_alloc(dims, 2, 1, NULL, NULL);

    float signal[16];
    kiss_fft_cpx freq[12];

    for(int i = 0; i < 12; i++){
        freq[i].r = 1.0/(i+1);
        freq[i].i = 0.0;
    }

    printf("Before:\n");
    print_freq(freq, 4, 3);

    // inverse transform followed by transform
    kiss_fftndri(i_cfg, freq, signal);
    kiss_fftndr(f_cfg, signal, freq);

    // renormalize
    for(int i = 0; i < 12; i++){
        freq[i].r /= 16.0;
        freq[i].i /= 16.0;
    }

    printf("\nAfter:\n");
    print_freq(freq, 4, 3);
}

0 个答案:

没有答案