Class Scrambler
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class Scrambler extends Transformer
Scramble the input bit sequence using a feedback shift register. The initial state of the shift register is given by the initialState parameter, which should be a non-negative integer. The taps of the feedback shift register are given by the polynomial parameter, which should be a positive integer. The n-th bit of this integer indicates whether the n-th tap of the delay line is fed back. The low-order bit is called the 0-th bit, and should always be set. The next low-order bit indicates whether the output of the first delay should be fed back, etc. The input port receives boolean tokens. "TRUE" is treated as 1 and "FALSE" is treated as 0. All the bits that are fed back are exclusive-ored together (i.e., their parity is computed), and the result is exclusive-ored with the input bit. The result is produced at the output and shifted into the delay line.With a proper choice of polynomial, the resulting output appears highly random even if the input is highly non-random. If the polynomial is a primitive polynomial, then the feedback shift register is a so-called maximal length feedback shift register. This means that with a constant input (or no input, which is equivalent to a constant false input) the output will be a sequence with period 2N-1, where N is the order of the polynomial (the length of the shift register). This is the longest possible sequence. Moreover, within this period, the sequence will appear to be white, in that a computed autocorrelation will be very nearly an impulse. Thus, the scrambler with a constant input can be very effectively used to generate a pseudo-random bit sequence.
The maximal-length feedback shift register with constant input will pass through 2N-1 states before returning to a state it has been in before. This is one short of the 2N states that a register with N bits can take on. This one missing state, in fact, is a lock-up state, in that if the input is an appropriate constant, the scrambler will cease to produce random-looking output, and will output a constant. For example, if the input is all zeros, and the initial state of the scrambler is zero, then the outputs will be all zero, hardly random. This is easily avoided by initializing the scrambler to some non-zero state. The default value for the shiftReg is set to 1.
The polynomial must be carefully chosen. It must represent a primitive polynomial, which is one that cannot be factored into two (nontrivial) polynomials with binary coefficients. See Lee and Messerschmitt (Kluwer, 1994) for more details. For convenience, we give here a set of primitive polynomials (expressed as octal numbers so that they are easily translated into taps on shift register). All of these will result in maximal-length pseudo-random sequences if the input is constant and lock-up is avoided:
order polynomial 2 07 3 013 4 023 5 045 6 0103 7 0211 8 0435 9 01021 10 02011 11 04005 12 010123 13 020033 14 042103 15 0100003 16 0210013 17 0400011 18 01000201 19 02000047 20 04000011 21 010000005 22 020000003 23 040000041 24 0100000207 25 0200000011 26 0400000107 27 01000000047 28 02000000011 29 04000000005 30 010040000007
The leading zero in the polynomial indicates an octal number. Note also that reversing the order of the bits in any of these numbers will also result in a primitive polynomial. Thus, the default value for the polynomial parameter is 0440001 in octal, or "100 100 000 000 000 001" in binary. Reversing these bits we get "100 000 000 000 001 001" in binary, or 0400011 in octal. This latter number is the one listed above as the primitive polynomial of order 17. The order is simply the index of the highest-order non-zero in the polynomial, where the low-order bit has index zero.
Since the polynomial and the feedback shift register are both implemented using type "int", the order of the polynomial is limited by the size of the "int" data type. For simplicity and portability, the polynomial is not allowed to be interpreted as a negative integer, so the sign bit cannot be used. Thus, if "int" is a 32-bit word, then the highest order polynomial allowed is 30 (recall that indexing for the order starts at zero, and we cannot use the sign bit). Java has 32-bit integers, so we give the primitive polynomials above only up to order 30.
For more information on scrambler, see Lee and Messerschmitt, Digital Communication, Second Edition, Kluwer Academic Publishers, 1994, pp. 595-603.
- Since:
- Ptolemy II 3.0
- Version:
- $Id$
- Author:
- Edward A. Lee and Ye Zhou
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description Parameter
initialState
Integer defining the initial state of the shift register.Parameter
polynomial
Integer defining a polynomial with binary coefficients.-
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description Scrambler(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
If the attribute being changed is polynomial, then verify that is a positive integer and the lower-order bit is 1.void
fire()
Read a bit from the input port and shift it into the shift register to scramble.void
initialize()
Initialize the actor by resetting the shift register state equal to the value of initialState.boolean
postfire()
Record the most recent shift register state as the new initial state for the next iteration.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
polynomial
public Parameter polynomial
Integer defining a polynomial with binary coefficients. The coefficients indicate the presence (1) or absence (0) of a tap in a feedback shift register. This parameter should contain a positive integer with the lower-order bit being 1. Its default value is the integer 0440001.
-
initialState
public Parameter initialState
Integer defining the initial state of the shift register. The n-th bit of the integer indicates the value of the n-th register. This parameter should be a non-negative integer. Its default value is the integer 1.
-
-
Constructor Detail
-
Scrambler
public Scrambler(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the given container and name. The output and trigger ports are also constructed.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the entity cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
If the attribute being changed is polynomial, then verify that is a positive integer and the lower-order bit is 1.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If polynomial is non-positive or the lower-order bit is not 1.
-
fire
public void fire() throws IllegalActionException
Read a bit from the input port and shift it into the shift register to scramble. Compute the parity and send true to the output port if it is 1; otherwise send false to the output port. The parity is shifted into the delay line for the next iteration.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Not thrown in this base class.
-
initialize
public void initialize() throws IllegalActionException
Initialize the actor by resetting the shift register state equal to the value of initialState.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the parent class throws it.
-
postfire
public boolean postfire() throws IllegalActionException
Record the most recent shift register state as the new initial state for the next iteration.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- If the base class throws it
-
-