Source Code
Infrared Signal Coding Schemes
home top contents previous up next

	
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;



final public class BER_PAPM extends Content{
	public BER_PAPM(Dimension dim, Image img, String problemName){
			super(dim,img,problemName);
	}

	protected void initPreconstructor_Variables(){
		modelDescription=new String[]{
				"Program 5.  Model:    BER A-R-L    where A-levels of intens, R-Rank, L-length.",
				"","","","","","","","","","","",
				"","","","","","","","","","",""
	    };

		modelDescription[2]="Vertical Axis: P/Pook (dB, 10log10(P/Pook).";
		modelDescription[3]="Horizontal Axis: Rc/Rb.";
		
        //Problem parameters.
        
		dmnStartF=0.0;
		dmnRangeF=16.0;
		dmnRangeFDown=8;
		grStartF=500;

		dmnStartX=0.01;
		dmnRangeX=8.0;
		grPoints=2;

		drawGrid=true;
		parametrizedFunction=true;
		showPointsAsCircles=true;
		functionCOUNT=19;
    	functionColor=new Color[]{
    			new Color(200,0,200),
    			new Color(0,0,255),
    			new Color(0,100,100),
    			new Color(0,100,200),
    			new Color(50,200,50),
    			new Color(150,100,50),
    			new Color(50,150,150),
    			new Color(200,150,200),
    			new Color(250,100,150),
    			
    			new Color(255,0,0),
    			new Color(255,0,0),
    			new Color(255,0,0),
    			new Color(255,0,0),
    			
    			new Color(0,0,255),
    			new Color(0,0,255),
    			new Color(0,0,255),

    			new Color(0,200,0),
    			new Color(0,200,0),
    			new Color(0,200,0)
    	};
        functionTitle=new String[]{
        	"OOK",
        	
        	" "," "," "," ",
        	" "," "," "," ",

        	"16-2-16",
        	"16-2-8",
        	"16-2-4",
        	"16-2-2",
        	
        	"4-2-16",
        	"4-2-8",
        	"4-2-4",
        	"4-2-2",
        	
        	"16-4-16",
        	"16-4-8",
        	"16-4-4",
        	"16-4-2",
        	
        };
	}
	
	
	//-----------------------------------------------
    // User Input-Output Prompts
    //- - - - - - - - - - - - - - - - - - - - - - - - 
   	
    protected int setParsToStrings(){
         int i=0;
         strParsCrr[i][0]=String.valueOf(dmnRangeX);  strParsCrr[i][1]="Argument Range"; strParsCrr[i++][2]="double"; 
         strParsCrr[i][0]=String.valueOf(dmnRangeF);  strParsCrr[i][1]="Function Range"; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(dmnStartF);  strParsCrr[i][1]="Function Start"; strParsCrr[i++][2]="double";

         strParsCrr[i][0]=String.valueOf(PAM_A2);   strParsCrr[i][1]="PAM 1. A"; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(PAM_A4);   strParsCrr[i][1]="PAM 4. A"; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(PAM_A8);   strParsCrr[i][1]="PAM 8. A"; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(PAM_A16);   strParsCrr[i][1]="PAM 16. A"; strParsCrr[i++][2]="double";

         strParsCrr[i][0]=String.valueOf(PPM_L2);   strParsCrr[i][1]="PPM_L 2. "; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(PPM_L4);   strParsCrr[i][1]="PPM_L 4. "; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(PPM_L8);   strParsCrr[i][1]="PPM_L 8. "; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(PPM_L16);   strParsCrr[i][1]="PPM_L 16. "; strParsCrr[i++][2]="double";

         return i;
    }
    public String setParsFromStrings(){
         int i=0;
         try{
        	 dmnRangeX =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 dmnRangeF =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 dmnStartF =Double.parseDouble(strParsCrr[i][0]);  i++;

        	 PAM_A2 =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 PAM_A4 =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 PAM_A8 =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 PAM_A16 =Integer.parseInt(strParsCrr[i][0]);  i++;

        	 PPM_L2 =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 PPM_L4 =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 PPM_L8 =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 PPM_L16 =Integer.parseInt(strParsCrr[i][0]);  i++;

         }catch(Exception e){
            return "Exception when (re)setting parameters.\n" + e;    
         }
         return "";
    }
    //- - - - - - - - - - - - - - - - - - - - - - - - 
    // User Input Output Prompts
	//-----------------------------------------------

	
    double P_OOK(double Rb){
    	return 0;
    }
    double Rb_OOK(double Rb){
    	return 1;
    }

    //=================================
    // PAM
    //---------------------------------
    int PAM_A2=2;
    int PAM_A4=4;
    int PAM_A8=8;
    int PAM_A16=16;
    //---------------------------------
    // PAM
    //=================================

    //=================================
    // PPM
    //---------------------------------
    int PPM_L2=2;
    int PPM_L4=4;
    int PPM_L8=8;
    int PPM_L16=16;
    //---------------------------------
    // PPM
    //=================================

