📄 firfilterdlg.cpp
字号:
CDC *PCDC;
CPen Dot_pen(PS_DOT,0,RGB(0,0,0));
CPen Dot_penCenter(PS_DOT,0,RGB(0,0,255));
CPen Solid_pen(PS_SOLID,0,RGB(0,0,0));
// CString str;
pwnd=GetDlgItem(IDC_PICTURE);
PCDC=pwnd->GetDC();
CBrush brwhite(RGB(255,255,255));
CRect rect1;
pwnd->GetClientRect(rect1);
PCDC->SelectObject(&Solid_pen); //选入设备环境
PCDC->FillRect(rect1,&brwhite);
//画边框
PCDC->MoveTo(rect1.left,rect1.top);
PCDC->LineTo(rect1.right,rect1.top);
PCDC->MoveTo(rect1.right,rect1.top);
PCDC->LineTo(rect1.right,rect1.bottom);
PCDC->MoveTo(rect1.left,rect1.bottom);
PCDC->LineTo(rect1.right,rect1.bottom);
PCDC->MoveTo(rect1.left,rect1.top);
PCDC->LineTo(rect1.left,rect1.bottom);
PCDC->SelectObject(&Dot_penCenter); //选入设备环境
//PCDC->FillRect(rect1,&brwhite);
int CenterLinePos= (rect1.bottom-rect1.top)/2;
PCDC->MoveTo(rect1.left,CenterLinePos);
PCDC->LineTo(rect1.right,CenterLinePos);
//画框内的网格
//将X和Y坐标分别等分为N1和N2份
width=(int)((rect1.right-rect1.left)/30);
height=(int)((rect1.bottom-rect1.top)/30);
PCDC->SelectObject(&Dot_pen); //选入设备环境
//画中心线上方的横线
m=CenterLinePos;
for(i=1;i<=height/2;i++)
{
m-=30;
if(m > rect1.top)
{
PCDC->MoveTo(0,m);
PCDC->LineTo(rect1.right-rect1.left,m);
}
}
//画中心线下方的横线
m=CenterLinePos;
for(i=1;i<=height/2;i++)
{
m+=30;
if(m < rect1.bottom)
{
PCDC->MoveTo(0,m);
PCDC->LineTo(rect1.right-rect1.left,m);
}
}
//画竖线
for(i=1;i<=width;i++)
{
n+=30;
PCDC->MoveTo(n,0);
PCDC->LineTo(n,rect1.bottom-rect1.top);
}
PCDC->SetBkColor(RGB(255,0,255)); //设置的是文字的背景颜色
PCDC->SetTextColor(RGB(0,0,0));
PCDC->TextOut(0,0,"正弦输入信号加干扰噪声");
// PCDC->TextOut(rect1.left-20,(int)((rect1.bottom-rect1.top)/2),"0.0");
}
/****************************画正弦加干扰信号波形控件的刻度函数*************************************/
void CFIRFilterDlg::DrawScale()
{
// TODO: Add your control notification handler code here
int width=0,height=0,i=0,n=0;
CWnd *pwnd;
CDC *PCDC;
CFont m_ScaleFont;
CString str;
m_ScaleFont.CreateFont(15,0,0,0,FW_THIN,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial");
pwnd=GetDlgItem(IDC_PICTURE);
PCDC=pwnd->GetDC();
CRect rect2;
pwnd->GetClientRect(rect2);
PCDC->SelectObject(&m_ScaleFont);
PCDC->SetTextColor(RGB(0,0,0));
PCDC->SetBkMode(TRANSPARENT);
PCDC->SetTextAlign(TA_RIGHT|TA_BASELINE);
//画坐标原点
PCDC->TextOut(rect2.left-2,(int)((rect2.bottom-rect2.top)/2)+5,"0.0");
width=(int)((rect2.right-rect2.left)/30);
height=(int)((rect2.bottom-rect2.top)/30);
/**************画正半轴***************************/
for(i=1;i<=height/2;i++)
{
int nPosY1=(rect2.bottom-rect2.top)/2- i*30;
if(nPosY1 >rect2.top)
{
str.Format("%.1f",i*1.0);
PCDC->TextOut(rect2.left-2,nPosY1+5,str);
}
}
/************画负半轴**************************/
for(i=1;i<=height/2;i++)
{
int nPosY2=(rect2.bottom-rect2.top)/2 + i*30;
if(nPosY2 < rect2.bottom)
{
str.Format("%.1f",-i*1.0);
PCDC->TextOut(rect2.left-2,nPosY2+5,str);
}
}
/************画时间轴的坐标刻度***************/
PCDC->SetTextAlign(TA_LEFT|TA_TOP);
PCDC->TextOut(rect2.left-2,rect2.bottom+2,CString("0"));//刻度规定原点
PCDC->SetTextAlign(TA_CENTER|TA_TOP);
for(i=1;i<=width;i++)
{
n+=30;
str.Format("%d",i*20);
PCDC->TextOut(n+2,rect2.bottom+2,str);
}
}
/***********************************获取正弦曲线数据的函数***************************************/
void CFIRFilterDlg::GetSinData(int N, int M,double T,Complex dataout[]) //获得正弦曲线的数据
{
int i;
double temp;
temp=2.0*PI*T/(double)N;
// double disturbT=(double)disturbperiod/10.0;
// double disturbtemp=2.0*PI*disturbT/(double)N;
double max=(double) amplitude/10.0;
//CString str;
//CString str2;
//GetDlgItemText(IDC_EDIT_DISTURBAMP,str);
// GetDlgItemText(IDC_EDIT_DISTURBPER,str2);
//disturbamp = atoi(str);
//disturbper = atoi(str2);
double disturbmax = disturbamp;
for(i=1;i<=M;i++)
{
dataout[i].real=max*sin(temp*(double)i) + disturbmax * sin(disturbper*(double)i);
//+ 1.5*sin(2.0*PI*0.1*(double)i);
// //可以在此处加上噪声信号
dataout[i].image=0;
}
}
/*********************************画正弦加干扰信号曲线波形的函数************************************/
void CFIRFilterDlg::DrawSinWave(int N, int M,Complex data[]) //data1[]中存放的是正弦曲线的的数据
{
CWnd *pwnd=GetDlgItem(IDC_PICTURE);
CDC *PCDC=pwnd->GetDC();
CRect rect3;
pwnd->GetClientRect(rect3);
CPen backpen1(PS_SOLID,1,RGB(0,0,0));
CPen *pold1=NULL;
pold1=PCDC->SelectObject(&backpen1);
double temp1,temp2;
int i,width,height,BaseLine;
height=rect3.bottom-rect3.top;
width=rect3.right-rect3.left;
BaseLine=(int)((rect3.bottom-rect3.top)/2);
/* double maxtemp=0.0,temp;
for(i=1;i<=N;i++)
{
temp=(data[i].real>0)?data[i].real:(0-data[i].real);
if(temp>=maxtemp)
maxtemp=temp;
}
*/
double step=(double)(width-10)/N; //由于控件的宽度为380,所以要将N个采样点放入空间内,要计算步长
// double stepcols=(double)(height/2-10)/maxtemp;
for(i=1;i<M;i++)
{
temp1=data[i].real; //将正弦曲线的数据不停的赋给temp变量
temp2=data[i+1].real;
int x1=(int)(step*(i-1));
int y1=BaseLine- (int)(temp1*30); //这样显示的y是没有刻度的,如果有刻度应该怎么办呢?
int x2=(int)(step*i);
int y2=BaseLine-(int)(temp2*30);
if(x1 < rect3.right && x2 < rect3.right && y1 < rect3.bottom && y1 > rect3.top && y2 < rect3.bottom && y2 > rect3.top)
{
PCDC->MoveTo(x1,y1);
PCDC->LineTo(x2,y2);
}
}
}
void CFIRFilterDlg::DrawOriginalSinWave()
{
// TODO: Add your control notification handler code here
int N=200; //序列长度,T/N是序列的周期,通过改变N和T可以改变频率
int M=1024;
//double T=0.0;
double T=(double)period/10.0;
// double noiseperiod=(double)noiper/10.0;
Complex *x=new Complex[1024];
int i;
double temp;
temp=2.0*PI*T/(double)N;
// double disturbT=(double)disturbperiod/10.0;
// double disturbtemp=2.0*PI*disturbT/(double)N;
double max=(double) amplitude/10.0;
double disturbmax = disturbamp/10.0;
for(i=1;i<=M;i++)
{
x[i].real=max*sin(temp*(double)i); //+ disturbmax*sin(disturbper*(double)i);
//+ 1.5*sin(2.0*PI*0.1*(double)i);
// //可以在此处加上噪声信号
x[i].image=0;
}
CWnd *pwnd=GetDlgItem(IDC_ORIGINAL_SINGAL);
CDC *PCDC=pwnd->GetDC();
// CRect rect3;
// pwnd->GetClientRect(rect3);
/****************画网格的程序段*************************/
int nwidth=0,nheight=0,m=0,n=0;
CPen Dot_pen(PS_DOT,0,RGB(0,0,0));
CPen Dot_penCenter(PS_DOT,0,RGB(0,0,255));
CPen Solid_pen(PS_SOLID,0,RGB(0,0,0));
// CString str;
CBrush brwhite(RGB(255,255,255));
CRect rect1;
pwnd->GetClientRect(rect1);
PCDC->SelectObject(&Solid_pen); //选入设备环境
PCDC->FillRect(rect1,&brwhite);
//画边框
PCDC->MoveTo(rect1.left,rect1.top);
PCDC->LineTo(rect1.right,rect1.top);
PCDC->MoveTo(rect1.right,rect1.top);
PCDC->LineTo(rect1.right,rect1.bottom);
PCDC->MoveTo(rect1.left,rect1.bottom);
PCDC->LineTo(rect1.right,rect1.bottom);
PCDC->MoveTo(rect1.left,rect1.top);
PCDC->LineTo(rect1.left,rect1.bottom);
PCDC->SelectObject(&Dot_penCenter); //选入设备环境
//PCDC->FillRect(rect1,&brwhite);
int CenterLinePos= (rect1.bottom-rect1.top)/2;
PCDC->MoveTo(rect1.left,CenterLinePos);
PCDC->LineTo(rect1.right,CenterLinePos);
//画框内的网格
//将X和Y坐标分别等分为N1和N2份
nwidth=(int)((rect1.right-rect1.left)/30);
nheight=(int)((rect1.bottom-rect1.top)/30);
PCDC->SelectObject(&Dot_pen); //选入设备环境
//画中心线上方的横线
m=CenterLinePos;
for(i=1;i<=nheight/2;i++)
{
m-=30;
if(m > rect1.top)
{
PCDC->MoveTo(0,m);
PCDC->LineTo(rect1.right-rect1.left,m);
}
}
//画中心线下方的横线
m=CenterLinePos;
for(i=1;i<=nheight/2;i++)
{
m+=30;
if(m < rect1.bottom)
{
PCDC->MoveTo(0,m);
PCDC->LineTo(rect1.right-rect1.left,m);
}
}
//画竖线
for(i=1;i<=nwidth;i++)
{
n+=30;
PCDC->MoveTo(n,0);
PCDC->LineTo(n,rect1.bottom-rect1.top);
}
PCDC->SetBkColor(RGB(255,0,255)); //设置的是文字的背景颜色
PCDC->SetTextColor(RGB(0,0,0));
PCDC->TextOut(0,0,"原始输入信号波形");
/******************************画刻度的程序段***************************/
CFont m_ScaleFont;
CString str;
m_ScaleFont.CreateFont(15,0,0,0,FW_THIN,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial");
PCDC->SelectObject(&m_ScaleFont);
PCDC->SetTextColor(RGB(0,0,0));
PCDC->SetBkMode(TRANSPARENT);
PCDC->SetTextAlign(TA_RIGHT|TA_BASELINE);
//画坐标原点
PCDC->TextOut(rect1.left-2,(int)((rect1.bottom-rect1.top)/2)+5,"0.0");
/**************画正半轴********************/
for(i=1;i<=nheight/2;i++)
{
int nPosY1=(rect1.bottom-rect1.top)/2- i*30;
if(nPosY1 >rect1.top)
{
str.Format("%.1f",i*1.0);
PCDC->TextOut(rect1.left-2,nPosY1+5,str);
}
}
/************画负半轴*******************/
for(i=1;i<=nheight/2;i++)
{
int nPosY2=(rect1.bottom-rect1.top)/2 + i*30;
if(nPosY2 < rect1.bottom)
{
str.Format("%.1f",-i*1.0);
PCDC->TextOut(rect1.left-2,nPosY2+5,str);
}
}
/************画时间轴的坐标刻度**********/
PCDC->SetTextAlign(TA_LEFT|TA_TOP);
PCDC->TextOut(rect1.left-1,rect1.bottom+2,CString("0"));//刻度规定原点
PCDC->SetTextAlign(TA_CENTER|TA_TOP);
n=0;
for(i=1;i<=nwidth;i++)
{
n+=30;
str.Format("%d",i*20);
PCDC->TextOut(n+2,rect1.bottom+2,str);
}
/*********************画原始的正弦波形*********************/
CPen backpen1(PS_SOLID,1,RGB(0,0,0));
CPen *pold1=NULL;
pold1=PCDC->SelectObject(&backpen1);
double temp1,temp2;
int width,height,BaseLine;
height=rect1.bottom-rect1.top;
width=rect1.right-rect1.left;
BaseLine=(int)((rect1.bottom-rect1.top)/2);
/* double maxtemp=0.0,temp;
for(i=1;i<=N;i++)
{
temp=(data[i].real>0)?data[i].real:(0-data[i].real);
if(temp>=maxtemp)
maxtemp=temp;
}
*/
double step=(double)(width-10)/N; //由于控件的宽度为380,所以要将N个采样点放入空间内,要计算步长
// double stepcols=(double)(height/2-10)/maxtemp;
for(i=1;i<N;i++)
{
temp1=x[i].real; //将正弦曲线的数据不停的赋给temp变量
temp2=x[i+1].real;
int x1=(int)(step*(i-1));
int y1=BaseLine- (int)(temp1*30); //这样显示的y是没有刻度的,如果有刻度应该怎么办呢?
int x2=(int)(step*i);
int y2=BaseLine-(int)(temp2*30);
if(x1 < rect1.right && x2 < rect1.right && y1 < rect1.bottom && y1 > rect1.top && y2 < rect1.bottom && y2 > rect1.top)
{
PCDC->MoveTo(x1,y1);
PCDC->LineTo(x2,y2);
}
}
}
/*******************************正弦加干扰噪声信号的频谱******************************************/
void CFIRFilterDlg::DrawInPic2(int N, Complex data1[]) //这里面的程序可能有点问题,画出的频谱图不正确
{
CWnd *pwnd=GetDlgItem(IDC_WAVESPECTRUM);
CDC *PCDC=pwnd->GetDC();
CRect rect1;
pwnd->GetClientRect(rect1);
CBrush brwhite(RGB(255,255,255));
PCDC->FillRect(rect1,&brwhite);
/****************画网格的程序段*************************/
int nwidth=0,nheight=0,i=0,m=0,n=0;
CPen Dot_pen(PS_DOT,0,RGB(0,0,0));
CPen Dot_penCenter(PS_DOT,0,RGB(0,0,255));
CPen Solid_pen(PS_SOLID,0,RGB(0,0,0));
// CString str;
// CBrush brwhite(RGB(255,255,255));
// CRect rect1;
// pwnd->GetClientRect(rect1);
PCDC->SelectObject(&Solid_pen); //选入设备环境
// PCDC->FillRect(rect1,&brwhite);
//画边框
PCDC->MoveTo(rect1.left,rect1.top);
PCDC->LineTo(rect1.right,rect1.top);
PCDC->MoveTo(rect1.right,rect1.top);
PCDC->LineTo(rect1.right,rect1.bottom);
PCDC->MoveTo(rect1.left,rect1.bottom);
PCDC->LineTo(rect1.right,rect1.bottom);
PCDC->MoveTo(rect1.left,rect1.top);
PCDC->LineTo(rect1.left,rect1.bottom);
PCDC->SelectObject(&Dot_penCenter); //选入设备环境
//PCDC->FillRect(rect1,&brwhite);
int CenterLinePos= (rect1.bottom-rect1.top)/2;
PCDC->MoveTo(rect1.left,CenterLinePos);
PCDC->LineTo(rect1.right,CenterLinePos);
//画框内的网格
//将X和Y坐标分别等分为N1和N2份
nwidth=(int)((rect1.right-rect1.left)/30);
nheight=(int)((rect1.bottom-rect1.top)/30);
PCDC->SelectObject(&Dot_pen); //选入设备环境
//画中心线上方的横线
m=CenterLinePos;
for(i=1;i<=nheight/2;i++)
{
m-=30;
if(m > rect1.top)
{
PCDC->MoveTo(0,m);
PCDC->LineTo(rect1.right-rect1.left,m);
}
}
//画中心线下方的横线
m=CenterLinePos;
for(i=1;i<=nheight/2;i++)
{
m+=30;
if(m < rect1.bottom)
{
PCDC->MoveTo(0,m);
PCDC->LineTo(rect1.right-rect1.left,m);
}
}
//画竖线
for(i=1;i<=nwidth;i++)
{
n+=30;
PCDC->MoveTo(n,0);
PCDC->LineTo(n,rect1.bottom-rect1.top);
}
/***************画波形的程序段*******************/
// CWnd *pwnd=GetDlgItem(IDC_WAVESPECTRUM);
// CDC *PCDC=pwnd->GetDC();
CPen backpen1(PS_SOLID,1,RGB(0,0,0));
CPen *pold1=NULL;
pold1=PCDC->SelectObject(&backpen1);
double temp,temp1,temp2;
double maxtemp=0.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -