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

📄 crosszeroo.java

📁 ptolemyModel嵌入式系统建模实例代码
💻 JAVA
字号:
/* An actor the short time crossing zero frequency of a frame voice.*/

package ptolemy.actor.lib;

import ptolemy.actor.IOPort;
import ptolemy.actor.TypedIOPort;
import ptolemy.data.Token;
//import ptolemy.data.BooleanToken;
import ptolemy.data.IntToken;
import ptolemy.data.DoubleToken;
import ptolemy.data.ScalarToken;
import ptolemy.data.expr.Parameter;
import ptolemy.data.type.BaseType;
import ptolemy.data.type.Type;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.*;

//////////////////////////////////////////////////////////////////////////
//// CrossZeroO
/* Computing the short time crossing zero frequency of a frame voice.*/


public class CrossZeroO extends Transformer {

    /** Construct an actor with the given container and name.
     *  @param container The container.
     *  @param name The name of this actor.
     *  @exception IllegalActionException If the actor cannot be contained
     *   by the proposed container.
     *  @exception NameDuplicationException If the container already has an
     *   actor with this name.
     */
    public CrossZeroO(CompositeEntity container, String name)
            throws NameDuplicationException, IllegalActionException  {
        super(container, name);

		Z_out= new TypedIOPort(this, "Z_out", false, true);  
       
        W_Size=new Parameter(this ,"W_Size",new IntToken(256));
	    //NoiseMin=new Parameter(this ,"NoiseMin",new DoubleToken(0.064));
        //NoiseMax=new Parameter(this,"NoiseMax",new DoubleToken(0.145));

	    // set the type constraints.

	    W_Size.setTypeEquals(BaseType.INT);
        Z_out.setTypeEquals(BaseType.DOUBLE);  
        output.setTypeAtLeast(input);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    
       public Parameter W_Size;
	//public Parameter NoiseMin;
	//public Parameter NoiseMax;

    
    public TypedIOPort Z_out ;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    /** Clone the actor into the specified workspace. This calls the
     *  base class and then sets up the type constraints.
     *  @param workspace The workspace for the new object.
     *  @return A new actor.
     *  @exception CloneNotSupportedException If a derived class contains
     *   an attribute that cannot be cloned.
     */
    public Object clone(Workspace workspace)
            throws CloneNotSupportedException {
        CrossZeroO newObject = (CrossZeroO)super.clone(workspace);
        // set the type constraints.
        newObject.output.setTypeAtLeast(newObject.input);
        return newObject;
    }

    /** Consume at most one token from the <i>input</i> port,
     *  add it to the running sum, and produce the result at the
     *  <i>output</i> port.  If there is no input token available,
     *  the current value of the running sum is the output value.
     *  If there is a true-valued token on the <i>reset</i> input,
     *  then the running sum is reset to the initial value before
     *  adding the input.
     *  @exception IllegalActionException If addition is not
     *   supported by the supplied tokens.
     */
    public void fire() throws IllegalActionException {
   
        _latestCount=_count;
	    _sum=_lastsum;

 if (input.hasToken(0))
  {     
      _current= (DoubleToken)input.get(0);
	  if(((DoubleToken)_current).doubleValue() >=(-0.032)) _currentsgn=1 ;
	  else  _currentsgn=-1 ;

      
	  if(_latestCount!=0)
    	{
		   /*if(((DoubleToken)_current).doubleValue() >= _NMax)  _currentsgn=1 ;
		   else if (((DoubleToken)_current).doubleValue() < _NMin)  _currentsgn=-1;
		   else _currentsgn=0 ;*/
            
		   
             _sum=_sum+(_currentsgn -_lastsgn);
		   if(_sum<0) _sum=-1*_sum;
		
		   output.send(0,_current);
	         --_latestCount;
         }

     else 
   	     { 		  
           Z_out.send(0,new DoubleToken(_sum/(2*N)));
           _sum=0; 
		   output.send(0,_current);
            _latestCount=((IntToken)(W_Size.getToken())).intValue();
			
		   	
          }      
  }

else 
	{
	    output.send(0,new DoubleToken(0.0));
        Z_out.send(0, new DoubleToken(0.0) );
    
}
     
}
public void initialize() throws IllegalActionException {
        super.initialize();
        	       _sum = 0;
				   _lastsum=0;
			_last=new DoubleToken(0.0);
			_current=new DoubleToken(0.0);
		    
		    //_NMax=((DoubleToken)(NoiseMax.getToken())).doubleValue();
		    //_NMin=((DoubleToken)(NoiseMin.getToken())).doubleValue(); 
           	    _count=0;
		    _latestCount=((IntToken)(W_Size.getToken())).intValue();
			N=((IntToken)(W_Size.getToken())).intValue();
		    //_currentsgn=0;
		    _lastsgn=0;
}

public boolean postfire() throws IllegalActionException {
	     _count=_latestCount;
		_last=_current;
		_lastsgn=_currentsgn;
        _lastsum=_sum;
		return super.postfire();
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private members                   ////

    private int  _sum;
    private int _lastsum;
	private int N;
   
	private Token _last;
	private Token _current;

	private int _currentsgn;
       private int _lastsgn;

	private int _latestCount;
       private int _count=0;

	//private double _NMax;
	//private double _NMin;


}

⌨️ 快捷键说明

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