📄 form1.java
字号:
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
public class Form1 extends Form
{
public boolean ok=false;
public int rank;//数字滤波器的阶数
public double Qc;//数字滤波器的截至频率
public complex P[],A[];//(从序号0开始)//记录极点位置;记录系统函数Ha(S)部分分式形式的分解系数;
public complex Br[],Ak[];//标准差分方程的系数参数(从0开始定义)
public double K0;//归一化常数
public Form1()
{
super();
initForm();
}
public void dispose()
{
super.dispose();
components.dispose();
}
private void button3_click(Object source, Event e)
{
new help().showDialog();
}
private void button4_click(Object source, Event e)
{
new aboutme().showDialog();
}
private void button1_click(Object source, Event e)
{
int rankx;//备用,存储计算出来的阶数如果合格就赋值给rank
double Qcx;
iirfilterset myframe=new iirfilterset();
int result=myframe.showDialog();
if(result==DialogResult.OK){
//System.out.print("FUCK!");
double w1=0.01*myframe.trackBar1.getValue()*Math.PI;
double w2=0.01*myframe.trackBar3.getValue()*Math.PI;
double a=0.1*myframe.trackBar2.getValue();
double b=0.1*myframe.trackBar4.getValue();
double nn=(Math.log(Math.pow(10,a/10)-1)-Math.log(Math.pow(10,b/10)-1))/(2*Math.log(w1/w2));
double nnn=nn;
int nnnn=(int)nnn;
double nnnnn=nnnn;
if(nnnnn-nn==0)rankx=(int)nn;
else rankx=(int)(nn+1);
Qcx=w1/Math.pow(Math.pow(10,a/10)-1,1/(double)(2*rankx));
rank=rankx;//合格!接受此值
Qc=Qcx;
MessageBox.show("计算结果:滤波器阶数N="+String.valueOf(rank)+",截止频率Ωc="+String.valueOf(Qc)+'\n'+"祝贺你,滤波器参数初始化成功!","提示",MessageBox.ICONINFORMATION);
//求出极点位置
P=new complex[rank];
K0=1;//归一化常数
for(int i=0;i<rank;i++){
P[i]=new complex();
P[i].Re=Qc*Math.cos(Math.PI*(0.5+(double)(2*i+1)/(double)(2*rank)));
P[i].Im=Qc*Math.sin(Math.PI*(0.5+(double)(2*i+1)/(double)(2*rank)));
//System.out.println("P["+i+"]=("+P[i].Re+")+("+P[i].Im+")");
K0*=Math.sqrt(P[i].Re*P[i].Re+P[i].Im*P[i].Im);
}
this.edit1.setText(String.valueOf(K0));
String s="";
for(int i=0;i<P.length;i++){
s+="[S-("+P[i].Re+((P[i].Im<0)?"-j":"+j")+Math.abs(P[i].Im)+"]";
}
this.edit2.setText(s);
ok=true;
this.panel.invalidate();
}
}
private void panel_paint(Object source, PaintEvent e)
{
if(ok){
int x0=10;
int y0=this.panel.getHeight()-20;
int height=y0-10;
int width=this.panel.getWidth()-x0-10;
//绘制坐标
e.graphics.setPen(new Pen(Color.WHITE,PenStyle.SOLID,2));
for(int i=0;i<=10;i++){//横向10格纵向10格
e.graphics.drawLine(x0,y0-height*i/10,x0+width,y0-height*i/10);//横向
e.graphics.drawLine(x0+width*i/10,y0-height,x0+width*i/10,y0);//纵向
}
//绘制文字
e.graphics.setTextColor(Color.WHITE);
//for(int i=0;i<=5;i++){//纵向写6个
//e.graphics.drawString(String.valueOf(-i*20)+"dB",5,5+height*i/5);
// }
e.graphics.drawString("0",x0-5,y0+5);//纵向写6个
for(int i=1;i<5;i++){
e.graphics.drawString(String.valueOf((float)(0.2*i))+"π",x0+width*i/5-10,5+y0);
}
e.graphics.drawString("π",x0+width-5,y0+5);
//画数据
e.graphics.setPen(new Pen(Color.GREEN,PenStyle.SOLID,2));
double MAX=0;
for(double w=0;w<=Math.PI;w+=0.01){
double xx=K0;
for(int i=0;i<P.length;i++){
xx/=Math.sqrt(P[i].Re*P[i].Re+(w-P[i].Im)*(w-P[i].Im));
}//for
if(Math.abs(10*Math.log(xx))>=MAX){
MAX=Math.abs(10*Math.log(xx));
}
}
for(double w=0;w<=Math.PI;w+=0.01){
double xx=K0;
double nextxx=K0;
for(int i=0;i<P.length;i++){
xx/=Math.sqrt(P[i].Re*P[i].Re+(w-P[i].Im)*(w-P[i].Im));
//if(i<P.length-1){
nextxx/=Math.sqrt(P[i].Re*P[i].Re+((w+0.01)-P[i].Im)*(w+0.01-P[i].Im));
//}
}//for
e.graphics.drawLine(x0+(int)(width*w/Math.PI),10-(int)(10*Math.log(xx)*height/MAX),x0+(int)(width*(w+0.01)/Math.PI),10-(int)(10*Math.log(nextxx)*height/MAX));
}//for
double xx=K0;
for(int i=0;i<P.length;i++) xx/=Math.sqrt(P[i].Re*P[i].Re+(Qc-P[i].Im)*(Qc-P[i].Im));
//e.graphics.
//e.graphics.setPixel(x0+(int)(width*Qc/Math.PI),10-(int)(10*Math.log(xx)*height/100),Color.RED);
e.graphics.setPen(new Pen(Color.RED,PenStyle.SOLID,2));
e.graphics.drawLine(x0+(int)(width*Qc/Math.PI)-2,10-(int)(10*Math.log(xx)*height/MAX)-2,x0+(int)(width*Qc/Math.PI)+2,10-(int)(10*Math.log(xx)*height/MAX)+2);
e.graphics.drawLine(x0+(int)(width*Qc/Math.PI)-2,10-(int)(10*Math.log(xx)*height/MAX)+2,x0+(int)(width*Qc/Math.PI)+2,10-(int)(10*Math.log(xx)*height/MAX)-2);
}
}
private void panel_mouseMove(Object source, MouseEvent e)
{
if(e.x>=10&&e.x<=this.panel.getWidth()-10&&ok){
double xx=K0;
double w=(double)(e.x-10)/(double)(this.panel.getWidth()-20)*Math.PI;
for(int i=0;i<P.length;i++)
xx/=Math.sqrt(P[i].Re*P[i].Re+(w-P[i].Im)*(w-P[i].Im));
xx=10*Math.log(xx);
this.toolTip1.setToolTip(panel,"ω="+String.valueOf((float)(e.x-10)/(float)(this.panel.getWidth()-20))+"π,Hdb(ω)="+xx+"dB");
}
}
Container components = new Container();
Button button1 = new Button();
GroupBox groupBox3 = new GroupBox();
Button button4 = new Button();
StatusBarPanel statusBarPanel1 = new StatusBarPanel();
StatusBarPanel statusBarPanel2 = new StatusBarPanel();
StatusBarPanel statusBarPanel3 = new StatusBarPanel();
StatusBarPanel statusBarPanel4 = new StatusBarPanel();
StatusBarPanel statusBarPanel5 = new StatusBarPanel();
StatusBarPanel statusBarPanel6 = new StatusBarPanel();
StatusBarPanel statusBarPanel7 = new StatusBarPanel();
GroupBox groupBox1 = new GroupBox();
Button button3 = new Button();
GroupBox groupBox2 = new GroupBox();
Label label1 = new Label();
Label label2 = new Label();
Edit edit1 = new Edit();
Edit edit2 = new Edit();
GroupBox groupBox4 = new GroupBox();
Panel panel = new Panel();
ToolTip toolTip1 = new ToolTip(components);
private void initForm()
{
// NOTE: This form is storing resource information in an
// external file. Do not modify the string parameter to any
// resources.getObject() function call. For example, do not
// modify "foo1_location" in the following line of code
// even if the name of the Foo object changes:
// foo1.setLocation((Point)resources.getObject("foo1_location"));
IResourceManager resources = new ResourceManager(this, "Form1");
this.setText("Design of butterworth filter");
this.setAutoScaleBaseSize(new Point(6, 12));
this.setBorderStyle(FormBorderStyle.FIXED_DIALOG);
this.setClientSize(new Point(840, 455));
this.setIcon((Icon)resources.getObject("this_icon"));
this.setMaximizeBox(false);
this.setMinimizeBox(false);
this.setStartPosition(FormStartPosition.CENTER_SCREEN);
button1.setLocation(new Point(40, 40));
button1.setSize(new Point(168, 24));
button1.setTabIndex(0);
button1.setText("Low-pass filter setting");
button1.addOnClick(new EventHandler(this.button1_click));
groupBox3.setLocation(new Point(592, 304));
groupBox3.setSize(new Point(240, 144));
groupBox3.setTabIndex(2);
groupBox3.setTabStop(false);
groupBox3.setText("information");
button4.setLocation(new Point(40, 80));
button4.setSize(new Point(168, 24));
button4.setTabIndex(0);
button4.setText("&About Me");
button4.addOnClick(new EventHandler(this.button4_click));
statusBarPanel1.setText("statusBarPanel1");
statusBarPanel2.setText("statusBarPanel2");
statusBarPanel3.setText("statusBarPanel3");
statusBarPanel4.setText("statusBarPanel4");
statusBarPanel5.setText("statusBarPanel5");
statusBarPanel6.setText("statusBarPanel6");
statusBarPanel7.setText("statusBarPanel7");
groupBox1.setLocation(new Point(592, 8));
groupBox1.setSize(new Point(240, 120));
groupBox1.setTabIndex(0);
groupBox1.setTabStop(false);
groupBox1.setText("setting");
button3.setLocation(new Point(40, 32));
button3.setSize(new Point(168, 24));
button3.setTabIndex(1);
button3.setText("About the &Topic");
button3.addOnClick(new EventHandler(this.button3_click));
groupBox2.setLocation(new Point(592, 144));
groupBox2.setSize(new Point(240, 144));
groupBox2.setTabIndex(1);
groupBox2.setTabStop(false);
groupBox2.setText("transfer function");
label1.setLocation(new Point(16, 24));
label1.setSize(new Point(88, 16));
label1.setTabIndex(0);
label1.setTabStop(false);
label1.setText("H(S)=R(S)/E(S)");
label2.setLocation(new Point(40, 80));
label2.setSize(new Point(192, 16));
label2.setTabIndex(1);
label2.setTabStop(false);
label2.setText("=-----------------------------------------");
edit1.setLocation(new Point(48, 40));
edit1.setSize(new Point(184, 40));
edit1.setTabIndex(3);
edit1.setText("");
edit1.setMultiline(true);
edit1.setReadOnly(true);
edit1.setScrollBars(ScrollBars.HORIZONTAL);
edit2.setLocation(new Point(48, 88));
edit2.setSize(new Point(184, 40));
edit2.setTabIndex(2);
edit2.setText("");
edit2.setMultiline(true);
edit2.setReadOnly(true);
edit2.setScrollBars(ScrollBars.HORIZONTAL);
groupBox4.setLocation(new Point(8, 8));
groupBox4.setSize(new Point(576, 440));
groupBox4.setTabIndex(3);
groupBox4.setTabStop(false);
groupBox4.setText("figure of gain response");
panel.setBackColor(Color.CONTROLTEXT);
panel.setLocation(new Point(8, 16));
panel.setSize(new Point(560, 408));
panel.setTabIndex(0);
panel.setText("panel1");
panel.addOnMouseMove(new MouseEventHandler(this.panel_mouseMove));
panel.addOnPaint(new PaintEventHandler(this.panel_paint));
toolTip1.setAutoPopDelay(5000);
toolTip1.setInitialDelay(500);
toolTip1.setReshowDelay(0);
toolTip1.setShowAlways(true);
toolTip1.setActivate(true);
toolTip1.setToolTip(panel, "hhh");
/* @designTimeOnly toolTip1.setLocation(new Point(112, 256)); */
this.setNewControls(new Control[] {
groupBox4,
groupBox3,
groupBox2,
groupBox1});
groupBox3.setNewControls(new Control[] {
button4,
button3});
groupBox1.setNewControls(new Control[] {
button1});
groupBox2.setNewControls(new Control[] {
edit2,
edit1,
label2,
label1});
groupBox4.setNewControls(new Control[] {
panel});
}
public static void main(String args[])
{
Application.run(new Form1());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -