test.signal: A random function with a smooth background

Description Usage Arguments Details Value Examples

View source: R/plot.R

Description

test.signal creates a random function that consists of peaks, a smooth background, and a Gaussian noise.

Usage

1
test.signal(x, lambda, sigma, x.delta, knots.n, peaks.widthRange, peaks.n)

Arguments

x

numeric vector, the x-points where data should be generated.

lambda

numeric, the mean signal magnitude.

sigma

numeric, the noise level.

x.delta

numeric, the minimum spacing allowed between spline knots. Defines background smoothness.

knots.n

numeric, a number of spline knots to generate.

peaks.widthRange

numeric vector, specifies range in peak widths.

peaks.n

numeric, the number of peaks to generate.

Details

The background is calculated as a sum of fundamental splines on the randomly generated knots. The function is a sum of the background, random peaks, and Gaussian noise.

Value

An object of type data (see set.data) with the following elements added:

knots

list with elements x and y that specify the knot positions and knot values, respectively.

bkg

numeric vector containing the generated background.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 1. Create test function 
f <- test.signal(x=seq(0,30,0.01), lambda=5, 
         sigma=0.1, x.delta=1.0, knots.n=5, 
         peaks.widthRange=c(0.1, 0.3), peaks.n=7)
	
# 2. Plot results
plot(f$x, f$y, t="l", xlab="x", ylab="f")
lines(f$x, f$bkg, col=2)
lines(f$x, f$y - f$bkg, col="gray")
legend(20, .9*max(f$y), c("test function", "background", 
       "peaks+noise"), lty=1, col=c(1,2,"gray"))

BBEST documentation built on Jan. 8, 2021, 2:22 a.m.