zoukankan      html  css  js  c++  java
  • 负数,傅里叶变换,反傅里叶变换

    #include <QCoreApplication>
    #include "C:UsersAdministratorDesktopfftwfftw-3.3.4-dll32fftw3.h"
    #include "D:QtEigenDense"
    #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("
    ");
        }
    
        //傅里叶变换
        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("
    ");
        }
    
        //逆傅里叶变换
        cout << endl;
        fftw_plan pp = fftw_plan_dft_2d(N, N, in, result, FFTW_BACKWARD, FFTW_ESTIMATE);
        fftw_execute(pp);
        for (i=0; i<N*N; i++)
        {
            printf("%.6f, %.6fi     ", result[i][0]/(N*N), result[i][1]/(N*N));
            if(i==2||i==5||i==8)printf("
    ");
        }
    
    
        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:UsersAdministratorDesktopfftwfftw-3.3.4-dll32" 
        -llibfftw3-3
    DEFINES += QT_DEPRECATED_WARNINGS
    SOURCES += main.cpp

    #include<QCoreApplication>
    #include"C:UsersAdministratorDesktopfftwfftw-3.3.4-dll32fftw3.h"
    #include"D:QtEigenDense"
    #include<stdio.h>
    #include<iostream>
    #include<complex>
    
    
    usingnamespacestd;
    //usingnamespacefftw_complex;
    #defineN3
    
    
    classMyComplex:publiccomplex<double>
    {
    public:
    MyComplex():complex<double>(0.0,0.0){m_r=0.0;m_i=0.0;}
    MyComplex(doubler,doublei):complex<double>(r,i){m_r=r;m_i=i;}
    doublegetR(){returnm_r;}
    doublegetI(){returnm_i;}
    private:
    doublem_r;
    doublem_i;
    };
    
    
    intmain(intargc,char*argv[])
    {
    QCoreApplicationa(argc,argv);
    
    
    //complex<float>www=(1,5);
    MyComplexwww(2,4);
    std::cout<<www<<std::endl;
    std::cout<<www.getR()<<std::endl;
    std::cout<<www.getI()<<std::endl;
    
    
    inti;
    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("
    ");
    }
    
    
    //傅里叶变换
    cout<<endl;
    fftw_planp=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("
    ");
    }
    
    
    //逆傅里叶变换
    cout<<endl;
    fftw_planpp=fftw_plan_dft_2d(N,N,in,result,FFTW_BACKWARD,FFTW_ESTIMATE);
    fftw_execute(pp);
    for(i=0;i<N*N;i++)
    {
    printf("%.6f,%.6fi",result[i][0]/(N*N),result[i][1]/(N*N));
    if(i==2||i==5||i==8)printf("
    ");
    }
    
    
    
    
    fftw_destroy_plan(p);
    fftw_cleanup();
    if(in!=NULL)
    fftw_free(in);
    if(out!=NULL)
    fftw_free(out);
    }
    
    
  • 相关阅读:
    ruby安装方法
    移动端适配问题px->rem方法
    判断元素阶段类型
    domReady
    电梯导航
    判断浏览器的版本以及浏览器内核( 转发 )
    AWS
    Amazon S3
    Pipeline 模型
    RESTful API
  • 原文地址:https://www.cnblogs.com/wangbin-heng/p/10203420.html
Copyright © 2011-2022 走看看