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

📄 fft2dlg.cpp

📁 fft and convolution
💻 CPP
字号:
// fft2Dlg.cpp : implementation file
//

#include "stdafx.h" 
#include "fft2.h"
#include "fft2Dlg.h"
#include "math.h"


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



/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About


/////////////////////////////////////////////////////



class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFft2Dlg dialog

CFft2Dlg::CFft2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFft2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFft2Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFft2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFft2Dlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFft2Dlg, CDialog)
	//{{AFX_MSG_MAP(CFft2Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_PLOT, OnPlot)
	ON_BN_CLICKED(IDC_CONVOLUTION, OnConvolution)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFft2Dlg message handlers

BOOL CFft2Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
    
	 
  
	

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFft2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFft2Dlg::OnPaint() 
{

	
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
 	
		
	}
	else
	{
	//	DrawElement();
		
		CDialog::OnPaint();
	}


}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFft2Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void CFft2Dlg::OnTest() 
{
	// TODO: Add your control notification handler code here
  
	
}



void CFft2Dlg::OnFft() 
{
	// TODO: Add your control notification handler code here

/*
	CString str;
	

	fftmy myfft;
	BeginWaitCursor();
str.Format(str+"总点数为:%d",Num);
	Num=sizeof(data)/16;
	myfft.FFTmy(data,Num); 
 Num=sizeof(data)/16;
	EndWaitCursor();	

		
	/*	for(int j=0;j<Num;j++)
		{
	str.Format(str+" %f+j%f ",data[j].real,data[j].image);
 
		}
		*/
/*	Num=sizeof(data)/16;	 
		myfft.fuabs(data,Num,power);
		Num=sizeof(data)/16;
			GetDlgItem(IDC_STATIC)->SetWindowText(str); 
*/	
}

void CFft2Dlg::OnDraw() 
{
	// TODO: Add your control notification handler code here
/*	
CString str;
Num=sizeof(data)/16;
xunite=512/Num;
str.Format("总点数为:%d 结果为:\n",Num);
	for(int i=0;i<Num;i++)
		{
		//mdrawlin(i*xunite,0,i*xunite,(10*(int)(power[i]))<160?(10*(int)(power[i])):160,0);
		mdrawlin(i*xunite,0,i*xunite,(int)160*(power[i]/power[1])<=160?(int)160*(power[i]/power[1]):160,0);
			str.Format(str+"%.3f ",power[i]);
		}
	//Invalidate();
	GetDlgItem(IDC_STATIC)->SetWindowText(str); 
*/	
}
/*
void CFft2Dlg::DrawElement()
{
		int i;
	CWnd *pWnd=GetDlgItem(IDC_DRAWBOX);//
	CDC *pDC=pWnd->GetDC();

	::GetClientRect(pWnd->m_hWnd,conRect); //获得这个控件的矩形区域。

	pDC->SelectStockObject(NULL_BRUSH);		//将索引值为NULL_BRUSH的库存对象选进设备环境

	//设置视窗原点
	pDC->SetViewportOrg(conRect.left+20,conRect.bottom-15);

	//判断成员变量的值,以便确定绘制对象的类型。
	CPen Pen(PS_SOLID,1,RGB(0,150,150));
	CPen *OldPen=pDC->SelectObject(&Pen);

	pDC->MoveTo(0,0);
	pDC->LineTo(510,0);
	pDC->LineTo(510,-160*2);
	pDC->LineTo(0,-160*2);
	pDC->LineTo(0,0);

	CPen Pen2(PS_DOT,1,RGB(0,150,150));;
	pDC->SelectObject(&Pen2);
	//||
	for(i=0;i<50;i++)
	{
	pDC->MoveTo(10*i+10,0);
	pDC->LineTo(10*i+10,-160*2);
	}
	//-
	for(i=1;i<32;i++)
	{
	pDC->MoveTo(0,-10*i);
	pDC->LineTo(510,-10*i);
	}

 
	CPen Pen1(PS_SOLID,1,RGB(0,150,150));;
	pDC->SelectObject(&Pen1);
	for(i=0;i<10;i++)
	{
	pDC->MoveTo(50*i,0);
	pDC->LineTo(50*i,-160*2);
	}

	pDC->MoveTo(0,-80*2);
	pDC->LineTo(510,-80*2);
	pDC->MoveTo(0,-240);
	pDC->LineTo(510,-240);
    
	pDC->SelectObject(&OldPen);

	pWnd->ReleaseDC(pDC);
}*/
/*
void CFft2Dlg::mdrawlin(int x0, int y0, int x1, int y1, int a)
{
	CWnd *pWnd=GetDlgItem(IDC_DRAWBOX);//
	CDC *pDC=pWnd->GetDC();
	::GetClientRect(pWnd->m_hWnd,conRect); //获得这个控件的矩形区域。
	pDC->SelectStockObject(NULL_BRUSH);		//将索引值为NULL_BRUSH的库存对象选进设备环境
	//设置视窗原点
	
	CPen *OldPen;
	if(a==0)
	{
		pDC->SetViewportOrg(conRect.left+20,conRect.bottom-15-160);
	CPen Pen(PS_SOLID,1,RGB(255,0,55));
	OldPen=pDC->SelectObject(&Pen);
	

	
	pDC->MoveTo(x0,y0);
	pDC->LineTo(x1,y1);
	}
	if(a==1)
	{
		pDC->SetViewportOrg(conRect.left+20,conRect.bottom-15-240);
	CPen Pen(PS_SOLID,1,RGB(0,0,0));
	CPen *OldPen=pDC->SelectObject(&Pen);

		pDC->Ellipse(x1-1,-y1-1,x1+1,-y1+1);

	}
//	Invalidate(false);
//	pDC->Ellipse(x0-a,y1-a,x0+a,y1+a);

	pDC->SelectObject(&OldPen);
	 
	pWnd->ReleaseDC(pDC);

	
}
*/
void CFft2Dlg::OnPlot() 
{
	// TODO: Add your control notification handler code here

/*	Num=sizeof(data)/16;
	 xunite=512/Num;
	double xjiange=1.2*3.14159/(Num-1);
	double x=0;
	int i=0;
	CString str;
	str.Format(str+"开始fft,总点数:%d\\ ",Num);
	for( i=0;i<Num;i++)
	{
	/*
		data[i].image=0;
		
		data[i].real=sin(x);	
		x+=xjiange;
		*/

		//str.Format(str+" %f+j%f ",data[i].real,data[i].image);

 /*  if(i<2)
   {
	   data[i].real=1;
       data[i].image=0;

   }
   else{
	   data[i].real=0;
	   data[i].image=0;  

   }
   */
   //矩形波
		/*
		if(i<256)
   {
	   data[i].real=i/255.0;
       data[i].image=0;

   }
   else{
	   data[i].real=(511-i)/256.0;
	   data[i].image=0;  

   }
   *///三角波
		//CString str;
		//	str.Format("%f",data[i].real);
   // AfxMessageBox(str);
		
/*		
		mdrawlin(i*xunite,0,i*xunite,(int)(50*data[i].real),1);

	}
*/
	DialogFFT fft;
    fft.DoModal();
	
}

void CFft2Dlg::OnConvolution() 
{
	// TODO: Add your control notification handler code here
	DialogConvolution dlg;
	dlg.DoModal();


	
}

⌨️ 快捷键说明

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