-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
125 lines (91 loc) · 5.04 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dpi = 300,
fig.width = 8
)
```
# fCWTr <a href="https://lschneiderbauer.github.io/fCWTr/"><img src="man/figures/logo.svg" align="right" height="139" alt="fCWTr website" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/lschneiderbauer/fCWTr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/lschneiderbauer/fCWTr/actions/workflows/R-CMD-check.yaml) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![CRAN status](https://www.r-pkg.org/badges/version/fCWTr)](https://CRAN.R-project.org/package=fCWTr) [![Codecov test coverage](https://codecov.io/gh/lschneiderbauer/fCWTr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/lschneiderbauer/fcwtr?branch=master)
<!-- badges: end -->
The R package fCWTr wraps the [fCWT library](https://github.com/fastlib/fCWT), a library implementing a [continuous wavelet transform](https://en.wikipedia.org/wiki/Continuous_wavelet_transform) with a Morlet wavelet, utilizing the power of [fftw](https://www.fftw.org/), a fast fourier transform implementation. It provides an R-like functional interface and implements common S3 methods for convenience.
See the original paper by Arts, L.P.A., van den Broek, E.L. The fast continuous wavelet transformation (fCWT) for real-time, high-quality, noise-resistant time–frequency analysis. Nat Comput Sci 2, 47–58 (2022). <https://doi.org/10.1038/s43588-021-00183-z>
## System dependencies
- R \>= 4.1
- [fftw](https://www.fftw.org/) library with [single-precision support](https://www.fftw.org/faq/section2.html#singleprec) enabled (used by [fCWT](https://github.com/fastlib/fCWT))
- Optional: a CPU/compiler supporting the [AVX](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) instruction set
- Optional: OpenMP (and fftw built with [OpenMP support](https://www.fftw.org/doc/Usage-of-Multi_002dthreaded-FFTW.html))
- On Windows, OpenMP support is disabled since rtools' fftw is compiled without OpenMP support.
- On Linux and MacOS the build scripts should automatically detect whether OpenMP support is available.
By default, most compiler setups do not make use of AVX to increase portability of the binary. If you are an R user that has a CPU supporting AVX and want to make use of it, you might need to manually enable compiler flags to let R know about it, and install the package from source (so that it gets compiled on your machine). One way to enable the flags is to create a file `~/.R/Makevars` with the following content:
``` bash
CPPFLAGS = -mavx
CXXFLAGS = -mavx
```
## Installation
You can install the latest CRAN release of fCWTr with:
``` r
install.packages("fCWTr")
```
Alternatively, you can install the development version of fCWTr like so (requiring installed [devtools](https://devtools.r-lib.org/) package):
``` r
devtools::install_github("lschneiderbauer/fCWTr")
```
Note that the installation process might fail if the package needs to be compiled from source and system requirements are not satisfied. The error message should give you hints, however, on what's missing on your system.
- Common confusion: fftw is installed, but compiled without single precision support. Please consult [fftw.org](https://www.fftw.org) for help.
## Example
This is a basic example where the continuous wavelet transform of a sample signal is calculated. The result is inspected and plotted.
```{r example}
library(fCWTr)
# A signal encoded in a numeric vector.
# In this example we use some superimposed sin signals.
signal <- ts_sin_superpos
output <-
fcwt(
signal,
x_sample_freq = u(44.1, "kHz"),
sigma = 5,
y_sample_freq = u(1, "kHz"),
freq_begin = u(16, "Hz"),
freq_end = u(2100, "Hz"),
n_freqs = 200,
freq_scale = "linear"
)
# The result is a numeric matrix with time and frequency dimension
dim(output)
# Some meta data is recorded too
output
```
The result can also be converted into a data frame:
```{r example_df}
as.data.frame(output) |>
head(10)
```
We can also directly plot the resulting scalogram:
```{r example_plot}
plot(output, time_unit = "ms")
```
For long sequences, the required memory can exceed your available local memory. In this case it can be useful to reduce the time resolution of the result and process the data in batches. This can be done with `fcwt_batch()`. In case the batch size is not explicitly provided, some heuristics are used to determine a batch size automatically:
```{r example_long_df, results='hide'}
batch_result <-
fcwt_batch(
rep(ts_sin_sin, 5),
x_sample_freq = u(44.1, "kHz"),
y_sample_freq = u(100, "Hz"),
freq_begin = u(100, "Hz"),
freq_end = u(12, "kHz"),
n_freqs = 200,
freq_scale = "linear",
sigma = 4
)
plot(batch_result)
```
<!-- regenerate with devtools::build_readme() -->