?? fft2d.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 + -