📄 bpftestview.cpp
字号:
// BPFTESTView.cpp : implementation of the CBPFTESTView class
//
#include "stdafx.h"
#include "BPFTEST.h"
#include "math.h"
#include "BPFTESTDoc.h"
#include "BPFTESTView.h"
#include "winbase.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBPFTESTView
IMPLEMENT_DYNCREATE(CBPFTESTView, CFormView)
BEGIN_MESSAGE_MAP(CBPFTESTView, CFormView)
//{{AFX_MSG_MAP(CBPFTESTView)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_UPDATE(IDC_EDIT1, OnUpdateEdit1)
ON_BN_CLICKED(IDC_BUTTON4, OnFFT)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CBPFTESTView construction/destruction
CBPFTESTView::CBPFTESTView()
: CFormView(CBPFTESTView::IDD)
{
//{{AFX_DATA_INIT(CBPFTESTView)
m_freq = _T("");
m_flt = FALSE;
m_pp = FALSE;
m_disp = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CBPFTESTView::~CBPFTESTView()
{
}
void CBPFTESTView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBPFTESTView)
DDX_Control(pDX, IDC_COMBO1, m_filtsel);
DDX_Text(pDX, IDC_EDIT1, m_freq);
DDX_Check(pDX, IDC_CHECK1, m_flt);
DDX_Check(pDX, IDC_CHECK2, m_pp);
DDX_Text(pDX, IDC_EDIT2, m_disp);
//}}AFX_DATA_MAP
}
BOOL CBPFTESTView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CBPFTESTView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit(false);
m_filtsel.SetCurSel(0);
m_freq="30";
UpdateData(false);
f=atoi(m_freq);
}
/////////////////////////////////////////////////////////////////////////////
// CBPFTESTView printing
BOOL CBPFTESTView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBPFTESTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBPFTESTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CBPFTESTView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CBPFTESTView diagnostics
#ifdef _DEBUG
void CBPFTESTView::AssertValid() const
{
CFormView::AssertValid();
}
void CBPFTESTView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CBPFTESTDoc* CBPFTESTView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBPFTESTDoc)));
return (CBPFTESTDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBPFTESTView message handlers
void CBPFTESTView::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CDC *pDC=GetDC();
CRect lpRect,rect;
this->GetClientRect(lpRect);
int i;
int InSize=10240;
int *pIn=new int[InSize];
int *pOut=new int[InSize];
ZeroMemory(pOut,InSize);
//
rect.bottom=lpRect.bottom-100;
rect.left=lpRect.left;
rect.right=lpRect.right;
rect.top=lpRect.top;
pDC->FillRect(rect,NULL);
int fs=22050;//500;//
pDC->MoveTo(0,lpRect.bottom/3);
for(i=0;i<InSize;i++)
{
pIn[i]=(int)(50*sin(2*3.14159*f*i/fs));
switch(m_filtsel.GetCurSel())
{
case 0: pOut[i]=BPF30(B30,A30,L30,pIn[i]);
//pOut[i]=BPF30(pIn[i]);
break;
case 1: pOut[i]=BPF60(B60,A60,L60,pIn[i]);
break;
case 2: pOut[i]=BPF100(B100,A100,L100,pIn[i]);
break;
case 3: pOut[i]=BPF150(B150,A150,L150,pIn[i]);
break;
case 4: pOut[i]=BPF300(B300,A300,L300,pIn[i]);
break;
case 5: pOut[i]=BPF500(B500,A500,L500,pIn[i]);
break;
case 6: pOut[i]=BPF1k(B1K,A1K,L1K,pIn[i]);
break;
case 7: pOut[i]=BPF2k(B2K,A2K,L2K,pIn[i]);
break;
case 8: pOut[i]=BPF3k(B3K,A3K,L3K,pIn[i]);
break;
case 9: pOut[i]=BPF4k(B4K,A4K,L4K,pIn[i]);
break;
case 10:pOut[i]=BPF5k(B5K,A5K,L5K,pIn[i]);
break;
case 11:pOut[i]=BPF6k(B6K,A6K,L6K,pIn[i]);
break;
case 12:pOut[i]=BPF7k(B7K,A7K,L7K,pIn[i]);
break;
case 13:pOut[i]=BPF8k(B8K,A8K,L8K,pIn[i]);
break;
case 14:pOut[i]=BPF9k(B9K,A9K,L9K,pIn[i]);
break;
case 15:pOut[i]=BPF10k(B10K,A10K,L10K,pIn[i]);
break;
default:break;
}
}
for(i=0;i<InSize;i++)
{
if(i*10<InSize)
{
pDC->LineTo(i,lpRect.bottom/3+pIn[i*10]);
}
}
pDC->MoveTo(0,2*lpRect.bottom/3);
/* for(i=InSize/10-1000;i<InSize;i++)
{
if(i*10<InSize)
{
pDC->LineTo(i-InSize/10+1000,2*lpRect.bottom/3+pOut[i*10]);
}
}*/
for(i=0;i<InSize;i++)
{
if(i*10<InSize)
{
pDC->LineTo(i,2*lpRect.bottom/3+pOut[i*10]);
}
}
ReleaseDC(pDC);
delete[] pIn;
delete[] pOut;
}
void CBPFTESTView::OnButton2()
{
// TODO: Add your control notification handler code here
//减小信号源频率
if(f>=5)
{
// itoa(f,m_freq,5);
// m_freq=f;
m_freq.Format("%d",f);
UpdateData(false);
if(m_flt)
{
f-=5;
OnButton1();
}
else
{
f-=50;
OnFFT();
}
}
}
void CBPFTESTView::OnButton3()
{
// TODO: Add your control notification handler code here
//增大信号源频率
if(f<=11000)
{
// itoa(f,m_freq,5);
// m_freq=f;
m_freq.Format("%d",f);
UpdateData(false);
if(m_flt)
{
f+=5;
OnButton1();
}
else
{
f+=50;
OnFFT();
}
}
}
void CBPFTESTView::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CFormView::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(true);
f=atoi(m_freq);
}
void CBPFTESTView::OnUpdateEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CFormView::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
UpdateData(true);
f=atoi(m_freq);
}
void CBPFTESTView::OnFFT()
{
// TODO: Add your control notification handler code here
int n=2048;
double * fr=new double[n];
double * fi=new double[n];
double * Pm=new double[n/2];
double * Am=new double[n/2];
CDC *pDC=GetDC();
CRect lpRect,rect;
this->GetClientRect(lpRect);
int i;
UpdateData(true);
// ZeroMemory(pOut,InSize);
//
rect.bottom=lpRect.bottom-100;
rect.left=lpRect.left;
rect.right=lpRect.right;
rect.top=lpRect.top;
pDC->FillRect(rect,NULL);
int fs=22050;//500;//
pDC->MoveTo(0,lpRect.bottom/3);
for(i=0;i<n;i++)//填充输入缓冲区
{
fr[i]=(int)(90*sin(2*PI*f*i/fs));
fi[i]=0;
}
for(i=0;i<n;i++)
{
if(i<=n/10)
fr[i]=fr[i]*sin(PI*i/n);
else
fr[i]=0;
}
FFT(fr,fi,n,0);
CString str="";
for(i=0;i<n/2;i++)
{
Pm[i]=fr[i]*fr[i]+fi[i]*fi[i];
Pm[i]/=5000;
Am[i]=sqrt(Pm[i]);
}
pDC->MoveTo(0,3*lpRect.bottom/4);
for(i=0;i<n/2;i++)
{
if(i<n/2)
{
pDC->LineTo(i,3*lpRect.bottom/4-(int)Pm[i]);
}
}
pDC->MoveTo(0,3*lpRect.bottom/4+10);
pDC->LineTo(fs/2,3*lpRect.bottom/4+10);
pDC->MoveTo(0,3*lpRect.bottom/4+10);
double k;
int z;
double div=(100.0*n/2)/11025;
for(k=0.0;k<fs/2;i++)
{
pDC->MoveTo((int)k,3*lpRect.bottom/4+10);
pDC->LineTo((int)k,3*lpRect.bottom/4+15);
k+=div;
}
div=(1000.0*n/2)/11025;
for(k=0.0,z=0;k<fs/2;z++)
{
str.Format("%dKHz",z);
pDC->MoveTo((int)k,3*lpRect.bottom/4+10);
pDC->LineTo((int)k,3*lpRect.bottom/4+20);
pDC->TextOut((int)k-10,3*lpRect.bottom/4+25,str);
k+=div;
}
ReleaseDC(pDC);
delete[] fr;
delete[] fi;
delete[] Pm;
delete[] Am;
}
void CBPFTESTView::OnCheck1()
{
// TODO: Add your control notification handler code here
m_flt=!m_flt;
m_pp=!m_flt;
UpdateData(false);
}
void CBPFTESTView::OnCheck2()
{
// TODO: Add your control notification handler code here
m_pp=!m_pp;
m_flt=!m_pp;
UpdateData(false);
}
void CBPFTESTView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
if(m_flt)
{
OnButton1();
}
else
{
OnFFT();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -