⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 C++实现的FFT
💻 CPP
字号:
#include <iostream>
//#include <vector>
//文件IO所需头文件
#include <fstream>
//复数所需头文件
#include <complex>
//MyFFT(...)函数所需头文件
#include "My_FFT.h"

//数组大小
#define LSIZE 16

//使用全命名空间(不推荐使用)
using namespace std;

//标准mian函数
int main ( int argc , char** argv)
{
	//新建数组
	//dComplex即complex<double>(这里使用了define)
	dComplex* Result = new dComplex[LSIZE];
	dComplex* OtherResult = new dComplex[LSIZE];
	dComplex* Input = new dComplex[LSIZE];

	//新建i文件流
	ifstream inFile("input.txt");
	
	//循环将数据读入数组
	int i = 0;
	while(inFile.good())
	{
		double tempReal = 0.0;
		double tempImag = 0.0;
		inFile >> tempReal;
		inFile >> tempImag;
		
		//使用默认的构造函数
		dComplex tempCom(tempReal, tempImag);
		//赋值
		Input[i++] = tempCom;
	}

	//关闭I文件流
	inFile.close();

	//新建o文件流
	ofstream outFile("output.txt");
	//格式化输出
	outFile << "i" << '\t' << '\t' <<"real" << '\t' << '\t' << "imag" << '\n';

	//提示
	cout << "FFT ing..." << endl;

	outFile << "FFT" << '\n' << '\n';

	//FFT
	MyFFT(Result,Input,LSIZE,0);
	//循环格式化输出
	for ( int j = 0 ; j < LSIZE ; j++ )
	{
		outFile << j+1 << '\t' << '\t' << Result[j].real() << '\t' << '\t' << Result[j].imag() << '\n';
	}
	
	
	outFile << '\n' << "IFFT" << '\n' << '\n';

	//提示
	cout << "IFFT ing..." << endl;

	//IFFT
	MyFFT(OtherResult,Result,LSIZE,1);
	//循环格式化输出
	for ( int j = 0 ; j < LSIZE ; j++ )
	{
		outFile << j+1 << '\t' << '\t' << OtherResult[j].real() << '\t' << '\t' << OtherResult[j].imag() << '\n';
	}

	//关闭o文件流
	outFile.close();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -