📄 fftdrawing.cpp
字号:
// FftDrawing.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "FftDrawing.h"
#include "FftDrawingDlg.h"
////自己添加的.
#include"math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFftDrawingApp
BEGIN_MESSAGE_MAP(CFftDrawingApp, CWinApp)
//{{AFX_MSG_MAP(CFftDrawingApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFftDrawingApp construction
CFftDrawingApp::CFftDrawingApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CFftDrawingApp object
CFftDrawingApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CFftDrawingApp initialization
BOOL CFftDrawingApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CFftDrawingDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
/*
////自己添加的.
void CFftDrawingApp::Fft(double *shibu, double *xubu)
{
double PI=3.1415926535;
int M,N;
double x[256],xr[256],xi[256],t[256],jiaodu;
M=8;
N=1<<M;
jiaodu=(-2*PI)/N;
///数据点输入:
//caidian();
for (int i=0;i<N;i++)
{
if (i<8)
x[i]=1;
else
x[i]=0;
}
////数据点输入结束.
////将数据点重新排序,以实现fft计算.
//paixu();
int kuaishu=1,geshu;
for( i=0;i<N;i++)
t[i]=x[i];
for(int pi=1;pi<M;pi++)
{
kuaishu=1<<(pi);
geshu=N/kuaishu;
for(int fi=0;fi<kuaishu;fi++)
{
if(fi%2==0)
{
for(int fk=0;fk<geshu;fk++)
x[fi*geshu+fk]=t[fi*geshu+fk*2];
}
if(fi%2==1)
{
for(int fk=0;fk<geshu;fk++)
x[fi*geshu+fk]=t[(fi-1)*geshu+1+fk*2];
}
}
for(int i=0;i<256;i++)
t[i]=x[i];
}
////排序结束.
////进行fft计算:
///fft();
int zengzhi;
double t1r,t2r,t1i,t2i;
double jd; ///计算的角度
int wz=1<<M;
for( i=0;i<N;i++)
{
xr[i]=x[i];
xi[i]=0;
}
for(int i1=M-1;i1>=0;i1--)
{
wz=wz/2;
kuaishu=1<<(i1);
geshu=N/kuaishu;
zengzhi=kuaishu;
for(int i2=0;i2<kuaishu;i2++)
{
for(int i3=0;i3<(geshu/2);i3++)
{
jd=jiaodu*zengzhi*i3;
t1r=xr[geshu*i2+i3];
t1i=xi[geshu*i2+i3];
t2r=xr[geshu*i2+i3+geshu/2];
t2i=xi[geshu*i2+i3+geshu/2];
xr[geshu*i2+i3]=t1r+t2r*cos(jd)-t2i*sin(jd);
xi[geshu*i2+i3]=t1i+t2i*cos(jd)+t2r*sin(jd);
xr[geshu*i2+i3+geshu/2]=t1r-t2r*cos(jd)+t2i*sin(jd);
xi[geshu*i2+i3+geshu/2]=t1i-t2i*cos(jd)-t2r*sin(jd);
}
}
}
for(i=0;i<256;i++)
{
shibu[i]=xr[i];
xubu[i]=xi[i];
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -