www.pudn.com > DigtalImageProc.rar > dft.cpp


 
#include "stdafx.h" 
#include "stdio.h" 
#include "math.h" 
#include "dft.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
#define PIE 3.14159265 
 
////////////////////////////////////////////////// 
 
Complex::Complex() 
{ 
	Re=0.0; 
	Im=0.0; 
} 
 
Complex::~Complex() 
{ 
} 
 
Complex::Complex(double x,double y) 
{ 
	Re=x;Im=y; 
} 
 
double Complex::abs() 
{ 
	return sqrt(Re*Re+Im*Im); 
} 
 
double Complex::GetRe() 
{ 
	return Re; 
} 
 
double Complex::GetIm() 
{ 
	return Im; 
} 
 
void Complex::operator=(wComplex &cm) 
{ 
	Re=cm.GetRe(); 
	Im=cm.GetIm(); 
} 
 
void Complex::operator+=(wComplex &cm) 
{	 
	Re+=cm.GetRe(); 
	Im+=cm.GetIm(); 
} 
 
void Complex::operator-=(wComplex &cm) 
{ 
	Re-=cm.GetRe(); 
	Im-=cm.GetIm(); 
} 
 
void Complex::operator*=(wComplex &cm) 
{ 
	double x=Re*cm.GetRe()-Im*cm.GetIm(); 
	double y=Re*cm.GetIm()+Im*cm.GetRe(); 
	Re=x; 
	Im=y; 
} 
 
Complex Complex::operator*(wComplex &cm) 
{ 
	Complex temp; 
	temp.Re=Re*cm.GetRe()-Im*cm.GetIm(); 
	temp.Im=Re*cm.GetIm()+Im*cm.GetRe(); 
	return temp; 
} 
 
void Complex::operator*=(float var) 
{ 
	Re*=var; 
	Im*=var; 
} 
 
wComplex Complex::operator+(wComplex &cm) 
{ 
	double x=Re+cm.GetRe(); 
	double y=Im+cm.GetIm(); 
	return wComplex(x,y); 
} 
 
void Complex::operator/=(double x) 
{ 
	Re/=x;Im/=x; 
} 
 
Complex Complex::operator/(double x) 
{ 
	Complex temp; 
	temp.Re=Re/x; 
	temp.Im=Im/x; 
	return temp; 
} 
 
wComplex Complex::operator-(wComplex &cm) 
{ 
	double x=Re-cm.GetRe(); 
	double y=Im-cm.GetIm(); 
	return wComplex(x,y); 
} 
 
////////////////////////////////////////////////// 
 
Fourior::Fourior() 
{ 
	flag=FALSE; 
} 
 
Fourior::Fourior(int N) 
{ 
	flag=FALSE; 
	ByteNum=N; 
	bWn=new BYTE[ByteNum*sizeof(wComplex)]; 
	Wn=(wComplex *)bWn; 
	if(!Wn)return; 
	for(int i=0;iGetRe(); 
			double y=-(Wn+i)->GetIm(); 
			*(Wn+i)=wComplex(x,y); 
		} 
	} 
} 
 
Fourior::~Fourior() 
{ 
	if(flag==TRUE)delete bWn; 
} 
 
void Fourior::DFT(wComplex *Input) 
{ 
	int i,j; 
	BYTE *btemp=new BYTE[ByteNum*sizeof(wComplex)]; 
	wComplex *temp=(wComplex *)btemp; 
	if(!temp) 
	{ 
		AfxMessageBox("内存分配失败!"); 
		return; 
	} 
 
	wComplex var0((double)0,(double)0); 
	for(i=0;i>=1;i++; 
		if(temp&1==1)break; 
	} 
	M=i; 
	BitsNum=i; 
	if(ByteNum!=1<>=1; 
		} 
		*(output+i)=*(Input+k); 
	} 
	for(i=1;i<=M;i++)     //蝶形运算 
	{ 
		N1=N; 
		for(j=0;j>=1; 
		N2=1; 
		/*for(j=0;j 0) 
			N2  = N2<<(i-1); 
		N3=N2*2; 
		N4=1; 
		/*for(j=0;j 0) 
			N4 = N4 <<(M-i); 
		for(j=0;j