Transform analog voltage signals with 'Morlet' wavelets: complex wavelet kernels with \(\pi/2\) phase differences.
Arguments
- freqs
frequency in which
data
will be projected on- srate
sample rate, number of time points per second
- wave_num
desired number of cycles in wavelet kernels to balance the precision in time and amplitude (control the smoothness); positive integers are strongly suggested
- data
numerical vector such as analog voltage signals
- precision
the precision of computation; choices are
'float'
(default) and'double'
.- trend
choices are
'constant'
: center the signal at zero;'linear'
: remove the linear trend;'none'
do nothing- signature
signature to calculate kernel path to save, internally used
- ...
further passed to
detrend
;- frequency_range
frequency range to calculate, default is 2 to 200
- cycle_range
number of cycles corresponding to
frequency_range
. For default frequency range (2 - 200), the defaultcycle_range
is 3 to 20. That is, 3 wavelet kernel cycles at 2 Hertz, and 20 cycles at 200 Hertz.
Value
wavelet_kernels
returns wavelet kernels to be
used for wavelet function; morlet_wavelet
returns a file-based array
if precision
is 'float'
, or a list of real and imaginary
arrays if precision
is 'double'
Examples
if(interactive()){
# generate sine waves
time <- seq(0, 3, by = 0.01)
x <- sin(time * 20*pi) + exp(-time^2) * cos(time * 10*pi)
plot(time, x, type = 'l')
# freq from 1 - 15 Hz; wavelet using float precision
freq <- seq(1, 15, 0.2)
coef <- morlet_wavelet(x, freq, 100, c(2,3))
# to get coefficients in complex number from 1-10 time points
coef[1:10, ]
# power
power <- Mod(coef[])^2
# Power peaks at 5Hz and 10Hz at early stages
# After 1.0 second, 5Hz component fade away
image(power, x = time, y = freq, ylab = "frequency")
# wavelet using double precision
coef2 <- morlet_wavelet(x, freq, 100, c(2,3), precision = "double")
power2 <- (coef2$real[])^2 + (coef2$imag[])^2
image(power2, x = time, y = freq, ylab = "frequency")
# The maximum relative change of power with different precisions
max(abs(power/power2 - 1))
# display kernels
freq <- seq(1, 15, 1)
kern <- wavelet_kernels(freq, 100, c(2,3))
print(kern)
plot(kern)
}