📄 firfilterdlg.cpp
字号:
inputdata2[i].image=0.0;
}
}
/*********************************画数字滤波器单位脉冲响应波形的函数 *****************************/
void CFIRFilterDlg::DrawSYS1(int N, Complex data1[]) //此函数在FirFunction()中被调用
{
CWnd *pwnd=GetDlgItem(IDC_SYSRESPONSE);
CDC *PCDC=pwnd->GetDC();
/****************画网格的程序段*************************/
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);
}
/******************画波形的程序段******************************/
CPen backpen1(PS_SOLID,0,RGB(0,0,0));
// CBrush brwhite(RGB(255,255,255)); //定义白色的画刷,清除前次显示
CPen *pold1=NULL;
pold1=PCDC->SelectObject(&backpen1);
// PCDC->FillRect(rect1,&brwhite);
// int i;
double temp,temp1,temp2;
double maxtemp=0;
for(i=1;i<=N;i++)
{
temp=(data1[i].real>0)?data1[i].real:(0-data1[i].real);
if(temp >= maxtemp)
maxtemp=temp;
}
double stepcols;
int centerline=(rect1.bottom-rect1.top)/2;
int width=rect1.right-rect1.left;
int height=rect1.bottom-rect1.top;
stepcols=(double)centerline/maxtemp;
for(i=1;i<=N;i++)
{
temp1=data1[i].real;
temp2=data1[i+1].real;
double step=width/N; //一定要放在循环的里面,否者 N做分母可能为零 与 edit控件中的windowlength变量有关,其值可能为零
int x1=(int)(20+step*(i-1));
int y1=centerline- (int)(temp1*stepcols);
int x2=(int)(20+step*i);
int y2=centerline-(int)(temp2*stepcols);
//PCDC->MoveTo(x,centerline);
PCDC->MoveTo(x1,y1);
PCDC->LineTo(x2,y2);
}
PCDC->SetBkColor(RGB(255,0,255)); //设置的是文字的背景颜色
PCDC->SetTextColor(RGB(0,0,0));
PCDC->TextOut(0,0,"数字滤波器的");
PCDC->TextOut(0,15,"单位脉冲响应");
}
/*********************************画数字滤波器幅频响应波形的函数 *****************************/
void CFIRFilterDlg::DrawSYS3(int N, Complex data1[]) //此函数在FirFunction()中被调用
{
CWnd *pwnd=GetDlgItem(IDC_AMPLITUDE_FRERES);
CDC *PCDC=pwnd->GetDC();
// CRect rect1;
// pwnd->GetClientRect(rect1);
/****************画网格的程序段*************************/
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);
}
/******************画波形的程序段******************************/
CPen backpen1(PS_SOLID,1,RGB(0,0,0));
// CBrush brwhite(RGB(255,255,255));
CPen *pold1=NULL;
pold1=PCDC->SelectObject(&backpen1);
// PCDC->FillRect(rect1,&brwhite);
// int i;
double relay[602];
Complex mm;
double power=0.0;
double X[602];
for(i = 1; i <= 601; i++)
{
mm.real = 0.0;
mm.image = 0.0;
double W = ((double)(i-1) * (double)2 * PI) / 601;
for(int j = 1; j <= N; j++)
{
mm.real += data1[j].real * cos(W * (double)j);
mm.image += data1[j].real * sin(-W * (double)j);
}
relay[i] = sqrt(mm.real * mm.real + mm.image * mm.image);
power += relay[i] * relay[i];
}
double max=0.0,maxtemp=0.0;
for(i=1;i<=601;i++)
{
relay[i] /= power;
if(relay[i] > max)
max = relay[i];
}
for(i = 1; i <= 601; i++)
{
X[i] = (double)20 * log(relay[i] / max);
X[i]/=200.0;
double temp;
temp=(X[i]>0)?X[i]:-X[i];
if(temp > maxtemp)
maxtemp = temp;
}
int width=rect1.right-rect1.left;
int height=rect1.bottom-rect1.top;
double stepcols;
stepcols=(double)(height-20)/maxtemp;
double step=(double)(width-20)/300.0;
for(i=1;i<=300;i++)
{
int x1=(int)(step*(i-1));
int y1=20- (int)(X[i]*stepcols);
int x2=(int)(step*i);
int y2=20- (int)(X[i+1]*stepcols);
PCDC->MoveTo(x1,y1);
PCDC->LineTo(x2,y2);
}
PCDC->SetBkColor(RGB(255,0,255)); //设置的是文字的背景颜色
PCDC->SetTextColor(RGB(0,0,0));
PCDC->TextOut(0,0,"数字滤波器的幅频响应");
}
/********************************计算卷积的函数*************************************************/
void CFIRFilterDlg::myconv(Complex A[], Complex B[], Complex C[], int N) //此函数在FirFunction()中被调用
{
int pointtemp=N;
int ffttime=0;
int i;
while(pointtemp!=0)
{
pointtemp/=2;
ffttime++;
}
ffttime--;
if(N>pow(2,ffttime))
{
ffttime++;
}
for(i=200+1;i<=pow(2,ffttime);i++)
{
A[i].real=0;
A[i].image=0;
}
for(i=windowlength+1;i<=pow(2,ffttime);i++)
{
B[i].real=0;
B[i].image=0;
}
int pointnum1=(int)pow(2,ffttime);
FFT(pointnum1,ffttime,A);
FFT(pointnum1,ffttime,B);
for(i=1;i<=pointnum1;i++)
{
C[i].real=(A[i].real*B[i].real-A[i].image*B[i].image)/(double)pointnum1;
C[i].image=0.0-(A[i].real*B[i].image+A[i].image*B[i].real)/(double)pointnum1;
}
FFT(pointnum1,ffttime,C);
for(i=1;i<=pointnum1;i++)
{
C[i].image-=0.0;
}
}
/**************************干扰信号幅值改变的消息响应函数********************************************/
void CFIRFilterDlg::OnChangeEditDisturbamp()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::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);
disturbamp=atof(m_disturbamp);
/*CString str;
GetDlgItemText(IDC_EDIT_DISTURBAMP,str);
disturbamp = atof(str);*/
// DrawCoordinate();
// CCordinateDlg::OnDrawScale();
// CCordinateDlg::OnGetsindata();
// CCordinateDlg::OnSpectrumdisplay();
MainFunction();
UpdateData(FALSE);
}
/**************************干扰信号频率改变的消息响应函数********************************************/
void CFIRFilterDlg::OnChangeEditDisturbper()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::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);
disturbper=atof(m_disturbper);
/*CString str;
GetDlgItemText(IDC_EDIT_DISTURBPER,str);
disturbper = atoi(str);*/
// DrawCoordinate();
// CCordinateDlg::OnDrawScale();
// CCordinateDlg::OnGetsindata();
// CCordinateDlg::OnSpectrumdisplay();
MainFunction();
UpdateData(FALSE);
}
/**************************滤波器类型改变的消息响应函数********************************************/
void CFIRFilterDlg::OnSelchangeFilterType()
{
// TODO: Add your control notification handler code here
if(m_filter_type.GetCurSel()<=1)
{
//m_PL="截止频率:";
m_cutmsg="Cutoff frequency";
m_unitcut="rad";
CWnd *pWnd=GetDlgItem(IDC_CUTOFF_FREQUENCY);
pWnd->ShowWindow(SW_SHOW);
//m_PL1="";
//m_phase1_msg="";
m_lowcutmsg="";
m_unitlowcut="";
pWnd=GetDlgItem(IDC_LOW_CUTFREQUENCY);
pWnd->ShowWindow(SW_HIDE);
//m_PL2="";
//m_phase2_msg="";
m_highcutmsg="";
m_unithighcut="";
pWnd=GetDlgItem(IDC_HIGH_CUTFREQUENCY);
pWnd->ShowWindow(SW_HIDE);
UpdateData(false);
}
else
{
//m_PL="";
//m_phase_msg="";
m_cutmsg="";
m_unitcut="";
CWnd *pWnd=GetDlgItem(IDC_CUTOFF_FREQUENCY);
pWnd->ShowWindow(SW_HIDE);
//m_PL1="频率1:";
m_lowcutmsg="Low cutoff frequency";
m_unitlowcut="rad";
pWnd=GetDlgItem(IDC_LOW_CUTFREQUENCY);
pWnd->ShowWindow(SW_SHOW);
//m_PL2="频率2:";
m_highcutmsg="High cutoff frequency";
m_unithighcut="rad";
pWnd=GetDlgItem(IDC_HIGH_CUTFREQUENCY);
pWnd->ShowWindow(SW_SHOW);
UpdateData(false);
UpdateData(false);
}
MainFunction();
}
/**************************窗函数类型改变的消息响应函数********************************************/
void CFIRFilterDlg::OnSelchangeWindowType()
{
// TODO: Add your control notification handler code here
MainFunction();
}
/**************************截止频率改变的消息响应函数********************************************/
void CFIRFilterDlg::OnChangeCutoffFrequency()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::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);
double temp_cutofffrequency=atof(m_cutoff_frequency);
cutofffrequency = (int)(temp_cutofffrequency * 100 / PI);
/*CString str;
GetDlgItemText(IDC_EDIT_DISTURBAMP,str);
disturbamp = atof(str);*/
/*DrawCoordinate();
CCordinateDlg::OnDrawScale();
CCordinateDlg::OnGetsindata();
CCordinateDlg::OnSpectrumdisplay(); */
MainFunction();
UpdateData(FALSE);
}
/**************************低通截止频率改变的消息响应函数********************************************/
void CFIRFilterDlg::OnChangeLowCutfrequency()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::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);
double temp_lowcutfrequency=atof(m_low_cutfrequency);
lowcutfrequency = (int)(temp_lowcutfrequency * 100 / PI);
/*CString str;
GetDlgItemText(IDC_EDIT_DISTURBAMP,str);
disturbamp = atof(str);*/
/*DrawCoordinate();
CCordinateDlg::OnDrawScale();
CCordinateDlg::OnGetsindata();
CCordinateDlg::OnSpectrumdisplay(); */
MainFunction();
UpdateData(FALSE);
}
/**************************高通截止频率改变的消息响应函数********************************************/
void CFIRFilterDlg::OnChangeHighCutfrequency()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::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);
double temp_highcutfrequency=atof(m_high_cutfrequency);
highcutfrequency =(int)(temp_highcutfrequency * 100 / PI);
/*CString str;
GetDlgItemText(IDC_EDIT_DISTURBAMP,str);
disturbamp = atof(str);*/
/*DrawCoordinate();
CCordinateDlg::OnDrawScale();
CCordinateDlg::OnGetsindata();
CCordinateDlg::OnSpectrumdisplay(); */
MainFunction();
UpdateData(FALSE);
}
/**************************窗口长度改变的消息响应函数********************************************/
void CFIRFilterDlg::OnChangeWindowLength()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::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);
int windowlength=atoi(m_window_length);
/*CString str;
GetDlgItemText(IDC_EDIT_DISTURBAMP,str);
disturbamp = atof(str);*/
/*DrawCoordinate();
CCordinateDlg::OnDrawScale();
CCordinateDlg::OnGetsindata();
CCordinateDlg::OnSpectrumdisplay(); */
MainFunction();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -