码迷,mamicode.com
首页 > 其他好文 > 详细

负数,傅里叶变换,反傅里叶变换(错)

时间:2018-12-31 22:38:01      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:stdio.h   img   bubuko   for   war   erro   傅里叶变换   undle   size   

#include <QCoreApplication>
#include "C:\Users\Administrator\Desktop\fftw\fftw-3.3.4-dll32\fftw3.h"
#include "D:\Qt\Eigen\Dense"
#include <stdio.h>
#include <iostream>
#include <complex>

using namespace std;
//  using namespace fftw_complex;
#define N 3

class MyComplex:public complex<double>
{
public:
    MyComplex():complex<double>(0.0, 0.0){m_r=0.0;m_i=0.0;}
    MyComplex(double r, double i):complex<double>(r,i){m_r=r;m_i=i;}
    double getR(){return m_r;}
    double getI(){return m_i;}
private:
    double m_r;
    double m_i;
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    //complex<float> www=(1,5);
    MyComplex www(2,4);
    std::cout<<www<<std::endl;
    std::cout<<www.getR()<<std::endl;
    std::cout<<www.getI()<<std::endl;

    int i;
    fftw_complex *in, *out, *result;
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N * N);
    result = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N * N);
    if (in == NULL || out == NULL)
    {
        printf("ERROR!");
    }
    else
    {
        //for (i=0; i<N*N; i++)
        {
            in[0][0] = 0;     in[0][1] = 0;
            in[1][0] = 1;     in[1][1] = 0;
            in[2][0] = 2;     in[2][1] = 0;
            in[3][0] = 2;     in[3][1] = 0;
            in[4][0] = 3;     in[4][1] = 0;
            in[5][0] = 4;     in[5][1] = 0;
            in[6][0] = 3;     in[6][1] = 0;
            in[7][0] = 2;     in[7][1] = 0;
            in[8][0] = 1;     in[8][1] = 0;
        }
    }
    for (i=0; i<N*N; i++)
    {
        printf("%.6f, %.6fi     ", in[i][0], in[i][1]);
        if(i==2||i==5||i==8)printf("\n");
    }

    cout << endl;
    fftw_plan p = fftw_plan_dft_2d(N, N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_execute(p);
    for (i=0; i<N*N; i++)
    {
        printf("%.6f, %.6fi     ", out[i][0], out[i][1]);
        if(i==2||i==5||i==8)printf("\n");
    }


//    cout << endl;
//    fftw_plan pp = fftw_plan_dft_2d(N, N, out, result, FFTW_BACKWARD, FFTW_ESTIMATE);
//    fftw_execute(pp);
//    for (i=0; i<N*N; i++)
//    {
//        printf("%.6f, %.6fi     ", result[i][0], result[i][1]);
//        if(i==2||i==5||i==8)printf("\n");
//    }
    fftw_destroy_plan(p);
    fftw_cleanup();
    if (in!=NULL)
        fftw_free(in);
    if (out!=NULL)
        fftw_free(out);
}
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
LIBS += -L"C:\Users\Administrator\Desktop\fftw\fftw-3.3.4-dll32"     -llibfftw3-3
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp

技术分享图片

负数,傅里叶变换,反傅里叶变换(错)

标签:stdio.h   img   bubuko   for   war   erro   傅里叶变换   undle   size   

原文地址:https://www.cnblogs.com/wangbin-heng/p/10203420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!