Last data update: 2014.03.03

R: A random function with a smooth background
test.signalR Documentation

A random function with a smooth background

Description

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

Usage

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. 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"))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BBEST)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BBEST/test.signal.Rd_%03d_medium.png", width=480, height=480)
> ### Name: test.signal
> ### Title: A random function with a smooth background
> ### Aliases: test.signal
> 
> ### ** Examples
> 
> # 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"))
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>