Learn R Programming

kza (version 4.2.1)

kza: Kolmogorov-Zurbenko Adaptive

Description

KZA will recover 2-dimensional or 3-dimensional image or signal buried in noise.

Usage

kza(x, m, y = NULL, k = 3, min_size = round(0.05*m), tol = 1.0e-5, impute_tails = FALSE,
    symmetrize = FALSE, normalize = c("max", "quantile"))
# S3 method for kza
plot(x, ...)

Author

Brian Close <[email protected]> and Igor Zurbenko <[email protected]>

Arguments

x

A vector of the time series or a matrix (2d) or an array (3d) of an image.

m

The full window width, on the same scale as kz(): the per-side radius used internally is floor(m/2), and the same radius drives the default kz baseline. (Before 4.2.0, kza used m itself as the per-side radius, so its adaptive window was roughly twice the baseline's for the same m; double m to reproduce old results.)

y

The filtered output from kz.

k

The number of iterations.

min_size

Minimum size of window q.

tol

The smallest value to accept as nonzero.

impute_tails

The default is to drop the tails.

symmetrize

Matrix input only: average the filter over the four 90-degree rotations of the input. The adaptive head/tail rule can misallocate the window immediately beside a sharp, high-contrast, axis-aligned edge, so plain kza does not commute with 90-degree rotation; rotation averaging cancels that row/column bias (exactly, for square input) at four times the compute. Default FALSE.

normalize

Normalizer for the adaptive shrink factor. "max" (the default, and the published behavior) uses the literal maximum of the difference metric; "quantile" uses its 99th percentile, so a handful of extreme pixels do not single-handedly set the smoothing scale for the whole image, with an automatic fallback to the maximum whenever the quantile is zero (sparse structure on an otherwise flat field would otherwise be smoothed away).

...

Other parameters.

Details

The selection of parameters of KZA depend on the nature of the data. This function may take a long time to run, depending on the number of dimensions and the size of the dimensions.

References

I. Zurbenko, P.S. Porter, S.T. Rao, J.Y. Ku, R. Gui, R.E. Eskridge Detecting Discontinuities in Time Series of Upper-air Data: Development and Demonstration of an Adaptive Filter Technique. Journal of Climate: (1996) Vol. 9, No. 12, pp. 3548 3560. tools:::Rd_expr_doi("10.1175/1520-0442(1996)009<3548:dditso>2.0.CO;2")

Kevin L. Civerolo, Elvira Brankov, S. T. Rao, Igor Zurbenko Assessing the impact of the acid deposition control program. Atmospheric Environment 35 (2001) 4135-4148 http://www.elsevier.com/locate/atmosenv

J.Chen, I.Zurbenko, Nonparametric Boundary detection, Communications in Statistics, Theory and Methods, Vol.26, 12, 2999-3014, 1997.

Examples

Run this code
#######
# this is an example of detection of a break point in a time series
#######
yrs <- 20
t <- seq(0,yrs,length=yrs*365)
m <- 365

#noise
e <- rnorm(n = length(t),0,1)
trend <- seq(0,-1,length=length(t))

#signal
bkpt <- 3452
brk <- c(rep(0,bkpt),rep(0.5,length(t)-bkpt))
signal <- trend + brk

# y = seasonal + trend + break point + noise
y <- sin(2*pi*t) + signal + e

k.kz <- kz(y,m)

# kza reconstruction of the signal
k.kza <- kza(y,m,y=k.kz,min_size=10)

par(mfrow=c(2,1))
plot(y,type="l", ylim=c(-3,3))
plot(signal,type="l",ylim=c(-3,3), 
    main="Signal and KZA Reconstruction")
lines(k.kza$kza, col=4)

######################
# image detection (2d)
######################
set.seed(2)
a <- matrix(rep(0,100*100),nrow=100)
a[35:70,35:70]<-1
a <- a + matrix(rnorm(100*100,0,1),nrow=100)
y<-kz(a,m=15,k=3)
v <- kza(a,m=15,y=y,k=3,impute_tails=TRUE)

x <- seq(1,100)
y <- x
op <- par(bg = "white")

###
#noise
###
c="lightblue"
persp(x, y, a, zlab="z", zlim=c(-5,5), ticktype="detailed", theta=30, phi=30, col=c)

###
#kza filtered
###
persp(x,y,v$kza,zlab="z",zlim=c(-5,5),ticktype="detailed",theta=30,phi=30,col=c)

###
# another view
###
par(mfrow=c(1,2))
image(a,col=gray(seq(0,1,1/255)))
image(v$kza,col=gray(seq(0,1,1/255)))
par(mfrow=c(1,1))

Run the code above in your browser using DataLab