fourierin_1d: Univariate Fourier integrals

Description Usage Arguments Details Value Examples

View source: R/fourierin.R

Description

It computes Fourier integrals of functions of one and two variables on a regular grid.

Usage

1
2
3
fourierin_1d(f, lower_int, upper_int, lower_eval = NULL, upper_eval = NULL,
  const_adj, freq_adj, resolution = NULL, eval_grid = NULL,
  use_fft = TRUE)

Arguments

f

function or a vector of size m. If a function is provided, it must be able to be evaluated at vectors. If a vector of values is provided, such evaluations must have been obtained on a regular grid and the Fourier integral is faster is m is a power of 2.

lower_int

Lower integration limit(s).

upper_int

Upper integration limit(s).

lower_eval

Lower evaluation limit(s). It can be NULL if an evaluation grid is provided.

upper_eval

Upper evaluation limit(s). It can be NULL if an evaluation grid is provided.

const_adj

Factor related to adjust definition of Fourier transform. It is usually equal to 0, -1 or 1.

freq_adj

Constant to adjust the exponent on the definition of the Fourier transform. It is usually equal to 1, -1, 2pi or -2pi.

resolution

A vector of integers (faster if powers of two) determining the resolution of the evaluation grid. Not required if f is a vector.

eval_grid

Optional matrix with d columns with the points where the Fourier integral will be evaluated. If it is provided, the FFT will not be used.

use_fft

Logical value specifying whether the FFT will be used.

Details

See vignette for more detailed examples.

Value

If w is given, only the values of the Fourier integral are returned, otherwise, a list with the elements

w

A vector of size m where the integral was computed.

values

A complex vector of size m with the values of the integral

Examples

 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
##--- Example 1 ---------------------------------------------------
##--- Recovering std. normal from its characteristic function -----
library(fourierin)

#' Function to to be used in integrand
myfun <- function(t) exp(-t^2/2)

                                        # Compute Foueien integral
out <- fourierin_1d(f = myfun,
                    lower_int = -5, upper_int = 5,
                    lower_eval = -3, upper_eval = 3,
                    const_adj = -1, freq_adj = -1,
                    resolution = 64)

## Extract grid and values
grid <- out$w
values <- Re(out$values)

plot(grid, values, type = "l", col = 3)
lines(grid, dnorm(grid), col = 4)

##--- Example 2 -----------------------------------------------
##--- Computing characteristic function of a gamma r. v. ------

library(fourierin)

## Function to to be used in integrand
myfun <- function(t) dgamma(t, shape, rate)

## Compute integral
shape <- 5
rate <- 3
out <- fourierin_1d(f = myfun, lower_int = 0, upper_int = 6,
                    lower_eval = -4, upper_eval = 4,
                    const_adj = 1, freq_adj = 1, resolution = 64)

grid <- out$w                           # Extract grid
re_values <- Re(out$values)             # Real values
im_values <- Im(out$values)             # Imag values

                                     # Now compute the real and
                                     # imaginary true values of the
                                        # characteric function.
true_cf <- function(t, shape, rate) (1 - 1i*t/rate)^-shape
true_re <- Re(true_cf(grid, shape, rate))
true_im <- Im(true_cf(grid, shape, rate))

                                     # Compare them. We can see a
                                     # slight discrepancy on the
                                     # tails, but that is fixed
                                     # when resulution is
                                     # increased.
plot(grid, re_values, type = "l", col = 3)
lines(grid, true_re, col = 4)

                                        # Same here
plot(grid, im_values, type = "l", col = 3)
lines(grid, true_im, col = 4)

gbasulto/fourierin documentation built on Feb. 14, 2018, 3:21 a.m.