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

本文介绍如何使用C++实现基于2的幂次的任意点数快速傅里叶变换(FFT)和逆快速傅里叶变换(IFFT)。通过修改主函数中的点数N和长度length(等于log2(N)),可以灵活调整变换的点数。复数类的定义和相关运算符的重载是实现关键,包括复数的加减乘除、输出以及赋值操作。
摘要由CSDN通过智能技术生成

    函数说明:更改主函数体中的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<<real<<"+"<<image<<"j"<<"   ";
		else
			cout<<real<<image<<"j"<<"   ";
	}
	void setvalue(double i=0,double j=0)
	{
		real=abs(i)<0.0001?0:i;
		image=abs(j)<0.0001?0:j;
	}
	complex operator +(complex&);
	complex operator-(complex&);
	complex operator*(complex&);
	complex operator /(int n);
	void operator+=(complex&);
	void operator =(complex&);
	friend complex W(int m,int n, int flag);
};
complex complex::operator +(complex& c)
	{
		complex t;
		t.real=real+c.real;
		t.image=image
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值