基于C++任意点数的FFT/IFFT(时域和频域)实现

    函数说明:更改主函数体中的N和length(=log2(N))既可以实现任意点数(2的幂次)的FFT/ IFFT的实现,fft函数中flag标志位控制是正变换还是逆变换。


1.复数操作类

     定义复数类,重载复数四则运算符号,重载输出运算符,重载赋值运算符。

/**********预编译文件头文件complex.h********/
#include"iostream"
using namespace std;
class complex
{
	double real,image;
public:
	complex(){real=0;image=0;}
	complex(float i,float j){real=i;image=j;}
	double getr(){return real;}
	double geti(){return image;}
	void show()
	{
		if(image>=0)
			cout<


2.主函数

/*******************主函数体***********************/
#include "stdafx.h"
#include"iostream"
#include"cmath"
#include"complex.h"
#define pi 3.141592657
#define N 16//需要运算的fft的点数
#define length 4//存储需要的二进制位,即length=log2(N)
using namespace std;
/*********************重新排列输入序列函数****************************/
void bit_reversal(complex a[],int n)
{
	int bitdesicion(unsigned);//用来重现排序原来的输入信号序列应该对应变换的信号的序号
	complex temp;
	int j;
	for(int i=0;i   void getW(complex w[],int len,int flag);//获得正变换(flag=1)或者逆变换系数(flag=0)
   void fft_temporal(complex input[],int len,int flag);//基时间的fft,flag控制为正变换或者逆变换
   void fft_frequency(complex input[],int len,int flag);//基频率的fft
/************************************************************/
   complex input[N];
   complex output[N];
   for(int i=0;i
      output[j]=input[j];
   fft_temporal(output,N,0);//"0"控制为逆变换
   cout<<"基2时域IFFT输出信号为:"<








转载于:https://www.cnblogs.com/engineerLF/p/5393172.html

你可能感兴趣的:(基于C++任意点数的FFT/IFFT(时域和频域)实现)