Learn R Programming

fftab

The goal of fftab is to make working with fft’s in R easier and more consistent. It follows the tidy philosophy by working with tabular data rather than lists, vectors, and so on. Typical signal processing operations can thus often be accomplished in a single dplyr::mutate call or by a call to similar functions. Some examples are shown here.

Installation

You can install the development version of fftab from GitHub with:

# install.packages("pak")
pak::pak("thk686/fftab")

Example

Using fftab with ggplot.

fftab(sunspot.month, norm = TRUE) |>
  to_rect(.keep = "all") |>
  to_polr(.keep = "all") |>
  print(n = 5) ->
ssm.fft
#> # A tibble: 3,177 × 6
#>    .dim_1 fx              re     im   mod    arg
#>     <dbl> <cpl>        <dbl>  <dbl> <dbl>  <dbl>
#> 1 0       51.96+0.00i 52.0    0     52.0   0    
#> 2 0.00378  4.37+4.99i  4.37   4.99   6.63  0.852
#> 3 0.00755 -0.86+5.08i -0.860  5.08   5.15  1.74 
#> 4 0.0113  -2.65-5.70i -2.65  -5.70   6.29 -2.01 
#> 5 0.0151  -4.64-0.59i -4.64  -0.586  4.68 -3.02 
#> # ℹ 3,172 more rows
ggplot(fortify(sunspot.month)) +
  geom_line(aes(x = Index, y = Data)) +
  ylab("Sunspot count") +
  xlab("Year") +
  theme_bw() ->
p1

xlocs <- c(1, 0.1, 0.01)
xlabs <- c("1", "10", "100")

ssm.fft |>
  dplyr::filter(.dim_1 > 0) |>
  ggplot() +
  geom_point(aes(x = .dim_1, y = mod)) +
  geom_smooth(aes(x = .dim_1, y = mod)) +
  scale_y_continuous(trans = "log", labels = function(y) signif(y, 1)) +
  scale_x_continuous(trans = "log", breaks = xlocs, labels = xlabs) +
  xlab("Cycle duration (years)") +
  ylab("Mean amplitude") +
  theme_bw() ->
p2

print(p1 / p2)

Copy Link

Version

Install

install.packages('fftab')

Monthly Downloads

136

Version

0.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Timothy H Keitt

Last Published

January 15th, 2025

Functions in fftab (0.1.0)

.is_ts

Check if an Object is a Time Series
.is_normalized

Check if an Object is Normalized
.nyquist

Compute Nyquist Frequency
.num_samples

Compute the number of samples in an input
.phase_diff

Compute Phase Difference Between Two Signals
.set_repr

Set Representation Format
.get_dim_cols

Select Columns Starting with .dim_
fftab-package

fftab: Tidy Manipulation of Fourier Transformed Data
.frequency

Retrieve Frequency
fft_internal_filters

Remove DC Component and Symmetric Frequencies
has_cplx

Check Representations of a fftab Object
plot.fftab

Plot the modulus of FFT results
.size

Retrieve Object Size
.shift_phase

Shift Phase
get_rect

Extract Rectangular or Polar Components
get_fx

Extract Fourier Coefficients and Components
fftab

Perform FFT and IFFT with Tidy Results
fourier_frequencies

Compute Fourier Frequencies
.is_array

Check if an Object is an Array
phase_diff

Compute Phase Difference and Maximum Correlation Between Two Signals
.is_complex

Check if an Object is Complex
.tsp

Retrieve Time Series Parameters
.variance

Compute Variance
to_cplx

Convert a fftab Object Between Representations
add_cplx

Add Additional Representations to Fourier Coefficients
.as_fftab_obj

Build a FFTAB Object
add_l2nm

Add L2 Norm and Squared L2 Norm of Frequency Dimensions
cross_spec

Compute the Cross-Spectrum (Cross FFT)
can_repr

Manage Representations of a fftab Object
.fourier_frequencies

Compute Fourier frequencies for default inputs
.fft

Compute the Fast Fourier Transform (FFT) of a Vector
.correlation

Compute Normalized Correlation Between Two Signals
.find_dc_row

Binary search for the DC row in lexicographically sorted data
.dim

Retrieve Object Dimensions