    //=================================
    // PAPM
    //---------------------------------
    int PAPM_L16=16;
    int PAPM_L8=8;
    int PAPM_L4=4;
    int PAPM_L2=2;
    
    int PAPM_A16=16;
    int PAPM_A8=8;
    int PAPM_A4=4;
    int PAPM_A2=2;

    int PAPM_R2=2;
    int PAPM_R4=4;
    //---------------------------------
    // PAPM
    //=================================

    
    double PFactor(int A, int L, int MRank){
    	double a_aver=0.5*A*MRank/L;
    	int S=A+1;
    	int ranks=MRank;
    	while(--ranks>0){S*=S;}
		double M=Math.log(S)/Math.log(2.0);
		double P=2.0*a_aver/Math.sqrt(M);
		con("aaver="+a_aver+" P="+P);
		//return P;
    	return 10.0*Math.log(P)/Math.log(10.0); 
    }
    double Rc(int A, int L, int MRank, String legend){
    	int S=A+1;
    	int ranks=MRank;
    	while(--ranks>0){S*=S;}
		double M=Math.log(S)/Math.log(2.0);
		double MM=M/L;
		double RcRb=1.0/MM;
		con(legend+" RcRb="+RcRb);
    	return RcRb;
    }

    

    protected void prepareParameters(){}
	
    protected double functionSwitch(int fIx, double x){
	    switch(fIx){
	    case 0: return P_OOK(x);
	    case 1: return PFactor(PAM_A2, 1, 1);
	    case 2: return PFactor(PAM_A4, 1, 1);
	    case 3: return PFactor(PAM_A8, 1, 1);
	    case 4: return PFactor(PAM_A16, 1, 1);
	    case 5: return PFactor(1, PPM_L2, 1);
	    case 6: return PFactor(1, PPM_L4, 1);
	    case 7: return PFactor(1, PPM_L8, 1);
	    case 8: return PFactor(1, PPM_L16, 1);
	    
	    case 9: return PFactor(PAPM_A16,  PAPM_L16,  PAPM_R2);
	    case 10: return PFactor(PAPM_A16,  PAPM_L8,  PAPM_R2);
	    case 11: return PFactor(PAPM_A16,  PAPM_L4,  PAPM_R2);
	    case 12: return PFactor(PAPM_A16,  PAPM_L2,  PAPM_R2);

	    case 13: return PFactor(PAPM_A4,  PAPM_L16,  PAPM_R2);
	    case 14: return PFactor(PAPM_A4,  PAPM_L8,  PAPM_R2);
	    case 15: return PFactor(PAPM_A4,  PAPM_L4,  PAPM_R2);

	    case 16: return PFactor(PAPM_A16,  PAPM_L16,  PAPM_R4);
	    case 17: return PFactor(PAPM_A16,  PAPM_L8,  PAPM_R4);
	    case 18: return PFactor(PAPM_A16,  PAPM_L4,  PAPM_R4);

	    }
	    return 0;
    }
	protected double functionSwitchX(int fIx, double t){
	    switch(fIx){
	    case 0: return Rb_OOK(t);
	    /*
	    case 1: return Rc(PAM_A2,  1,  1, "PAM 1");
	    case 2: return Rc(PAM_A4, 1,  1, "PAM 4");
	    case 3: return Rc(PAM_A8, 1,  1, "PAM 8");
	    case 4: return Rc(PAM_A16, 1,  1, "PAM 16");

	    case 5: return Rc(1,  PPM_L2,  1, "PPM 1");
	    case 6: return Rc(1,  PPM_L4, 1, "PPM 2");
	    case 7: return Rc(1,  PPM_L8, 1, "PPM 3");
	    case 8: return Rc(1,  PPM_L16, 1, "PPM 4");
	    */
	    
	    case 9: return Rc(PAPM_A16,  PAPM_L16,  PAPM_R2, "PAPM");
	    case 10: return Rc(PAPM_A16,  PAPM_L8,  PAPM_R2, "PAPM");
	    case 11: return Rc(PAPM_A16,  PAPM_L4,  PAPM_R2, "PAPM");
	    case 12: return Rc(PAPM_A16,  PAPM_L2,  PAPM_R2, "PAPM");
	    
	    case 13: return Rc(PAPM_A4,  PAPM_L16,  PAPM_R2, "PAPM");
	    case 14: return Rc(PAPM_A4,  PAPM_L8,  PAPM_R2, "PAPM");
	    case 15: return Rc(PAPM_A4,  PAPM_L4,  PAPM_R2, "PAPM");
	    
	    case 16: return Rc(PAPM_A16,  PAPM_L16,  PAPM_R4, "PAPM");
	    case 17: return Rc(PAPM_A16,  PAPM_L8,  PAPM_R4, "PAPM");
	    case 18: return Rc(PAPM_A16,  PAPM_L4,  PAPM_R4, "PAPM");
	    }
	    return 0;
	}
	
    protected void spawnParametersAfterUserApplied(){};

}


Copyright (C) 2009 Konstantin Kirillov