#### example : composite of two components having different frequencies
## define vertex coordinate
x <- y <- seq(0, 1, length=30)
xy <- expand.grid(x=x, y=y)
## weighted adjacency matrix by Gaussian kernel
## for connecting vertices within distance 0.04
A <- adjmatrix(xy, method = "dist", 0.04)
## signal
# high-frequency component
signal1 <- rep(sin(12.5*pi*x - 1.25*pi), 30)
# low-frequency component
signal2 <- rep(sin(5*pi*x - 0.5*pi), 30)
# composite signal
signal0 <- signal1 + signal2
# noisy signal with SNR(signal-to-noise ratio)=5
signal <- signal0 + rnorm(900, 0, sqrt(var(signal0) / 5))
# graph with signal
gsig <- gsignal(vertex = cbind(xy, signal), edge = A, edgetype = "matrix")
# local extrema using graph object
extremaout <- gextrema(as_adjacency_matrix(gsig, attr="weight"), V(gsig)$z)
maxima <- extremaout$maxima_list; minima <- extremaout$minima_list
# Interpolation of upper, lower and mean envelope
uenvelope <- ginterpolating(as_adjacency_matrix(gsig, attr="weight"),
V(gsig)$z, maxima)
lenvelope <- ginterpolating(as_adjacency_matrix(gsig, attr="weight"),
V(gsig)$z, minima)
menvelope <- (uenvelope + lenvelope) / 2
# display a graph signal
gplot(gsig, size=3, legend=FALSE)
# display mean envelope
gplot(gsig, menvelope, size=3, legend=FALSE)
Run the code above in your browser using DataLab