Skip to content

Commit

Permalink
Choose number of wavelet levels in analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Perpiñán Lamigueiro authored and Oscar Perpiñán Lamigueiro committed Jul 16, 2015
1 parent c6d0f27 commit 0b53946
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
63 changes: 35 additions & 28 deletions R/analysis.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
analysis <- function(x, threshold = 8e-3, ...){
analysis <- function(x, threshold = 8e-3, n.levels = 4, ...){
x0=no0(x, threshold = threshold)
if (length(x0)> 10){
wavelet=wavVarPD(x0, ...)[1:4] ##cuatro primeros niveles de varianza wavelet
max.where=which(x0==max(x0))[1]
rango=abs(diff(range(x0)))
len=length(x0)
energy=sum(x0^2)
nZC=nZeroCross(x0)
err <- try(pr <- prony(x0, M=10), silent=TRUE) ##descomposición por prony
if (class(err)!='try-error'){
freq <- pr$freq[1:2] ##Elijo como frecuencias aquellas 2 que transportan más energía
damp <- abs(pr$damp[1:2])
} else {
freq=c(1,1)
##names(freq)=c('freq1', 'freq2')
damp=c(1,1)
##names(damp)=c('damp1', 'damp2')
}
##result=c(max.where, wavelet, rango, len, energy, nZC)
result=c(max.where, wavelet, rango, len, energy, nZC, freq, damp)
names(result)=c('RefMax',
'W1', 'W2', 'W3', 'W4',
'range', 'N',
'energy',
'nZC',
'freq1', 'freq2', 'damp1', 'damp2')
return(as.data.frame(t(result)))
} else {return <- NULL}

## Wavelet variance
wavelet=wavVarPD(x0, ...)
## Choose the number of levels
n.levels <- min(length(wavelet), n.levels)
wavelet <- wavelet[seq_len(n.levels)]
## Other features
max.where <- which(x0==max(x0))[1]
rango <- abs(diff(range(x0)))
len <- length(x0)
energy <- sum(x0^2)
nZC <- nZeroCross(x0)
## Prony method
err <- try(pr <- prony(x0, M=10), silent=TRUE) ##descomposición por prony
if (class(err)!='try-error'){
freq <- pr$freq[1:2] ##Elijo como frecuencias aquellas 2 que transportan más energía
damp <- abs(pr$damp[1:2])
} else {
freq <- c(1,1)
##names(freq)=c('freq1', 'freq2')
damp <- c(1,1)
##names(damp)=c('damp1', 'damp2')
}
## Return the result
result <- c(max.where, wavelet, rango, len, energy, nZC, freq, damp)
names(result) <- c('RefMax',
paste0('W', seq_len(n.levels)),
'range', 'N',
'energy',
'nZC',
'freq1', 'freq2', 'damp1', 'damp2')
return(as.data.frame(t(result)))
} else {
return <- NULL
}
}


Expand Down
5 changes: 3 additions & 2 deletions man/analysis.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ Analysis of partial discharge signals.
Analysis of partial discharge signals.
}
\usage{
analysis(x, threshold = 8e-3, ...)
analysis(x, threshold = 8e-3, n.levels = 4, ...)
}

\arguments{
\item{x}{numeric, a partial discharge signal.}
\item{threshold}{numeric, relative value. The threshold is calculated
with the product of this value and the absolute maximum value of
\code{x}. See \code{\link{no0}}}
\item{n.levels}{numeric, number of wavelet levels}
\item{\dots}{additional arguments for \code{\link{wavVarPD}}
}
}
Expand All @@ -27,7 +28,7 @@ Prony's method (\code{\link{prony}}).
}
\value{A \code{data.frame} with:
\item{RefMax}{Maximum location.}
\item{W1, W2, W3 and W4}{Wavelet variances of the first 4 levels.}
\item{W1, W2, ...}{Wavelet variances of the first \code{n.levels} levels.}
\item{range}{Range of the signal.}
\item{N}{Number of samples of the signal.}
\item{energy}{Energy of the signal calculated as the sum of the
Expand Down

0 comments on commit 0b53946

Please sign in to comment.