Transform analog voltage signals with 'Morlet' wavelets: complex wavelet kernels with $$\pi/2$$ phase differences.

Usage

wavelet_kernels(freqs, srate, wave_num)

morlet_wavelet(
data,
freqs,
srate,
wave_num,
precision = c("float", "double"),
trend = c("constant", "linear", "none"),
signature = NULL,
...
)

wavelet_cycles_suggest(
freqs,
frequency_range = c(2, 200),
cycle_range = c(3, 20)
)

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 default cycle_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


# \donttest{

# 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, ]
#>                          [,1]                   [,2]                    [,3]
#>  [1,]  0.079415046+0.1186043i  0.09068563+0.1566062i  0.081491686+0.2158995i
#>  [2,]  0.070035875+0.1221303i  0.07500284+0.1634681i  0.053901780+0.2204804i
#>  [3,]  0.060283009+0.1248344i  0.05994895+0.1687918i  0.028882088+0.2217750i
#>  [4,]  0.050308734+0.1270776i  0.04561965+0.1722808i  0.006465297+0.2200116i
#>  [5,]  0.040320020+0.1290842i  0.03170361+0.1737074i -0.014214927+0.2154187i
#>  [6,]  0.030511839+0.1308505i  0.01765361+0.1729923i -0.034401946+0.2081803i
#>  [7,]  0.021003243+0.1321430i  0.00295374+0.1702363i -0.055064443+0.1984321i
#>  [8,]  0.011802451+0.1325862i -0.01261945+0.1656932i -0.076370113+0.1862965i
#>  [9,]  0.002815931+0.1318068i -0.02884216+0.1596938i -0.097490542+0.1719405i
#> [10,] -0.006100574+0.1295805i -0.04505559+0.1525505i -0.116815194+0.1556303i
#>                         [,4]                   [,5]                   [,6]
#>  [1,]  0.09494893+0.2750027i  0.07831753+0.3720973i  0.12207478+0.4939324i
#>  [2,]  0.05750818+0.2820133i  0.02066774+0.3739292i  0.02797596+0.5025347i
#>  [3,]  0.02137382+0.2835686i -0.03839022+0.3655892i -0.06338145+0.4926330i
#>  [4,] -0.01272639+0.2795582i -0.09631336+0.3473318i -0.14782295+0.4650585i
#>  [5,] -0.04462781+0.2700548i -0.14979412+0.3199039i -0.22251487+0.4214858i
#>  [6,] -0.07452112+0.2553693i -0.19543830+0.2845643i -0.28576091+0.3642318i
#>  [7,] -0.10262396+0.2360650i -0.23056759+0.2430175i -0.33649319+0.2960882i
#>  [8,] -0.12886351+0.2129196i -0.25385961+0.1972672i -0.37372234+0.2202145i
#>  [9,] -0.15269735+0.1868443i -0.26559499+0.1494193i -0.39621446+0.1400774i
#> [10,] -0.17314655+0.1587818i -0.26742333+0.1014823i -0.40256131+0.0593922i
#>                          [,7]                    [,8]                    [,9]
#>  [1,]  0.123074822+0.6599417i  0.29512212+0.80541188i  0.481908888+0.9416207i
#>  [2,] -0.009155749+0.6693053i  0.11448307+0.86292142i  0.256427228+1.0539577i
#>  [3,] -0.145165384+0.6481661i -0.07666951+0.87634575i  0.003848762+1.1080878i
#>  [4,] -0.276914090+0.5966316i -0.26706496+0.84258908i -0.259800225+1.0963969i
#>  [5,] -0.395405680+0.5168822i -0.44542515+0.76171952i -0.516965687+1.0158346i
#>  [6,] -0.491899669+0.4131744i -0.60101658+0.63718253i -0.749713719+0.8684299i
#>  [7,] -0.559261739+0.2916004i -0.72409075+0.47574779i -0.940880179+0.6614633i
#>  [8,] -0.593079686+0.1596200i -0.80632752+0.28717023i -1.075251460+0.4072578i
#>  [9,] -0.592241049+0.0254319i -0.84138227+0.08357185i -1.140798926+0.1225601i
#> [10,] -0.558839977-0.1027219i -0.82555842-0.12141941i -1.129926801-0.1725127i
#>                         [,10]                  [,11]                  [,12]
#>  [1,]  0.613101900+1.1134408i  0.97635090+1.0530784i  1.2249333+1.01607740i
#>  [2,]  0.334765136+1.2709807i  0.70727330+1.3227400i  0.9577800+1.37094104i
#>  [3,]  0.009571603+1.3525786i  0.35680702+1.5176992i  0.5832236+1.65095401i
#>  [4,] -0.339798450+1.3449109i -0.05261636+1.6127059i  0.1244914+1.82088077i
#>  [5,] -0.685791612+1.2415154i -0.48996174+1.5897704i -0.3844635+1.85322142i
#>  [6,] -0.998754323+1.0440711i -0.91824609+1.4408896i -0.9013491+1.73211050i
#>  [7,] -1.250209093+0.7628828i -1.29823387+1.1698096i -1.3790479+1.45617616i
#>  [8,] -1.416096091+0.4164638i -1.59268785+0.7925254i -1.7700713+1.03991318i
#>  [9,] -1.479472041+0.0302225i -1.77058423+0.3363909i -2.0316057+0.51328421i
#> [10,] -1.432301402-0.3656267i -1.81071901-0.1620989i -2.1306221-0.08051831i
#>                        [,13]                 [,14]                 [,15]
#>  [1,]  1.35191715+1.1092380i  1.6438580+0.7382753i  1.7838074+0.8809177i
#>  [2,]  1.05171585+1.5203370i  1.4613980+1.2524108i  1.5476340+1.4624588i
#>  [3,]  0.62185955+1.8432338i  1.1074976+1.7156254i  1.1065426+1.9686555i
#>  [4,]  0.09072659+2.0339305i  0.5994499+2.0676584i  0.4901076+2.3258750i
#>  [5,] -0.49923444+2.0586474i -0.0239758+2.2552743i -0.2442087+2.4738417i
#>  [6,] -1.09487903+1.8989538i -0.7057343+2.2403517i -1.0182161+2.3757749i
#>  [7,] -1.63736320+1.5553236i -1.3766049+2.0062461i -1.7437997+2.0248806i
#>  [8,] -2.06835794+1.0485209i -1.9633654+1.5613497i -2.3352664+1.4461050i
#>  [9,] -2.33684039+0.4185183i -2.3978601+0.9392623i -2.7209735+0.6930609i
#> [10,] -2.40563107-0.2790205i -2.6256561+0.1955671i -2.8523569-0.1590180i
#>                       [,16]                 [,17]                  [,18]
#>  [1,]  2.0009513+0.4329820i  2.1021199+0.2082681i  2.1996233-0.01233783i
#>  [2,]  1.9174918+1.1055355i  2.0970860+0.9460760i  2.2720675+0.79616457i
#>  [3,]  1.5851542+1.7526965i  1.8063605+1.6844114i  2.0168366+1.63061273i
#>  [4,]  1.0173950+2.2799182i  1.2368711+2.3078260i  1.4356301+2.35038424i
#>  [5,]  0.2667023+2.6022451i  0.4453299+2.7107744i  0.5929527+2.82652712i
#>  [6,] -0.5827126+2.6594913i -0.4710104+2.8182421i -0.3962666+2.96917272i
#>  [7,] -1.4283910+2.4268260i -1.3921632+2.5997078i -1.3905101+2.74522424i
#>  [8,] -2.1661053+1.9187409i -2.1971214+2.0734994i -2.2502131+2.18229890i
#>  [9,] -2.7056894+1.1860645i -2.7841260+1.3013198i -2.8633745+1.35905087i
#> [10,] -2.9831216+0.3073068i -3.0850532+0.3752776i -3.1621120+0.38584641i
#>                         [,19]                  [,20]                 [,21]
#>  [1,]  2.33506536+0.69246244i  2.4501245+0.06454356i  2.4651997-0.2008947i
#>  [2,]  2.13033867+1.47070014i  2.4586723+0.90580237i  2.5679915+0.6772068i
#>  [3,]  1.65624738+2.17644382i  2.1613877+1.74592674i  2.3369265+1.5861278i
#>  [4,]  0.94257206+2.71395230i  1.5647689+2.47089338i  1.7692572+2.3947690i
#>  [5,]  0.05369809+3.00124192i  0.7201751+2.97369766i  0.9166396+2.9778409i
#>  [6,] -0.91813743+2.98262143i -0.2820088+3.17148042i -0.1218577+3.2377720i
#>  [7,] -1.86402524+2.63782454i -1.3249383+3.01895523i -1.2157197+3.1214414i
#>  [8,] -2.67228317+1.98626935i -2.2821121+2.51580286i -2.2242208+2.6285341i
#>  [9,] -3.24295902+1.08581531i -3.0352345+1.70700836i -3.0182986+1.8104304i
#> [10,] -3.50081182+0.02629376i -3.4900486+0.67652702i -3.4987714+0.7607290i
#>                         [,22]                  [,23]                  [,24]
#>  [1,]  2.471909523-0.4527444i  2.48310828-0.6981176i  2.5095661-0.94233018i
#>  [2,]  2.666216373+0.4641936i  2.76812243+0.2656741i  2.8854177+0.08128414i
#>  [3,]  2.495334387+1.4436839i  2.65026212+1.3234967i  2.8117075+1.22942650i
#>  [4,]  1.947960377+2.3341198i  2.11079621+2.2983096i  2.2642350+2.29364872i
#>  [5,]  1.078675508+2.9894106i  1.21106923+3.0197523i  1.3163128+3.07550859i
#>  [6,] -0.001040098+3.2969441i  0.08025372+3.3597388i  0.1214682+3.43147302i
#>  [7,] -1.143531799+3.1981289i -1.11204588+3.2573230i -1.1230568+3.30240774i
#>  [8,] -2.192038298+2.6972275i -2.19056463+2.7272103i -2.2209857+2.72054148i
#>  [9,] -3.007503033+1.8574508i -3.00727081+1.8511975i -3.0171371+1.79388797i
#> [10,] -3.489273787+0.7865683i -3.46451735+0.7565802i -3.4226763+0.67477643i
#>                        [,25]                  [,26]                 [,27]
#>  [1,]  2.5597193-1.18711960i  2.63878536-1.4304572i  3.0148675-1.1060885i
#>  [2,]  3.0256851-0.08753117i  3.19160414-0.2379207i  3.3878024+0.2944070i
#>  [3,]  2.9846883+1.16450822i  3.16900539+1.1302563i  3.0822475+1.7566789i
#>  [4,]  2.4102669+2.32293010i  2.54688358+2.3848839i  2.1465552+2.9471982i
#>  [5,]  1.3942275+3.15792918i  1.44301248+3.2628736i  0.7859895+3.6041443i
#>  [6,]  0.1219929+3.51163125i  0.08234455+3.5946085i -0.6990706+3.6061065i
#>  [7,] -1.1757939+3.33207870i -1.26614952+3.3417084i -1.9999197+2.9959815i
#>  [8,] -2.2801137+2.67692685i -2.36046910+2.5953102i -2.8828051+1.9547400i
#>  [9,] -3.0318129+1.68811870i -3.04227376+1.5381390i -3.2425628+0.7364987i
#> [10,] -3.3580842+0.54776108i -3.26310921+0.3851931i -3.1116619-0.4113465i
#>                       [,28]                 [,29]                  [,30]
#>  [1,]  3.1947560-1.2840021i  2.7357285-2.1535256i  3.3279779-1.69316530i
#>  [2,]  3.6036561+0.2503167i  3.6075091-0.7159399i  3.9045222+0.03994172i
#>  [3,]  3.2497482+1.8335520i  3.6868143+1.0097815i  3.5580297+1.86702156i
#>  [4,]  2.2070611+3.0870326i  2.9319055+2.5869319i  2.3700070+3.30611634i
#>  [5,]  0.7279506+3.7271509i  1.5323865+3.6237602i  0.6599216+3.99466658i
#>  [6,] -0.8363473+3.6419389i -0.1533425+3.8883989i -1.1195199+3.79596090i
#>  [7,] -2.1415222+2.9114096i -1.7115843+3.3696992i -2.5263419+2.82949495i
#>  [8,] -2.9469476+1.7675955i -2.7988815+2.2656636i -3.2632554+1.41731334i
#>  [9,] -3.1723278+0.5106685i -3.2375839+0.9062406i -3.2568700-0.03253290i
#> [10,] -2.8981290-0.5882277i -3.0509958-0.3605143i -2.6575718-1.16304982i
#>                        [,31]                 [,32]                  [,33]
#>  [1,]  3.5382948-1.81696606i  2.9342194-2.7534552i  3.6709437-2.11524653i
#>  [2,]  4.1170473+0.05529752i  4.0583143-1.0410227i  4.3653116-0.06902755i
#>  [3,]  3.6894689+1.98786068i  4.1655478+1.0338389i  3.9176700+2.06103587i
#>  [4,]  2.3747342+3.45822501i  3.2175047+2.8887649i  2.4613724+3.66616106i
#>  [5,]  0.5473364+4.09270239i  1.4931444+4.0163007i  0.4339745+4.31117916i
#>  [6,] -1.2882986+3.77727675i -0.5071648+4.1427193i -1.5715019+3.86947823i
#>  [7,] -2.6614833+2.67991257i -2.2284436+3.3058789i -3.0036790+2.55163646i
#>  [8,] -3.2807407+1.17913353i -3.2405860+1.8271718i -3.5297272+0.81978035i
#>  [9,] -3.1119680-0.27367055i -3.3686996+0.1897533i -3.1312408-0.78021222i
#> [10,] -2.3648248-1.30815506i -2.7306361-1.1321286i -2.0876002-1.80792630i
#>                       [,34]                 [,35]                 [,36]
#>  [1,]  2.9656105-3.0569928i  3.7645516-2.3299246i  2.9743092-3.2672565i
#>  [2,]  4.2366405-1.2268951i  4.5376792-0.1521685i  4.3441257-1.3547779i
#>  [3,]  4.3819547+1.0208271i  4.0662217+2.1213930i  4.5107627+1.0105745i
#>  [4,]  3.3531106+3.0267251i  2.4977989+3.8164403i  3.4213076+3.1136911i
#>  [5,]  1.4668674+4.2151313i  0.3209561+4.4532270i  1.4221781+4.3312898i
#>  [6,] -0.7044845+4.2794075i -1.8023022+3.8995938i -0.8611342+4.3361416i
#>  [7,] -2.5267656+3.2736807i -3.2598472+2.4036007i -2.7376585+3.1983204i
#>  [8,] -3.5138578+1.5806044i -3.6906185+0.4957319i -3.6832633+1.3490076i
#>  [9,] -3.4809539-0.2317493i -3.0936787-1.2034105i -3.5104220-0.5793013i
#> [10,] -2.5886061-1.6117542i -1.8081353-2.2006013i -2.4163253-1.9785502i
#>                       [,37]                 [,38]                [,39]
#>  [1,]  3.7988098-2.4735126i  3.7240367-2.5138834i  2.848142-3.3984356i
#>  [2,]  4.6218805-0.2154855i  4.5936208-0.2585213i  4.309911-1.4724206i
#>  [3,]  4.1349535+2.1437199i  4.1358562+2.1295335i  4.524998+0.9565532i
#>  [4,]  2.4966784+3.8864796i  2.4933510+3.9134400i  3.419847+3.1316411i
#>  [5,]  0.2307914+4.5049353i  0.1888932+4.5594788i  1.349867+4.3830142i
#>  [6,] -1.9543053+3.8661289i -2.0535977+3.9126203i -1.022831+4.3513274i
#>  [7,] -3.4069319+2.2469442i -3.5555210+2.2411225i -2.956120+3.1039290i
#>  [8,] -3.7500093+0.2272735i -3.9115138+0.1348012i -3.880315+1.1032375i
#>  [9,] -2.9989638-1.5200574i -3.1188779-1.7068865i -3.587958-0.9616780i
#> [10,] -1.5386397-2.4671452i -1.5630968-2.7213631i -2.293884-2.4206567i
#>                        [,40]                [,41]                [,42]
#>  [1,]  3.6828005-2.56395578i  2.761570-3.4309258i  2.697829-3.3602076i
#>  [2,]  4.5634751-0.29743251i  4.235487-1.5215883i  4.158175-1.4791826i
#>  [3,]  4.1011467+2.09802079i  4.462800+0.8944273i  4.382802+0.9116253i
#>  [4,]  2.4456556+3.87300086i  3.369932+3.0551012i  3.292628+3.0538902i
#>  [5,]  0.1338267+4.48870468i  1.315826+4.2870903i  1.240975+4.2731209i
#>  [6,] -2.0949392+3.79604626i -1.031700+4.2319622i -1.107057+4.2058239i
#>  [7,] -3.5519338+2.07986283i -2.925521+2.9637482i -3.002280+2.9199209i
#>  [8,] -3.8329611-0.04763826i -3.795239+0.9563227i -3.867757+0.8859368i
#>  [9,] -2.9502380-1.86696887i -3.439861-1.0886738i -3.494274-1.1919868i
#> [10,] -1.3152252-2.80677700i -2.088403-2.4929421i -2.105344-2.6265590i
#>                        [,43]                [,44]                [,45]
#>  [1,]  3.48999786-2.5334368i  2.544442-3.3447075i  2.503186-3.2291193i
#>  [2,]  4.37326050-0.3376532i  3.999378-1.5331479i  3.914323-1.4455364i
#>  [3,]  3.93967557+1.9972719i  4.253737+0.7902871i  4.142331+0.8351622i
#>  [4,]  2.32985616+3.7286539i  3.223722+2.8831189i  3.107003+2.8815253i
#>  [5,]  0.07079511+4.3183055i  1.249994+4.0822334i  1.146548+4.0408335i
#>  [6,] -2.10460424+3.6135612i -1.018983+4.0280361i -1.097538+3.9598446i
#>  [7,] -3.50898242+1.8954576i -2.849549+2.7845623i -2.899753+2.7032421i
#>  [8,] -3.73594475-0.2237827i -3.675160+0.8130565i -3.699316+0.7282429i
#>  [9,] -2.79644060-2.0193882i -3.290509-1.1934229i -3.292327-1.2775848i
#> [10,] -1.10634136-2.9121420i -1.917747-2.5576987i -1.898682-2.6404538i
#>                        [,46]                  [,47]                 [,48]
#>  [1,]  3.22675991-2.4543104i  3.16936731-2.3264494i  2.2516725-3.0681870i
#>  [2,]  4.09577799-0.3887969i  3.98687220-0.2996546i  3.6036687-1.4275271i
#>  [3,]  3.71405125+1.8257535i  3.57841039+1.8577497i  3.8546040+0.6978704i
#>  [4,]  2.20676637+3.4778445i  2.07414913+3.4499581i  2.9188864+2.6214142i
#>  [5,]  0.07133675+4.0468121i -0.03262736+3.9715414i  1.1053289+3.7252259i
#>  [6,] -1.99250209+3.3786633i -2.05344319+3.2779968i -0.9882566+3.6687562i
#>  [7,] -3.32244253+1.7365087i -3.33950329+1.6333746i -2.6785631+2.5032365i
#>  [8,] -3.52153063-0.2932601i -3.50422382-0.3824753i -3.4306126+0.6528968i
#>  [9,] -2.59439421-2.0090032i -2.55622244-2.0778134i -3.0427537-1.2333857i
#> [10,] -0.94098085-2.8445752i -0.89316702-2.8949780i -1.7164109-2.5121295i
#>                       [,49]                  [,50]                  [,51]
#>  [1,]  2.2379272-2.9190328i  2.85429287-2.2382662i  2.81143618-2.0874882i
#>  [2,]  3.5200524-1.3000990i  3.65874243-0.3844451i  3.54727221-0.2714689i
#>  [3,]  3.7209268+0.7718943i  3.33056664+1.6158565i  3.17914605+1.6616915i
#>  [4,]  2.7682154+2.6257722i  1.97751117+3.1148076i  1.82576144+3.0843074i
#>  [5,]  0.9734974+3.6637704i  0.04677613+3.6347287i -0.06792398+3.5415542i
#>  [6,] -1.0741578+3.5630214i -1.82675016+3.0279505i -1.88161290+2.9026690i
#>  [7,] -2.7079351+2.3836157i -3.03541231+1.5262964i -3.02829432+1.4043519i
#>  [8,] -3.4102044+0.5474176i -3.20728374-0.3378769i -3.15437937-0.4286765i
#>  [9,] -2.9910266-1.3077666i -2.33697987-1.9172329i -2.26425886-1.9646611i
#> [10,] -1.6546948-2.5526402i -0.78812933-2.6809320i -0.72075182-2.6895740i
#>                       [,52]                 [,53]                 [,54]
#>  [1,]  1.9383160-2.7660811i  1.9426708-2.6107895i  2.4555550-2.0470860i
#>  [2,]  3.1706400-1.3242352i  3.0965977-1.1839021i  3.2094612-0.4271744i
#>  [3,]  3.4232113+0.5666487i  3.2892559+0.6534200i  2.9624896+1.3453621i
#>  [4,]  2.6118269+2.2916737i  2.4544497+2.3021188i  1.7992355+2.6956284i
#>  [5,]  1.0057716+3.2945428i  0.8675359+3.2297530i  0.1048080+3.1933899i
#>  [6,] -0.8651598+3.2624640i -0.9504839+3.1464174i -1.5640018+2.6927052i
#>  [7,] -2.3880255+2.2297387i -2.4064577+2.0993273i -2.6623290+1.3816534i
#>  [8,] -3.0735552+0.5677451i -3.0333545+0.4587325i -2.8430495-0.2765235i
#>  [9,] -2.7266438-1.1404415i -2.6523416-1.2052492i -2.0829308-1.7013897i
#> [10,] -1.5186124-2.3052187i -1.4402789-2.3216074i -0.6962802-2.4043565i
#>                         [,55]                 [,56]                 [,57]
#>  [1,]  2.426996231-1.8957025i  1.5924708-2.5023348i  1.6099882-2.3571868i
#>  [2,]  3.108124733-0.3080825i  2.7274668-1.2787368i  2.6684124-1.1412779i
#>  [3,]  2.815939426+1.3985411i  3.0128570+0.3703721i  2.8922162+0.4605267i
#>  [4,]  1.649070740+2.6699150i  2.3595781+1.9072059i  2.2122014+1.9245251i
#>  [5,] -0.008056067+3.1012499i  0.9872150+2.8387077i  0.8558960+2.7817366i
#>  [6,] -1.613890171+2.5663905i -0.6529875+2.8738313i -0.7334973+2.7651930i
#>  [7,] -2.646287203+1.2600824i -2.0233135+2.0175419i -2.0381184+1.8939205i
#>  [8,] -2.778956175-0.3617870i -2.6769223+0.5753644i -2.6337724+0.4732825i
#>  [9,] -2.000647068-1.7356418i -2.4162481-0.9440653i -2.3400021-1.0003659i
#> [10,] -0.626008987-2.3924577i -1.3714346-2.0078161i -1.2936904-2.0129032i
#>                       [,58]                 [,59]                  [,60]
#>  [1,]  1.6291827-2.2108769i  2.0223403-1.7778202i  2.00940514-1.6374005i
#>  [2,]  2.6094227-1.0017039i  2.6900053-0.4249961i  2.60582161-0.3082213i
#>  [3,]  2.7694368+0.5524032i  2.5141609+1.0708392i  2.38223267+1.1286596i
#>  [4,]  2.0610187+1.9416360i  1.5615888+2.2280574i  1.42177904+2.2107973i
#>  [5,]  0.7207387+2.7217536i  0.1451238+2.6827528i  0.03840881+2.6000226i
#>  [6,] -0.8158651+2.6510684i -1.2755371+2.2973690i -1.32243276+2.1793768i
#>  [7,] -2.0512769+1.7637738i -2.2354569+1.2098864i -2.21786451+1.0946852i
#>  [8,] -2.5850189+0.3656787i -2.4219310-0.1994630i -2.35607314-0.2794580i
#>  [9,] -2.2550507-1.0591658i -1.7948811-1.4335548i -1.71031666-1.4614041i
#> [10,] -1.2061895-2.0161519i -0.6114144-2.0609083i -0.54006964-2.0394278i
#>                        [,61]                 [,62]                 [,63]
#>  [1,]  1.99615645-1.4968544i  1.2678558-2.0402925i  1.2967606-1.9145942i
#>  [2,]  2.52061081-0.1913637i  2.1991014-1.0498766i  2.1580286-0.9234648i
#>  [3,]  2.24848437+1.1857940i  2.4355311+0.2844589i  2.3338258+0.3730831i
#>  [4,]  1.27999616+2.1914680i  1.9147528+1.5273854i  1.7831541+1.5506623i
#>  [5,] -0.06936412+2.5138381i  0.8132340+2.2901611i  0.6925207+2.2435155i
#>  [6,] -1.36851454+2.0571926i -0.5167341+2.3371105i -0.5922088+2.2397795i
#>  [7,] -2.19708753+0.9756001i -1.6453965+1.6567386i -1.6593624+1.5423422i
#>  [8,] -2.28480148-0.3618382i -2.1991041+0.4817950i -2.1564450+0.3855393i
#>  [9,] -1.61900711-1.4891160i -1.9989907-0.7748259i -1.9219477-0.8273582i
#> [10,] -0.46219048-2.0148447i -1.1402282-1.6666828i -1.0599476-1.6670697i
#>                       [,64]                 [,65]                  [,66]
#>  [1,]  1.3243761-1.7895404i  1.5979588-1.4822203i  1.59880424-1.3624456i
#>  [2,]  2.1158495-0.7980021i  2.1613417-0.3987669i  2.09815860-0.2932374i
#>  [3,]  2.2310457+0.4603490i  2.0468531+0.8056440i  1.93754470+0.8631279i
#>  [4,]  1.6506625+1.5719366i  1.3091894+1.7543641i  1.18867564+1.7466685i
#>  [5,]  0.5715532+2.1942551i  0.1826939+2.1592472i  0.08791818+2.0927930i
#>  [6,] -0.6668748+2.1395898i -0.9780500+1.8916150i -1.02215946+1.7913973i
#>  [7,] -1.6712238+1.4253479i -1.7916812+1.0368446i -1.77874470+0.9357197i
#>  [8,] -2.1103542+0.2875044i -1.9826471-0.1094808i -1.92472172-0.1816265i
#>  [9,] -1.8404368-0.8802667i -1.4976486-1.1376160i -1.42028952-1.1629936i
#> [10,] -0.9748936-1.6660146i -0.5367500-1.6811993i -0.46989784-1.6597471i
#>                         [,67]                 [,68]                 [,69]
#>  [1,]  1.597956538-1.2439231i  0.9398270-1.7105370i  0.9755515-1.6103427i
#>  [2,]  2.033836126-0.1894441i  1.7325824-0.9394110i  1.7097660-0.8318992i
#>  [3,]  1.827662945+0.9184634i  1.9711685+0.1225555i  1.8938630+0.2032667i
#>  [4,]  1.068315148+1.7365732i  1.6082021+1.1354973i  1.5012285+1.1633288i
#>  [5,] -0.005889252+2.0240428i  0.7654062+1.7993118i  0.6633980+1.7682818i
#>  [6,] -1.064555883+1.6893046i -0.3020929+1.9090847i -0.3695053+1.8333771i
#>  [7,] -1.763421178+0.8333433i -1.2527838+1.4199094i -1.2700042+1.3260312i
#>  [8,] -1.863810062-0.2541806i -1.7625654+0.4932239i -1.7308873+0.4107738i
#>  [9,] -1.339606285-1.1877015i -1.6571842-0.5404754i -1.5934587-0.5878278i
#> [10,] -0.399889022-1.6364752i -0.9931343-1.3063893i -0.9238878-1.3087059i
#>                       [,70]                 [,71]
#>  [1,]  1.0089647-1.5111580i  1.0396967-1.4129652i
#>  [2,]  1.6853703-0.7260948i  1.6590753-0.6222578i
#>  [3,]  1.8157876+0.2818265i  1.7368206+0.3578002i
#>  [4,]  1.3943741+1.1888105i  1.2877952+1.2115057i
#>  [5,]  0.5623614+1.7351103i  0.4626952+1.6995418i
#>  [6,] -0.4353651+1.7560649i -0.4991703+1.6771836i
#>  [7,] -1.2853483+1.2311652i -1.2983905+1.1356310i
#>  [8,] -1.6970941+0.3279551i -1.6609907+0.2452661i
#>  [9,] -1.5274355-0.6348679i -1.4592371-0.6810863i
#> [10,] -0.8523360-1.3099889i -0.7789017-1.3098996i

# 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))
#> [1] 6.914835e-05

# display kernels
freq <- seq(1, 15, 1)
kern <- wavelet_kernels(freq, 100, c(2,3))
print(kern)
#> Discrete wavelet kernels
#>   number of kernels/frequencies: 15
#>   frequency range: 1.00 Hz - 15.00 Hz
#>   number of cycles: 2.00 - 3.00

plot(kern)

# }