ptolemy.actor.lib.comm
Class Scrambler
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.Transformer
ptolemy.actor.lib.comm.Scrambler
- All Implemented Interfaces:
- java.io.Serializable, 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: Scrambler.java 57040 2010-01-27 20:52:32Z cxh $
- Author:
- Edward A. Lee and Ye Zhou
- See Also:
- Serialized Form
- Accepted Rating:
- Proposed Rating:
Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Constructor Summary |
Scrambler(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
Method Summary |
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.AtomicActor |
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, 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 |
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName |
Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, 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, propagateValue, propagateValues, removeChangeListener, removeDebugListener, 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 |
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.
_shiftReg
private int _shiftReg
_latestShiftReg
private int _latestShiftReg
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.
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 class NamedObj
- 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 interface Executable
- Overrides:
fire
in class AtomicActor
- 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 interface Initializable
- Overrides:
initialize
in class AtomicActor
- 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 interface Executable
- Overrides:
postfire
in class AtomicActor
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- If the base class throws it