random-signal
Generate a pseudo-random signal for mocking Sensor data
var RandomSignal =var opt =sep: "\n" // seperatortdelta: 200 // millisecondsvar rs =rs
outputs
{"x":"2014-02-26 16:30:57.918","y":1.3151883383869654}{"x":"2014-02-26 16:30:58.123","y":4.24176480313184}{"x":"2014-02-26 16:30:58.328","y":3.719194025237043}{"x":"2014-02-26 16:30:58.529","y":3.7442073803567077}
Options
Along with Readable stream options, (including object mode) you may pass in these options or use the defaults given below
var tdelta = opttdelta || 50 hz = opthz || 1 / 20 * tdelta amp = optamp || 1 noiseHz = optnoiseHz || 4 * hz noiseAmp = optnoiseAmp || 03 * amp trendIV = opttrendIV || 1000 * 1/hz lowtrend = optlowtrend || -amp hightrend = opthightrend || amp sep = optsep || "" timeFormatter = opttimeFormatter || getTimeString
tdelta (milliseconds)
The millisecond time that data will be produced. The default is 50ms
.
hz (seconds)
The frequency of the underlying sine signal. The default frequency for the sine wave is 1 cycle per 20 tdelta
's. This means that each cycle is fairly well sampled. It also means that setting tdelta = 50
will result in a default of a cycle per second.
amp
The amplitude of the underlying sine signal.
noizeHz (seconds)
The frequency of the applied noise signal
noiseAmp
The amplitude of the noise which will be randomly generated between 0 and noiseAmp
trendIV (milliseconds)
The millisecond interval in which to apply a random trend constant to the output data. The default is 1000 * 1/hz
which provides a new trend every cycle of the underlying sine wave. If you want a longer trend, say applied every 5 cycles, set trendIV = 5000 * 1/hz
. Remember the trendIV is in milliseconds, so the 1000
multiplication is necessary.
hightrend
The maximum amplitude of the randomly applied constant trend. The default is 1
.
lowtrend
The minimum amplitude of the randomly applied constant trend. The default is -1
.
sep
If the stream is not configured in objectMode this seperator will be applied to the end of the utf8
encoded string buffer
. The default is set to empty string ""
.
timeFormatter
A function that takes a Javascript Date
object as inputs and outputs a formatted date string. The default getTimeString
function will output dates as "YYYY-MM-SS HH:MM:SS.f"
Install
npm install random-signal