# Re: [R] Fourier Transform

Date: Thu, 05 Jun 2008 16:23:09 +0100

-----Original Message-----
From: r-help-bounces_at_r-project.org on behalf of Neil Gupta Sent: Thu 6/5/2008 15:21
To: R-help_at_r-project.org
Subject: [R] Fourier Transform

Hello All,

I wanted to perform a fourier transform on high frequency financial data. I have searched and have not found much on this topic for R. I was wondering if anyone has used any libraries for it or have come across any papers I may read.

Many Thanks,

Neil Gupta

Dear Neil,
I'm not sure this can be of any help, but here it is anyway.

Given a real function, sample it:

## Sampled density (N points)
sample_rho <- function(rho,N)
{
xS <- seq(0,1,length=N+1)[1:N]
yS <- rho(xS)
xSyS <- list(xS,yS)
return(xSyS)
}

Then use these sampled values to perform Fourier transform:

```xS <- sample_rho(rho,N)[[1]]
yS <- sample_rho(rho,N)[[2]]
F_complex <- fft(yS)/length(yS)
```

F <- Mod(F_complex)
f <- Arg(F_complex)
```F[1] <- Re(F_complex[1])
f[1] <- 0

------------------------------

```

I have used these and other similar lines when writing an educational paper on Fourier transforms and aliasing:

J. Foadi - "A simple approach to Fourier aliasing" - Eur J Phys 28 (2007) 551-561

My best regards,

James

Membrane Protein Laboratory (MPL)
Diamond Light Source Ltd
Diamond House
Harewell Science and Innovation Campus
Chilton, Didcot
Oxfordshire OX11 0DE