001/* The integrator in the continuous domain. 002 003 Copyright (c) 1998-2010 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.domains.continuous.lib; 029 030import ptolemy.kernel.CompositeEntity; 031import ptolemy.kernel.util.IllegalActionException; 032import ptolemy.kernel.util.NameDuplicationException; 033 034////////////////////////////////////////////////////////////////////////// 035//// Noise 036 037/** 038This actor generates continuous-time noise with a Gaussian distribution. 039It provides two rather ad-hoc approximations to a white noise process, depending 040on the value of the <i>linearlyInterpolate</i> parameter. Specifically, 041if this parameter is true (the default), then the output signal is 042a continuous signal that linearly interpolates between 043Gaussian random numbers generated at each sample time chosen by 044the solver. If the solver step size is constant or increasing, then these Gaussian 045random numbers will be independent. However, if the solver finds itself having 046to reduce the step size after performing a speculative execution into the 047future, then the random number produced at the end of the reduced 048integration step will be correlated with that produced at the beginning 049of the integration step. (FIXME: Need a figure to illustrate this.) 050<p> 051If <i>linearlyInterpolate</i> is set to false, then this actor will 052hold the value of its output constant for the duration of an integration 053step. Thus, the output signal is piecewise constant. At each time step 054chosen by the solver, the value is given by a new independent Gaussian 055random number. This method has the advantage that samples at all 056times chosen by the solver are uncorrelated. 057<p> 058In both cases, whether <i>linearlyInterpolate</i> is true or false, if the 059solver holds its step size constant, then the resulting signal is 060statistically equivalent to filtered white noise. If <i>linearlyInterpolate</i> 061is true, then the power spectrum has the shape of a sinc squared. 062If it is false, then it has the shape of the absolute value of a sinc 063function. In the latter case, the power is infinite, so the approximation 064is not physically realizable. In the former case, the power is finite. 065In both cases, sampling the process at the rate of one over the step 066size yields a discrete-time white noise process. 067<p> 068It is worth explaining why we must approximate white noise. 069In general, it is not possible in any discretized approximation of a continuous 070random process to exactly simulate a white noise process. By definition, a 071white noise process is one where any two values at distinct times are 072uncorrelated. A naive attempt to simulate this might simply generate 073a new random number at each sample time at which the solver chooses 074to fire the actor. However, this cannot work in general. 075Specifically, the semantics of the continuous domain assumes 076that signals are piecewise continuous. The signal resulting from 077the above strategy will not be piecewise continuous. If the solver 078refines a step size and chooses a point close to a previously calculated 079point, the new value produced by such an actor would not be close to the 080previously value previously produced. This can result in the solver 081assuming that its step size is too large and reducing it until it can 082reduce it no more. 083<p> 084To demonstrate this effect, try connecting a GaussianActor to a 085LevelCrossingDetector actor under a ContinuousDirector. An execution 086of the model will immediately trigger an exception with a message 087like "The refined step size is less than the time resolution, at time..." 088Conceptually, with a true white noise process, the level crossing 089occurs <i>at all times</i>, and therefore the exception is, 090in fact, the correct response. 091<p> 092If you modify the above example by sending the output of the 093Gaussian actor directly to an Integrator, and then the output 094of the Integrator to the LevelCrossingDetector, then the exception 095disappears. The Integrator ensures that the signal is piecewise 096continuous. This might seem like a reasonable approximation to a 097Weiner process, but in fact it is problematic. In particular, 098at the times that the LevelCrossingDetector triggers, the 099Gaussian actor will actually produce two distinct random numbers 100at the same time (at different microsteps). This changes the 101statistics of the output in a very subtle way. 102<p> 103Note that a much more principled noise process is generated 104by the {@link BandlimitedNoise} actor. 105 106 @author Edward A. Lee 107 @version $Id$ 108 @since Ptolemy II 8.0 109 @Pt.ProposedRating Yellow (eal) 110 @Pt.AcceptedRating Red (eal) 111 */ 112public class Noise extends ptolemy.domains.continuous.kernel.Noise { 113 114 // NOTE: This is simply a wrapper for continuous.kernel.Noise to make 115 // it appear in the lib package. 116 117 /** Construct an actor with the given container and name. 118 * @param container The container. 119 * @param name The name of this actor. 120 * @exception IllegalActionException If the actor cannot be contained 121 * by the proposed container. 122 * @exception NameDuplicationException If the container already has an 123 * actor with this name. 124 */ 125 public Noise(CompositeEntity container, String name) 126 throws NameDuplicationException, IllegalActionException { 127 super(container, name); 128 } 129}