⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.java

📁 IIR带通滤波器设计,提供交互界面,JAVA编写,VJ编译
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;

/**
 * 程序说明:本程序提供两种滤波器的参数设置方式:其一,设置中心频率和3-dB带宽;其二,设置滤波器系统表达式中的
 * 参数α和β;这两种设置方式是相通的,由一组中心频率和带宽可以确定一组α和β,反之亦可。根据不同的需要可以采用
 * 不同的参数设置方式。不管采用何种设置方式,都会进行相应的换算,即由一组数据计算出另一组数据,这样使用就比较方
 * 便;
 */
public class Form1 extends Form
{
	public double alpha,beta;//全局变量,据此算出幅度平方
	
	public Form1()
	{
		// Required for Visual J++ Form Designer support
		initForm();		//初始化,将默认值读入
		
		double omiga0=Double.valueOf(this.edit1.getText()).doubleValue();
		double Bomiga=Double.valueOf(this.edit2.getText()).doubleValue();
		this.beta=Math.cos(omiga0*Math.PI);
		this.alpha=(Bomiga!=0.5)?((1-Math.sin(Bomiga*Math.PI))/Math.cos(Bomiga*Math.PI)):0;
		

		// TODO: Add any constructor code after initForm call
	}

	/**
	 * Form1 overrides dispose so it can clean up the
	 * component list.
	 */
	
	public double H(double omiga){//幅度平方,是关于omiga的函数
		return (1-alpha)*(1-alpha)*(1-Math.cos(2*omiga))/(2*(1+beta*beta*(1+alpha)*(1+alpha)+alpha*alpha-2*beta*(1+alpha)*(1+alpha)*Math.cos(omiga)+2*alpha*Math.cos(2*omiga)));
	}
	
	
	public void dispose()
	{//关闭按钮
		super.dispose();
		components.dispose();
	}

	private void button1_click(Object source, Event e)
	{//帮助按钮(About the Topic)
		new help().showDialog();
	}

	private void button2_click(Object source, Event e)
	{//关于作者按钮(About Me)
		new aboutme().showDialog();
	}

	private void button3_click(Object source, Event e)
	{//介绍相关知识的按钮(Basic Knowledge)
		new basicinfo().showDialog();
	}

	private void button4_click(Object source, Event e)
	{//点击“Observe”按钮执行操作,这是第一种参数设置方式
		try{//读入文本框内的数据,如果输入的不是double型数据,则视为异常,并出现出错提示;
			double omiga0=Double.valueOf(this.edit1.getText()).doubleValue();//读入“中心频率”数据
			double Bomiga=Double.valueOf(this.edit2.getText()).doubleValue();//读入“3-dB带宽”数据
			boolean inputok=true;//输入数据是否合理
			if(omiga0>=1||omiga0<=0){//输入的“中心频率”数据不合理(小于0或者大于1)
				MessageBox.show("Failed to initialize ωo,because 0<ωo<π .Please check carefully and input the correct data.","Error!",MessageBox.ICONERROR);
				inputok=false;//不合理
			}
			if(Bomiga<0||Bomiga>1){//输入的带宽和中心频率之间应该满足的关系:即通带范围应该在0和Pi之间
				MessageBox.show("Failed to initialize Bω,because 0<Bω<π .Please check carefully and input the correct data.","Error!",MessageBox.ICONERROR);				
				inputok=false;//不合理
			}
			if(inputok){//只有输入的数据合理了才进行赋值、画图的操作,否则不理
				this.beta=Math.cos(omiga0*Math.PI);//给β赋值
				this.alpha=(Bomiga!=0.5)?((1-Math.sin(Bomiga*Math.PI))/Math.cos(Bomiga*Math.PI)):0;//给α赋值
				//同时在应该输入α和β的文本框中显示它们的值
				this.edit3.setText(String.valueOf((float)this.beta));
				this.edit4.setText(String.valueOf((float)this.alpha));
				this.panel1.invalidate();//重新绘图
			}
			
		}catch(Exception ee){//异常处理:输入的不是double数据,则显示出错信息
			MessageBox.show("Failed to initialize ωo or Bω.Please check carefully and ensure not to input wrong characters. ","Error!",MessageBox.ICONERROR);
		}
		
	}
	
	private void button5_click(Object source, Event e)
	{//点击“Observe”按钮执行操作,这是第二种参数设置方式
		try{//读入文本框内的数据,如果输入的不是double型数据,则视为异常,并出现出错提示;
			double a=Double.valueOf(this.edit3.getText()).doubleValue();//读入α数据
			double b=Double.valueOf(this.edit4.getText()).doubleValue();//读入β数据
			boolean inputok=true;//输入数据是否合理
			if(Math.abs(a)>=1){//输入的 α不合理:绝对值应该小于1
				MessageBox.show("Failed to initialize α,because |α|<1 .Please check carefully and input the correct data.","Error!",MessageBox.ICONERROR);
				inputok=false;//不合理
			}
			if(Math.abs(b)>=1){//输入的 β不合理:绝对值应该小于1
				MessageBox.show("Failed to initialize β,because because |β|<1  .Please check carefully and input the correct data.","Error!",MessageBox.ICONERROR);				
				inputok=false;//不合理
			}
			if(inputok){//只有输入的数据合理了才进行赋值、画图的操作,否则不理
				this.beta=a;//给β赋值
				this.alpha=b;//给α赋值
				//同时在应该输入中心频率和3-dB带宽的文本框中显示它们的值
				this.edit1.setText(String.valueOf((float)(Math.acos(this.beta)/Math.PI)));
				this.edit2.setText(String.valueOf((float)(Math.acos(2*this.alpha/(1+this.alpha*this.alpha))/Math.PI)));
				this.panel1.invalidate();//重新绘图
			}
			
		}catch(Exception ee){//异常处理:输入的不是double数据,则显示出错信息
			MessageBox.show("Failed to initialize α or β.Please check carefully and ensure not to input wrong characters. ","Error!",MessageBox.ICONERROR);
		}
	}


	private void panel1_paint(Object source, PaintEvent e)
	{//绘图部分:根据α和β的值绘图
		e.graphics.setPen(new Pen(Color.WHITE,PenStyle.DOT,1));//设置画栅格的线型:白色,虚线,1象素宽
		for(int i=0;i<=10;i++){//横向纵向各10个栅格
			 e.graphics.drawLine(0,i*this.panel1.getHeight()/10,this.panel1.getWidth(),i*this.panel1.getHeight()/10);
			 e.graphics.drawLine(i*this.panel1.getWidth()/10,0,i*this.panel1.getWidth()/10,this.panel1.getHeight());
			 }
		double step=Math.PI/this.panel1.getWidth();//设置绘图步长:隔象素画
		e.graphics.setPen(new Pen(Color.GREEN,PenStyle.SOLID,2));//设置绘制数据的线型:绿色、实线,2象素宽
		for(int i=0;i<this.panel1.getWidth();i++){//逐象素画图
			 e.graphics.drawLine(i,this.panel1.getHeight()-(int)(H(i*Math.PI/this.panel1.getWidth())*this.panel1.getHeight()),i+1,this.panel1.getHeight()-(int)(H((i+1)*Math.PI/this.panel1.getWidth())*this.panel1.getHeight()));
		}
	}

	
	

//从此处开始至程序结束,是界面设计部分,代码通过设计器生成
	/**
	 * NOTE: The following code is required by the Visual J++ form
	 * designer.  It can be modified using the form editor.  Do not
	 * modify it using the code editor.
	 */
	Container components = new Container();
	GroupBox groupBox1 = new GroupBox();
	Button button1 = new Button();
	Button button2 = new Button();
	Button button3 = new Button();
	GroupBox groupBox2 = new GroupBox();
	Panel panel1 = new Panel();
	GroupBox groupBox3 = new GroupBox();
	Label label1 = new Label();
	Edit edit1 = new Edit();
	Label label2 = new Label();
	Label label3 = new Label();
	Edit edit2 = new Edit();
	Label label4 = new Label();
	Button button4 = new Button();
	Label label6 = new Label();
	Edit edit3 = new Edit();
	Label label5 = new Label();
	GroupBox groupBox4 = new GroupBox();
	Edit edit4 = new Edit();
	Button button5 = new Button();
	Label label7 = new Label();
	Label label8 = new Label();
	Label label9 = new Label();
	Label label10 = new Label();
	Label label11 = new Label();
	Label label12 = new Label();
	Label label13 = new Label();
	Label label14 = new Label();
	Label label15 = new Label();
	Label label16 = new Label();
	Label label17 = new Label();
	Label label18 = new Label();
	Label label19 = new Label();
	Label label20 = new Label();
	Label label21 = new Label();
	Label label22 = new Label();
	Label label23 = new Label();
	Label label24 = new Label();
	Label label25 = new Label();
	Label label26 = new Label();
	Label label27 = new Label();
	Label label28 = new Label();

	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("Second-order IIR bandpass filter");
		this.setAutoScaleBaseSize(new Point(6, 12));
		this.setBorderStyle(FormBorderStyle.FIXED_DIALOG);
		this.setClientSize(new Point(807, 464));
		this.setIcon((Icon)resources.getObject("this_icon"));
		this.setMaximizeBox(false);
		this.setStartPosition(FormStartPosition.CENTER_SCREEN);

		groupBox1.setLocation(new Point(544, 312));
		groupBox1.setSize(new Point(240, 144));
		groupBox1.setTabIndex(0);
		groupBox1.setTabStop(false);
		groupBox1.setText("information");

		button1.setLocation(new Point(16, 64));
		button1.setSize(new Point(120, 24));
		button1.setTabIndex(0);
		button1.setText("About the &Topic");
		button1.addOnClick(new EventHandler(this.button1_click));

		button2.setLocation(new Point(16, 104));
		button2.setSize(new Point(120, 24));
		button2.setTabIndex(1);
		button2.setText("About &Me");
		button2.addOnClick(new EventHandler(this.button2_click));

		button3.setLocation(new Point(16, 24));
		button3.setSize(new Point(120, 24));
		button3.setTabIndex(2);
		button3.setText("&Basic Knowledge");
		button3.addOnClick(new EventHandler(this.button3_click));

		groupBox2.setLocation(new Point(8, 16));
		groupBox2.setSize(new Point(528, 440));
		groupBox2.setTabIndex(1);
		groupBox2.setTabStop(false);
		groupBox2.setText("Figure");

		panel1.setBackColor(Color.CONTROLTEXT);
		panel1.setLocation(new Point(32, 24));
		panel1.setSize(new Point(480, 384));
		panel1.setTabIndex(0);
		panel1.setText("panel1");
		panel1.addOnPaint(new PaintEventHandler(this.panel1_paint));

		groupBox3.setLocation(new Point(544, 16));
		groupBox3.setSize(new Point(240, 144));
		groupBox3.setTabIndex(2);
		groupBox3.setTabStop(false);
		groupBox3.setText("Setting");

		label1.setLocation(new Point(16, 32));
		label1.setSize(new Point(128, 16));
		label1.setTabIndex(1);
		label1.setTabStop(false);
		label1.setText("center frequency ωo=");

		edit1.setLocation(new Point(144, 32));
		edit1.setSize(new Point(72, 19));
		edit1.setTabIndex(3);
		edit1.setText("0.5");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -