📄 痴迷人信号采集系统dlg.cpp
字号:
for(i=0;i<r;i++)
{
if(j&(1<<i))
p+=1<<(r-i-1);
}
FD[j]=X1[p];
}
delete W;
delete X1;
delete X2;
}
void CMyDlg::DrawFFT()
{
CClientDC dc(this);
dc.SelectObject(hBlackBrush);
dc.Rectangle(&rectArea2);
if(m_iChanels==2)
dc.Rectangle(&rectArea4);
dc.SelectObject(hYellowPen);
dc.MoveTo(rectArea2.left,rectArea2.bottom-1);
dc.LineTo(rectArea2.right,rectArea2.bottom-1);
int i=0;
double fftdatmax=0;
for(i=0;i<SCANCOUNT;i++)
{
fftdat[i]=sqrt(fftout[i].real*fftout[i].real+fftout[i].imag*fftout[i].imag);
if(fftdatmax<fftdat[i])
fftdatmax=fftdat[i];
}
double fftinput;
unsigned int newx,newy,oldx,oldy;
dc.SelectObject(hRedPen);
for (i=1; i<SCANCOUNT/2; ) {
fftinput = fftdat[i];
newy = rectArea2.bottom-2-(int)(fftinput*(rectArea2.bottom-rectArea2.top-2)/fftdatmax);
newx = (rectArea2.left)+i;
if (i==1)
dc.MoveTo(newx, newy);
else
dc.MoveTo(oldx, oldy);
dc.LineTo(newx, newy);
oldx = newx;
oldy = newy;
i+=1;
if(oldx>=(unsigned int)(rectArea2.right-1))
break;
}
fftdatmax = fftdatmax*2/65536;
dc.SetBkMode(TRANSPARENT);
dc.SelectObject(hBlackPen);
CString m_strMark;
m_strMark.Format("%.3f",fftdatmax);
dc.TextOut(rectArea2.left-60,rectArea2.top-10,m_strMark);
m_strMark.Format("%.3f",3*fftdatmax/4);
dc.TextOut(rectArea2.left-60,(rectArea2.top+(rectArea2.bottom-rectArea2.top)/4)-10,m_strMark);
m_strMark.Format("%.3f",fftdatmax/2);
dc.TextOut(rectArea2.left-60,((rectArea2.bottom+rectArea2.top)/2)-4,m_strMark);
m_strMark.Format("%.3f",fftdatmax/4);
dc.TextOut(rectArea2.left-60,(rectArea2.top+(rectArea2.bottom-rectArea2.top)*3/4)-10,m_strMark);
m_strMark.Format(" %d",0);
dc.TextOut(rectArea2.left-60,rectArea2.bottom-10,m_strMark);
if(m_iChanels==2)
{
dc.SelectObject(hYellowPen);
dc.MoveTo(rectArea4.left,rectArea4.bottom-1);
dc.LineTo(rectArea4.right,rectArea4.bottom-1);
int i=0;
double fftdatmax=0;
for(i=0;i<SCANCOUNT;i++)
{
fftdat1[i]=sqrt(fftout1[i].real*fftout1[i].real+fftout1[i].imag*fftout1[i].imag);
if(fftdatmax<fftdat1[i])
fftdatmax=fftdat1[i];
}
double fftinput;
unsigned int newx,newy,oldx,oldy;
CClientDC dc(this);
dc.SelectObject(hBlackBrush);
dc.SelectObject(hRedPen);
for (i=1; i<SCANCOUNT/2; ) {
fftinput = fftdat1[i];
newy = rectArea4.bottom-2-(int)(fftinput*(rectArea4.bottom-rectArea4.top-2)/fftdatmax);
newx = (rectArea4.left)+i;
if (i==1)
dc.MoveTo(newx, newy);
else
dc.MoveTo(oldx, oldy);
dc.LineTo(newx, newy);
oldx = newx;
oldy = newy;
i+=1;
if(oldx>=(unsigned int)(rectArea4.right-1))
break;
}
fftdatmax = fftdatmax*2/65536;
dc.SetBkMode(TRANSPARENT);
dc.SelectObject(hBlackPen);
CString m_strMark;
m_strMark.Format("%.3f",fftdatmax);
dc.TextOut(rectArea4.left-60,rectArea4.top-10,m_strMark);
m_strMark.Format("%.3f",3*fftdatmax/4);
dc.TextOut(rectArea4.left-60,(rectArea4.top+(rectArea4.bottom-rectArea4.top)/4)-10,m_strMark);
m_strMark.Format("%.3f",fftdatmax/2);
dc.TextOut(rectArea4.left-60,((rectArea4.bottom+rectArea4.top)/2)-4,m_strMark);
m_strMark.Format("%.3f",fftdatmax/4);
dc.TextOut(rectArea4.left-60,(rectArea4.top+(rectArea4.bottom-rectArea4.top)*3/4)-10,m_strMark);
m_strMark.Format(" %d",0);
dc.TextOut(rectArea4.left-60,rectArea4.bottom-10,m_strMark);
}
}
void CMyDlg::OnSelchange()
{
int m_iRate=m_combRate.GetCurSel();
int m_iVolt=m_combVolt.GetCurSel();
switch(m_iRate)
{
case 0:
m_uRate=10000;
break;
case 1:
m_uRate=20000;
break;
case 2:
m_uRate=30000;
break;
case 3:
m_uRate=40000;
break;
case 4:
m_uRate=50000;
break;
case 5:
m_uRate=60000;
break;
case 6:
m_uRate=70000;
break;
case 7:
m_uRate=80000;
break;
case 8:
m_uRate=90000;
break;
case 9:
m_uRate=100000;
break;
case 10:
m_uRate=110000;
break;
case 11:
m_uRate=120000;
break;
case 12:
m_uRate=130000;
break;
case 13:
m_uRate=140000;
break;
case 14:
m_uRate=150000;
break;
case 15:
m_uRate=160000;
break;
case 16:
m_uRate=170000;
break;
case 17:
m_uRate=180000;
break;
case 18:
m_uRate=190000;
break;
case 19:
m_uRate=200000;
break;
}
switch(m_iVolt)
{
case 0:
m_fVolt=10;
break;
case 1:
m_fVolt=5;
break;
case 2:
m_fVolt=2.5;
break;
case 3:
m_fVolt=1.25;
break;
case 4:
m_fVolt=0.625;
break;
default:
break;
}
DrawArea();
if(m_bIsDrawGraph)
DrawGraph();
if(m_bIsDrawFFT)
DrawFFT();
m_btStart.SetFocus();
}
void CMyDlg::DrawArea()
{
CClientDC dc(this);
dc.SelectObject(GetStockObject(GRAY_BRUSH));
dc.Rectangle(&rectBig);
if(m_iChanels==1)
{
rectArea1.left=rectSmall.left;
rectArea1.right=rectSmall.right;
rectArea1.top=rectSmall.top;
rectArea1.bottom=(rectSmall.top+rectSmall.bottom)/2-50;
rectArea2.left=rectSmall.left;
rectArea2.right=rectSmall.right;
rectArea2.top=(rectSmall.top+rectSmall.bottom)/2;
rectArea2.bottom=rectSmall.bottom-50;
dc.SelectObject(hBlackBrush);
dc.Rectangle(&rectArea1);
dc.Rectangle(&rectArea2);
dc.SelectObject(hYellowPen);
dc.MoveTo(rectArea1.left,(rectArea1.top+rectArea1.bottom)/2);
dc.LineTo(rectArea1.right,(rectArea1.top+rectArea1.bottom)/2);
dc.MoveTo(rectArea2.left,rectArea2.bottom-1);
dc.LineTo(rectArea2.right,rectArea2.bottom-1);
dc.SetBkMode(TRANSPARENT);
dc.SelectObject(hBlackPen);
CString m_strMark;
m_strMark.Format("+%.3f",m_fVolt);
dc.TextOut(rectArea1.left-60,rectArea1.top-10,m_strMark);
m_strMark.Format("+%.3f",m_fVolt/2);
dc.TextOut(rectArea1.left-60,(rectArea1.top+(rectArea1.bottom-rectArea1.top)/4)-10,m_strMark);
m_strMark.Format(" %d (V)",0);
dc.TextOut(rectArea1.left-60,((rectArea1.bottom+rectArea1.top)/2)-4,m_strMark);
m_strMark.Format("-%.3f",m_fVolt/2);
dc.TextOut(rectArea1.left-60,(rectArea1.top+(rectArea1.bottom-rectArea1.top)*3/4)-10,m_strMark);
m_strMark.Format("-%.3f",m_fVolt);
dc.TextOut(rectArea1.left-60,rectArea1.bottom-10,m_strMark);
m_strMark.Format("采样信号时域图");
dc.TextOut(rectSmall.left+200,rectArea1.bottom+26,m_strMark);
m_strMark.Format(" 0 (ms)");
dc.TextOut(rectSmall.left+0-10,rectArea1.bottom+6,m_strMark);
m_strMark.Format("%.2f",100000/(float)m_uRate);
dc.TextOut(rectSmall.left+100-10,rectArea1.bottom+6,m_strMark);
m_strMark.Format("%.2f",200000/(float)m_uRate);
dc.TextOut(rectSmall.left+200-10,rectArea1.bottom+6,m_strMark);
m_strMark.Format("%.2f",300000/(float)m_uRate);
dc.TextOut(rectSmall.left+300-10,rectArea1.bottom+6,m_strMark);
m_strMark.Format("%.2f",400000/(float)m_uRate);
dc.TextOut(rectSmall.left+400-10,rectArea1.bottom+6,m_strMark);
m_strMark.Format("%.2f",500000/(float)m_uRate);
dc.TextOut(rectSmall.left+500-10,rectArea1.bottom+6,m_strMark);
m_strMark.Format(" 0 (Hz)");
dc.TextOut(rectSmall.left+0-20,rectArea2.bottom+6,m_strMark);
m_strMark.Format("%d",m_uRate/8);
dc.TextOut(rectSmall.left+128-20,rectArea2.bottom+6,m_strMark);
m_strMark.Format("%d",m_uRate/4);
dc.TextOut(rectSmall.left+256-20,rectArea2.bottom+6,m_strMark);
m_strMark.Format("%d",3*m_uRate/8);
dc.TextOut(rectSmall.left+384-20,rectArea2.bottom+6,m_strMark);
m_strMark.Format("%d",m_uRate/2);
dc.TextOut(rectSmall.left+512-20,rectArea2.bottom+6,m_strMark);
m_strMark.Format("采样信号FFT幅值谱");
dc.TextOut(rectSmall.left+200,rectArea2.bottom+26,m_strMark);
}
if(m_iChanels==2)
{
rectArea1.left=rectSmall.left;
rectArea1.right=rectSmall.right;
rectArea1.top=rectSmall.top;
rectArea1.bottom=(3*rectSmall.top+rectSmall.bottom)/4-25;
rectArea2.left=rectSmall.left;
rectArea2.right=rectSmall.right;
rectArea2.top=(3*rectSmall.top+rectSmall.bottom)/4;
rectArea2.bottom=(rectSmall.top+rectSmall.bottom)/2-25;
rectArea3.left=rectSmall.left;
rectArea3.right=rectSmall.right;
rectArea3.top=(rectSmall.top+rectSmall.bottom)/2;
rectArea3.bottom=(rectSmall.top+3*rectSmall.bottom)/4-25;
rectArea4.left=rectSmall.left;
rectArea4.right=rectSmall.right;
rectArea4.top=(rectSmall.top+3*rectSmall.bottom)/4;
rectArea4.bottom=rectSmall.bottom-25;
dc.SelectObject(hBlackBrush);
dc.Rectangle(&rectArea1);
dc.Rectangle(&rectArea2);
dc.Rectangle(&rectArea3);
dc.Rectangle(&rectArea4);
dc.SelectObject(hYellowPen);
dc.MoveTo(rectArea1.left,(rectArea1.top+rectArea1.bottom)/2);
dc.LineTo(rectArea1.right,(rectArea1.top+rectArea1.bottom)/2);
dc.MoveTo(rectArea2.left,rectArea2.bottom-1);
dc.LineTo(rectArea2.right,rectArea2.bottom-1);
dc.MoveTo(rectArea3.left,(rectArea3.top+rectArea3.bottom)/2);
dc.LineTo(rectArea3.right,(rectArea3.top+rectArea3.bottom)/2);
dc.MoveTo(rectArea4.left,rectArea4.bottom-1);
dc.LineTo(rectArea4.right,rectArea4.bottom-1);
dc.SetBkMode(TRANSPARENT);
dc.SelectObject(hBlackPen);
CString m_strMark;
m_strMark.Format("+%.3f",m_fVolt);
dc.TextOut(rectArea1.left-60,rectArea1.top-10,m_strMark);
dc.TextOut(rectArea3.left-60,rectArea3.top-10,m_strMark);
m_strMark.Format("+%.3f",m_fVolt/2);
dc.TextOut(rectArea1.left-60,(rectArea1.top+(rectArea1.bottom-rectArea1.top)/4)-10,m_strMark);
dc.TextOut(rectArea3.left-60,(rectArea3.top+(rectArea3.bottom-rectArea3.top)/4)-10,m_strMark);
m_strMark.Format(" %d",0);
dc.TextOut(rectArea1.left-60,((rectArea1.bottom+rectArea1.top)/2)-4,m_strMark);
dc.TextOut(rectArea3.left-60,((rectArea3.bottom+rectArea3.top)/2)-4,m_strMark);
m_strMark.Format("-%.3f",m_fVolt/2);
dc.TextOut(rectArea1.left-60,(rectArea1.top+(rectArea1.bottom-rectArea1.top)*3/4)-10,m_strMark);
dc.TextOut(rectArea3.left-60,(rectArea3.top+(rectArea3.bottom-rectArea3.top)*3/4)-10,m_strMark);
m_strMark.Format("-%.3f",m_fVolt);
dc.TextOut(rectArea1.left-60,rectArea1.bottom-10,m_strMark);
dc.TextOut(rectArea3.left-60,rectArea3.bottom-10,m_strMark);
m_strMark.Format("通道一采样信号");
dc.TextOut(rectSmall.left+250,rectArea1.bottom+6,m_strMark);
m_strMark.Format("通道一FFT幅值谱");
dc.TextOut(rectSmall.left+200,rectArea2.bottom+6,m_strMark);
m_strMark.Format("通道二采样信号");
dc.TextOut(rectSmall.left+250,rectArea3.bottom+6,m_strMark);
m_strMark.Format("通道二FFT幅值谱");
dc.TextOut(rectSmall.left+200,rectArea4.bottom+6,m_strMark);
m_strMark.Format(" 0 (ms)");
dc.TextOut(rectSmall.left+0-10,rectArea1.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+0-10,rectArea3.bottom+6,m_strMark);
m_strMark.Format("%.2f",100000/(float)m_uRate);
dc.TextOut(rectSmall.left+100-10,rectArea1.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+100-10,rectArea3.bottom+6,m_strMark);
m_strMark.Format("%.2f",200000/(float)m_uRate);
dc.TextOut(rectSmall.left+200-10,rectArea1.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+200-10,rectArea3.bottom+6,m_strMark);
m_strMark.Format("%.2f",400000/(float)m_uRate);
dc.TextOut(rectSmall.left+400-10,rectArea1.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+400-10,rectArea3.bottom+6,m_strMark);
m_strMark.Format("%.2f",500000/(float)m_uRate);
dc.TextOut(rectSmall.left+500-10,rectArea1.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+500-10,rectArea3.bottom+6,m_strMark);
m_strMark.Format(" 0 (Hz)");
dc.TextOut(rectSmall.left+0-20,rectArea2.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+0-20,rectArea4.bottom+6,m_strMark);
m_strMark.Format("%d",m_uRate/8);
dc.TextOut(rectSmall.left+128-20,rectArea2.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+128-20,rectArea4.bottom+6,m_strMark);
m_strMark.Format("%d",3*m_uRate/8);
dc.TextOut(rectSmall.left+384-20,rectArea2.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+384-20,rectArea4.bottom+6,m_strMark);
m_strMark.Format("%d",m_uRate/2);
dc.TextOut(rectSmall.left+512-20,rectArea2.bottom+6,m_strMark);
dc.TextOut(rectSmall.left+512-20,rectArea4.bottom+6,m_strMark);
}
}
void CMyDlg::OnChanelchange()
{
if(m_iChanels==1)
m_iChanels=2;
else
m_iChanels=1;
DrawArea();
::EnableWindow(m_btFFT,false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -