📄 fft1view.cpp
字号:
// FFT1View.cpp : implementation of the CFFT1View class
//
#include "stdafx.h"
#include "FFT1.h"
#include "FFT1Doc.h"
#include "FFT1View.h"
#include "matlib.h"
//#pragma hdrstop
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//unsigned int mlibpr=mt_set_MT(0);
/////////////////////////////////////////////////////////////////////////////
// CFFT1View
IMPLEMENT_DYNCREATE(CFFT1View, CFormView)
BEGIN_MESSAGE_MAP(CFFT1View, CFormView)
//{{AFX_MSG_MAP(CFFT1View)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFFT1View construction/destruction
CFFT1View::CFFT1View()
: CFormView(CFFT1View::IDD)
{
//{{AFX_DATA_INIT(CFFT1View)
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CFFT1View::~CFFT1View()
{
}
void CFFT1View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFFT1View)
DDX_Control(pDX, IDC_STATIC222, m_static222);
DDX_Control(pDX,IDC_STATIC111,m_picture);
//}}AFX_DATA_MAP
}
BOOL CFFT1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CFFT1View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CFFT1View printing
BOOL CFFT1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFFT1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFFT1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CFFT1View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CFFT1View diagnostics
#ifdef _DEBUG
void CFFT1View::AssertValid() const
{
CFormView::AssertValid();
}
void CFFT1View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFFT1Doc* CFFT1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFFT1Doc)));
return (CFFT1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFFT1View message handlers
void CFFT1View::OnButton1()
{
// TODO: Add your control notification handler code here
// begin_scope
initM(MATCOM_VERSION);
/* CWnd *p1=NULL;
p1=(CWnd *)GetDlgItem(IDC_STATIC);
Mm h=winaxes(p1->m_hWnd);
Mm pos=(BR(20),20,200,150);
set(h,TM("RealPosition"),pos);
Mm t;
t=linspace(0,4*pi);
plot((CL(t),sin(t),TM("b-")));
hold(TM("on"));
plot((CL(t),cos(t),TM("r*")));
title((CL(TM("波形图"))));
xlabel((CL(TM("X 轴"))));
ylabel((CL(TM("Y 轴"))));
set(h,(CL(TM("Color")),TM("white")));*/
dMm(fs); dMm(t); dMm(f1); dMm(f2); dMm(x); dMm(number); dMm(y); dMm(n); dMm(f);
// call_stack_begin;
// display(clear());
//编写骆遥
double m_temp1,m_temp2;
int m_number;
fs = 1000.0; //display(fs);
t = colon(0.0,1.0/fs,0.6);
f1 = 100.0;
f2 = 300.0;
// x = sin(2.0*pi*f1*t);
x = sin(2.0*pi*f1*t)+sin(2.0*pi*f2*t);
CWnd *p1=NULL;
p1=(CWnd *)GetDlgItem(IDC_STATIC111);
Mm h=winaxes(p1->m_hWnd);
Mm pos=(BR(30),30,200,150);
set(h,TM("RealPosition"),pos);
// display( subplot(711.0) );
plot(CL(x));
m_temp1=x.r(1); //矩阵第一点
m_temp2=x.r(600);
m_number=x.size();
// title((CL(TM("三维图"))));
// set(h,(CL(TM("Color")),TM("white")));
// hold(TM("on"));
// grid(TM("on"));
display( title((CL(TM("f1(100Hz)\\f2(300Hz)的正弦信号,初相0")))) );
display( xlabel((CL(TM("序列(n)")))) );
//grid(TM("on"));
number = 512.0; //display(number);
y = fft(x,number);
n = colon(0.0,1.0,length(y)-1.0);
f = fs*n/length(y);
CWnd *p2=NULL;
p2=(CWnd *)GetDlgItem(IDC_STATIC222);
Mm h2=winaxes(p2->m_hWnd);
Mm pos2=(BR(30),30,200,150);
set(h2,TM("RealPosition"),pos2);
// display( subplot(713.0) );
plot((CL(f),abs(y)));
display( title((CL(TM("f1\\f2的正弦信号的FFT(512点)")))) );
display( xlabel((CL(TM("频率Hz")))) );
grid(TM("on"));
drawnow();
// call_stack_end;
/* dMm(y);
dMm(z);
dMm(x1);
dMm(y1);
y=colon(8.0,-0.5,-8.0);
meshgrid(y,y,i_o,x1,y1);
z=power(x1,2.0)+power(y1,2.0);
// CWnd *p1=NULL;
// m_picture=GetDlgItem(IDC_STATIC);
// p1=(CWnd *)GetDlgItem(IDC_STATIC);
Mm plothandle=winaxes(m_picture.m_hWnd);
Mm pos=(BR(20),20,200,150);
set(plothandle,TM("RealPosition"),pos);
title((CL(TM("三维图"))));
set(plothandle,(CL(TM("Color")),TM("white")));
// set(plothandle,(CL(TM("Box")),TM("on")));
mesh((CL(z)));
drawnow();*/
exitM();
// end_scope
CString str;
str.Format("测试值为:%f %f %d",m_temp1,m_temp2,m_number);
AfxMessageBox(str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -