Learn R Programming

OscillatorGenerator (version 0.1.0)

SquareSpike: Generation of a Square-wave Signal

Description

This function takes in numeric arguments for a customizable, square-wave spike shape. A discretized time course is returned.

Usage

SquareSpike(baseline, peak, period, duty_cycle, trend, duration, resolution)

Arguments

baseline

minimal oscillation value

peak

maximal oscillation value

period

oscillation period of the oscillating species (reciprocal of the frequency)

duty_cycle

ratio of the active phase (oscillator above baseline) to the total oscillation period

trend

percental decrease or increase in the peak value for the successive oscillation cycles; if set to 1, peak value remains unchanged

duration

duration of the generated time course

resolution

temporal resolution of the generated time course

Value

Returns a matrix with two columns: a time vector and an oscillator abundance vector.

Details

Standards:

  • peak must be larger than baseline

  • duration must be larger than resolution

  • duration must be a multiple of resolution

  • period must be a multiple of resolution

  • duration, resolution, peak and period must be larger than 0

  • baseline must be larger or equal to 0

  • duty_cycle must be larger than 0 and smaller or equal to 1

  • trend must be larger than 0

Examples

Run this code
# NOT RUN {
# test effect of changes in period
m1 = SquareSpike(baseline = 200, peak = 1000, period = 50, duty_cycle = 0.6,
trend = 1, duration = 500, resolution = 0.1)
m2 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.6,
trend = 1, duration = 500, resolution = 0.1)
m3 = SquareSpike(baseline = 200, peak = 1000, period = 200, duty_cycle = 0.6,
trend = 1, duration = 500, resolution = 0.1)

par(mfrow = c(3,1))
plot(m1, type = "l", xlab = "time", ylab = "abundance")
plot(m2, type = "l", xlab = "time", ylab = "abundance")
plot(m3, type = "l", xlab = "time", ylab = "abundance")

# test effect of changes in duty_cycle
m1 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.3,
trend = 1, duration = 500, resolution = 0.1)
m2 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.6,
trend = 1, duration = 500, resolution = 0.1)
m3 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.9,
trend = 1, duration = 500, resolution = 0.1)

par(mfrow = c(3,1))
plot(m1, type = "l", xlab = "time", ylab = "abundance")
plot(m2, type = "l", xlab = "time", ylab = "abundance")
plot(m3, type = "l", xlab = "time", ylab = "abundance")

# test effect of changes in trend
m1 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.6,
trend = 0.7, duration = 500, resolution = 0.1)
m2 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.6,
trend = 1, duration = 500, resolution = 0.1)
m3 = SquareSpike(baseline = 200, peak = 1000, period = 100, duty_cycle = 0.6,
trend = 1.3, duration = 500, resolution = 0.1)

par(mfrow = c(3,1))
plot(m1, type = "l", xlab = "time", ylab = "abundance")
plot(m2, type = "l", xlab = "time", ylab = "abundance")
plot(m3, type = "l", xlab = "time", ylab = "abundance")
# }

Run the code above in your browser using DataLab