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


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


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

    int unitsSignalSequenceNumber;
    int amplitudeVariatedSingnalSubsequenceNumber;
	
	//////////////////////////////////////////////////
	// Initializers
	//================================================
    //Overriding:
	//------------------------------------------------
    protected void spawnParametersAfterUserApplied(){
	 spanParsInMPLevel();
	 displySpawnedParsInMPLevel();
     simulationBlocked=false;
	 simulateThresholding();
    }
    //================================================
    
    //================================================
	//Overriding:
	//------------------------------------------------
	protected void initPreconstructor_Variables(){
		initPreconstructorInMPLevel();
		unitsSignalSequenceNumber=22;
		amplitudeVariatedSingnalSubsequenceNumber=19;
		ceilingHeight=10.0;
    	modelDescription=new String[200];
		modelDescription[0]="Program 13: Signal Sequences Generator Demo.";

		tapsSimulationLimit=31;
		
		dmnStartF=0.0;
		dmnRangeF=8.0;
		dmnRangeFDown=1.0;

		dmnStartX=0.0;
		dmnRangeX=3.0;
		grPoints=100;
		grStartF=600;

		functionCOUNT=4;
    	functionColor=new Color[]{
    			new Color(255,0,0),
    			new Color(220,100,0),
    			new Color(0,0,200),
    			new Color(150,0,150),
    			new Color(0,150,0),
    			new Color(0,255,0),
    			new Color(100,100,100,50),
    			new Color(200,0,0,50),
    			new Color(222,0,200,50)
    	};
        functionTitle=new String[]{
        	"h",
        	"beta",
        	"incoming signal, bk",
        	"convolved signal"
        };
	}
	//------------------------------------------------
	//Overriding:
    //================================================
	
	//-----------------------------------------------
    // User Input Prompts
    //- - - - - - - - - - - - - - - - - - - - - - - - 
    protected int setParsToStrings(){
         int i=0;
        
         String decription="";
         for(int j=0; j<subModelTitle.length; j++){
        	 decription += ", "+j+" - " + subModelTitle[j];
         }

         strParsCrr[i][0]=String.valueOf(unitsSignalSequenceNumber);   strParsCrr[i][1]="Units Signal Sequence Number"; strParsCrr[i++][2]="int"; 
         strParsCrr[i][0]=String.valueOf(amplitudeVariatedSingnalSubsequenceNumber);   strParsCrr[i][1]="Amplitude Variated Singnal Subsequence Number"; strParsCrr[i++][2]="int"; 
         //strParsCrr[i][0]=String.valueOf(subModel);   strParsCrr[i][1]="Sub Model: "+decription; strParsCrr[i++][2]="int"; 
         //strParsCrr[i][0]=String.valueOf(shotNoisePresented);   strParsCrr[i][1]="shotNoisePresented, 0 or 1"; strParsCrr[i++][2]="int"; 
         //strParsCrr[i][0]=String.valueOf(SNR);  strParsCrr[i][1]="SNR, dB"; strParsCrr[i++][2]="double"; 
         //strParsCrr[i][0]=String.valueOf(amSAR);  strParsCrr[i][1]="SAR, Signal to Ambient Light Ratio"; strParsCrr[i++][2]="double"; 
         //strParsCrr[i][0]=String.valueOf(amInterferencePeriodTi);  strParsCrr[i][1]="Ti, Ambient Light Interference Period, sec"; strParsCrr[i++][2]="double"; 
		 //strParsCrr[i][0]=String.valueOf(amInteferenceSummationPoints);   strParsCrr[i][1]="NTi, Ambient Light Interf. Sum. Points Numb., 1 for no Interference."; strParsCrr[i++][2]="int";
         
         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(Rb);   strParsCrr[i][1]="Bit Rate, Rb"; strParsCrr[i++][2]="double";
         strParsCrr[i][0]=String.valueOf(ceilingHeight);   strParsCrr[i][1]="Room Height, meters"; strParsCrr[i++][2]="double";

         strParsCrr[i][0]=String.valueOf(L);   strParsCrr[i][1]="Maximum symbol length, L"; strParsCrr[i++][2]="int"; 
         strParsCrr[i][0]=String.valueOf(Amax);   strParsCrr[i][1]="Non-zero levels in chip amplitude, A"; strParsCrr[i++][2]="int";
         
         return i;
    }
    public String setParsFromStrings(){
         int i=0;
         try{
        	 
        	 unitsSignalSequenceNumber =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 amplitudeVariatedSingnalSubsequenceNumber =Integer.parseInt(strParsCrr[i][0]);  i++;

        	 dmnRangeX =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 dmnRangeF =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 dmnStartF =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 Rb =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 ceilingHeight =Double.parseDouble(strParsCrr[i][0]);  i++;
        	 L =Integer.parseInt(strParsCrr[i][0]);  i++;
        	 Amax =Integer.parseInt(strParsCrr[i][0]);  i++;
         }catch(Exception e){
            return "Exception when (re)setting parameters.\n" + e;    
         }
         return "";
    }
    //- - - - - - - - - - - - - - - - - - - - - - - - 
    // User Input Prompts
	//================================================================
	protected void simulateThresholding(){
    	
	  	   //Demo:
	  	   //Clear display:
	       int i;
	  	   for(i=20; i<modelDescription.length; i++){
	  	    	modelDescription[i]=null;
	  	   }
	       	
	       if(simulationBlocked)return;
		   if(subModel>0){
				  modelDescription[20]="BER for sub Model " + subModelTitle[subModel]+" is not implemented.";
				  simulationBlocked=true;
	              return;
		   }
		   if(tapsSimulationLimit<=tapsNumber){
					  modelDescription[20]="BER for sub Model " + subModelTitle[subModel]+". Taps Number exceeded limit.";
					  //Set B to 1.0 to attract attention:
					  BAmb=1.0;
					  simulationBlocked=true;
					  return;
		   }

		   //PAM and OOK:
		   int unitEventsCount=2;
	       int eventsCount=Amax+1;
	       int tL=Math.min(tapsSimulationLimit,tapsNumber);
	       i=tL;
	       while(--i>0){
	            	unitEventsCount*=2;
	            	eventsCount*=Amax+1;
	       };

		   modelDescription[22]="Chip sequences count " + eventsCount +
			         " Unit sequences count=" + unitEventsCount;
	       int EVENTS_MEASURE_LIMIT=1000000;
	 	   if(eventsCount>EVENTS_MEASURE_LIMIT){
		  			modelDescription[20]="Chip sequences count " + eventsCount +
		  			     " > " + EVENTS_MEASURE_LIMIT + " which seems too long to process.";
	                return;
	 	   }
	       for(int iXAm=0; iXAm<amInteferenceSummationPoints; iXAm++){
	            firstLossThreshold=-1;
	            int k=tL-1; //Probe slot to count statistics.
            	int sequenceCount=0; //First signal always 0.
	            for(int e=0; e<unitEventsCount; e++){
	            	
	            	//-----------------------------------------
	            	//Generate signal of units and signal:
	            	//   like for Amax=3, tL=5:
                    //   units:
                    //   1  0  1  1  0  = e = 22  
                    //
                    //   signal:
                    //   3  0  1  2  0 
	            	//            
	            	//   2*3^2 + 0*3^1 + 1 = signalSequenceNumber = 18+1 = 19
                    //   weight 3^3=27 
                    //
	            	int mask=e;
	            	int weight=1;
	            	int count=0;
	          	    for(int slot=0; slot<tL; slot++){
	          	    	int ampl=mask&1;
	          	    	if(ampl>0){ weight*=Amax; count++; } 
	          	    	b[k-slot]=ampl;
	          	        mask>>>=1;
	          	    }
	            	//-------------------------------

	          	    for(int iW=0; iW<weight; iW++){
	          	    	//----------------------------------------------
	          	    	//Decompose iW and assign amplitudes to a signal 
	          	    	//of units:
	          	    	sequenceCount++;
	          	    	i=tL;
	          	    	int weightS=iW;
	          	    	int reminder=-1;
	          	    	while(--i>-1){
	          	    		if(b[i]>0){
	          	    			reminder=weightS%Amax;
	          	    			b[i]=reminder+1;
	          	    			weightS=(weightS-reminder)/Amax;
	          	    		}
	          	    	}
	          	    	//----------------------------------------------
	          	        if(unitsSignalSequenceNumber==e && amplitudeVariatedSingnalSubsequenceNumber==iW){
	                       convolve(0,b,result,true);
	                       modelDescription[18]="unit sequence number, e="+e;
                           modelDescription[19]="live chips ="+count;
	                   	   modelDescription[20]="weight of live chips="+weight;
	                       modelDescription[21]="live chips sequence number ="+iW;
	                       modelDescription[22]="first live chip amplitude level ="+(reminder+1);
	                       modelDescription[23]="sequence number ="+sequenceCount;
	                       return;
	          	        }
	          	     } //for(int iW=0; iW<weight; iW++){
	            }// e 
	       } // for(int iXAm=0; iXAm<amInteferenceSummationPoints; iXAm++){
		}
		//------------------------------------------
		//  Simulation
		//==========================================

    protected double functionSwitch(int fIx, double x){
	    switch(fIx){
	    case 0: return hh(x);
	    case 1: return drawSignal(x,beta)/scaled_chip_length;
	    case 2: return drawSignal(x,b);
	    case 3: return drawSignal(x,result);
	    }
	    return 0;
    }
	protected double functionSwitchX(int fIx, double t) {return 0;}
}



Copyright (C) 2009 Konstantin Kirillov