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

📄 fft2d.cpp

📁 用于声音图像的FFC变换源码
💻 CPP
字号:
// FFT2D.cpp: implementation of the CFFT2D class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FFT2D.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFFT2D::CFFT2D(unsigned int x/* = 2 */, unsigned int y/* = 2*/)
{
	pInput = new CComplex*[x];
	for(unsigned int i = 0; i < x; i++)
		pInput[i] = new CComplex[y];

	nX = x;
	nY = y;
}

CFFT2D::~CFFT2D()
{
	if(pInput != NULL)
	{
		for(unsigned  int i = 0; i < nX; i++)
		{
			delete[] pInput[i];
			pInput[i] = NULL;
		}
		pInput = NULL;
	}
}

CComplex CFFT2D::GetInputAt(unsigned int x, unsigned int y)
{
	if(x >= 0 && x < nX && y >= 0 && y < nY)
		return pInput[x][y];
	else
	{
		#ifdef USE_MESSAGE_BOX_FOR_FAILURE		
			AfxMessageBox("Index out of range!");
		#endif
		return NULL;
	}
}

bool CFFT2D::SetInputAt(unsigned int x, unsigned int y, double real/* = 0 */, double imag/* = 0 */)
{
	if(x >= 0 && x < nX && y >= 0 && y < nY)
	{
		pInput[x][y].SetReal(real);
		pInput[x][y].SetImag(imag);
		return true;
	}
	else
	{
		#ifdef USE_MESSAGE_BOX_FOR_FAILURE		
			AfxMessageBox("Index out of range!");
		#endif
		return false;
	}
}

void CFFT2D::ForwardTransform()
{
	unsigned int i, j;

	for(j = 0; j < nY; j++)
	{
		CFFT1D rowFFT(nX);
		for(i = 0; i < nX; i++)
			rowFFT.SetInputAt(i, pInput[i][j].GetReal(), pInput[i][j].GetImag());

		rowFFT.ForwardTransform();

		for(i = 0; i < nX; i++)
			pInput[i][j] = rowFFT.GetOutputAt(i);
	}

	for(i = 0; i < nX; i++)
	{
		CFFT1D colFFT(nY);
		for(j = 0; j < nY; j++)
			colFFT.SetInputAt(j, pInput[i][j].GetReal(), pInput[i][j].GetImag());

		colFFT.ForwardTransform();

		for(j = 0; j < nY; j++)
			pInput[i][j] = colFFT.GetOutputAt(j);
	}
}
	
void CFFT2D::ReverseTransform()
{
	unsigned int i, j;

	for(i = 0; i < nX; i++)
	{
		CFFT1D colFFT(nY);
		for(j = 0; j < nY; j++)
			colFFT.SetOutputAt(j, pInput[i][j].GetReal(), pInput[i][j].GetImag());

		colFFT.ReverseTransform();

		for(j = 0; j < nY; j++)
			pInput[i][j] = colFFT.GetOutputAt(j);
	}

	for(j = 0; j < nY; j++)
	{
		CFFT1D rowFFT(nX);
		for(i = 0; i < nX; i++)
			rowFFT.SetOutputAt(i, pInput[i][j].GetReal(), pInput[i][j].GetImag());

		rowFFT.ReverseTransform();

		for(i = 0; i < nX; i++)
			pInput[i][j] = rowFFT.GetOutputAt(i);
	}
}

⌨️ 快捷键说明

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