[R] Fourier Transform

Foadi, J (James) james.foadi at diamond.ac.uk
Thu Jun 5 17:23:09 CEST 2008


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


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

Email    :  james.foadi at diamond.ac.uk
Alt Email:  j.foadi at imperial.ac.uk
<DIV><FONT size="1" color="gray">This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
</FONT></DIV> 



More information about the R-help mailing list