欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
快速傅里葉變換C++遞歸算法實(shí)現

  Fouier.h文件:


#pragma once
#include"Complex.h"
class Fouier
{
    Complex * data;
    void fft(int start,int step,int len);
    Complex W(int k,int n);//e^(-i*2*pi*k/n)
public:
    Fouier(void);
    ~Fouier(void);
    
    void fft();
};

    Fouier.c文件:


#include "Fouier.h"
#include<iostream>
using namespace std;
#include<cmath>
#include<ctime>
#define DATALEN 32
#define KEYVALUE 10000 //生成隨機浮點(diǎn)數的值,保證分子和分母在這個(gè)值之內
#define PI 3.14159265358979323846
Fouier::Fouier(void)
{
    data=new Complex[DATALEN];
    srand(unsigned int(time(0)));
    cout<<"源數據:"<<endl;
    for(int i=0;i<DATALEN;i++)
    {
        data[i]=(rand()%(KEYVALUE))/(double)(rand()%(KEYVALUE)+1);
        if(i%5==0&&i!=0)
            cout<<endl;
        cout<<data[i]<<" ";
    }
    cout<<endl;
}


Fouier::~Fouier(void)
{
    delete [] data;
}
Complex Fouier:: W(int k,int n)//歐拉公式
{
    double alpha=-2*PI*k/n;
    return Complex(cos(alpha),sin(alpha));
}
void Fouier::fft(int start,int step,int len)
{
    if(len==1)//一個(gè)元素
    {
        //一個(gè)元素不需要變換
        return ;
    }
    fft(start,step*2,len/2);//X1(k)
    fft(start+step,step*2,len/2);//X2(k)
    Complex X1,X2;
    for(int i=0;i<len/2;i++)
    {
        X1=data[start+step*i*2];
        X2=data[start+step*(i*2+1)];
        //計算X(k):k=0~N/2-1
        data[start+step*i]=X1+W(i,len)*X2;
        //計算X(k):k=N/2~N-1
        data[start+step*(i+len/2)]=X1-W(i,len)*X2;
    }
}
void Fouier::fft()
{
    fft(0,1,DATALEN);
    cout<<"變換后數據:"<<endl;
    for(int i=0;i<DATALEN;i++)
    {
        if(i%5==0&&i!=0)
            cout<<endl;
        cout<<data[i]<<" ";
    }
}

  Complex.h文件:


#pragma once
#include<iostream>
using namespace std;
class Complex//a+b*i
{
    double a;//實(shí)數部分
    double b;//虛數部分
public:
    Complex(double a=0,double b=0);
    //+操作
    friend Complex operator +(Complex &x,Complex &y);
    friend Complex operator +(double x,Complex &y);
    friend Complex operator +(Complex &x,double y);
    //-操作
    friend Complex operator -(Complex &x,Complex &y);
    friend Complex operator -(double x,Complex &y);
    friend Complex operator -(Complex &x,double y);
    //*操作
    friend Complex operator *(Complex &x,Complex &y);
    friend Complex operator *(double x,Complex &y);
    friend Complex operator *(Complex &x,double y);
    //=操作
    Complex operator =(Complex &x);
    Complex operator =(double x);
    //<<操作
    friend ostream & operator<<(ostream&out,Complex&c);

    ~Complex(void);
};

    Complex.c文件:


#include "Complex.h"

Complex::Complex(double a,double b)//虛部默認是0
{
    this->a=a;
    this->b=b;
}


Complex::~Complex(void)
{
}

Complex operator +(Complex &x,Complex &y)
{
    return Complex(x.a+y.a,x.b+y.b);
}
Complex operator +(double x,Complex &y)
{
    return Complex(x+y.a,y.b);
}
Complex operator +(Complex &x,double y)
{
    return Complex(x.a+y,x.b);
}

Complex operator -(Complex &x,Complex &y)
{
    return Complex(x.a-y.a,x.b-y.b);
}
Complex operator -(double x,Complex &y)
{
    return Complex(x-y.a,-y.b);
}
Complex operator -(Complex &x,double y)
{
    return Complex(x.a-y,x.b);
}

Complex operator *(Complex &x,Complex &y)
{
    return Complex(x.a*y.a-x.b*y.b,x.a*y.b+x.b*y.a);
}
Complex operator *(double x,Complex &y)
{
    return Complex(x*y.a,x*y.b);
}
Complex operator *(Complex &x,double y)
{
    return Complex(x.a*y,x.b*y);
}

Complex Complex::operator =(Complex &x)
{
    a=x.a;
    b=x.b;
    return *this;
}
Complex Complex::operator =(double x)
{
    a=x;
    b=0;
    return *this;
}
ostream & operator<<(ostream&out,Complex&c)
{
    if(c.a!=0||c.a==0&&c.b==0)
        out<<c.a;
    if(c.b!=0)
    {
        if(c.b>0)
            out<<"+";
        if(c.b!=1)
            out<<c.b;
        out<<"i";
    }
    return out;
}

    main.c文件:


#include<iostream>
using namespace std;
#include"Fouier.h"

int main()
{
    Fouier f;
    f.fft();
    return 0;
}
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
double_operator.cpp
運算符重載
C++之運算符重載(1)
函數返回值是否使用引用類(lèi)型的問(wèn)題:理解引用、返回值
從一維到二維,C 復數運算總結
在c中重載流提取操作符
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久