
Helper function to smooth numerical data using methods specified by the user.
smth(
x = stop("Numeric Vector 'x' is Required"),
method = getOption("smoother.method"),
...
)
a numeric vector of same length as input 'x'
vector
numeric vector of values to smooth
one of 'gaussian', 'sma', 'ema', 'dema'
or 'wma'
.
any other arguments to be passed to each specific smoothing methodology.
At this moment in time, the only method is the 'gaussian'
window function (similar to the Matlab
Gaussian Window Smoothing Function) and a number of moving averages 'sma', 'ema', 'dema'
or 'wma'
.
These are functions that allows the user to smooth an input vector, returning vector of the same length as the input.
This can also be achieved using the specific smth.gaussian
function.
If the 'method'
argument is equal to 'gaussian'
, then this function is a port of the function
described here: https://goo.gl/HGM47U, very loosly based of code which has also been ported to c++ elsewhere
Refer to specific man files: smth.gaussian
, SMA
, EMA
,
DEMA
or WMA
#Prepare Data
n = 1000
x = seq(-pi,pi,length.out=n)
y = sin(x) + (runif(length(x))*0.1) #NOISY DATA
ys = smth(y,window = 0.1,method = "gaussian") #SMOOTHING
plot(x,y,type="l",col="red")
lines(x,ys,col="black",lwd=3)
title("Example Smoothing of Noisy Data")
Run the code above in your browser using DataLab