[R] Calling fft from C
Gunnar Hellmund
ghellmund at gmail.com
Sun May 30 21:35:38 CEST 2010
Thanks for the reply, but ...
No, I am not interested in the convolution function defined in the
R-extensions manual.
I want to use a fast fourier transform version implemented in C
returning values to another C function.
So the question is: How do I call the fft supplied by R in C? (just
like it is possible to use other R functions in C using #include
<Rmath.h> etc)
Best,
Gunnar
On Sun, May 30, 2010 at 8:12 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> The Writing R Extensions manual specifically uses convolve as an
> example of calling C from R.
>
> On Sun, May 30, 2010 at 2:08 PM, Gunnar Hellmund <ghellmund at gmail.com> wrote:
>> Hi
>>
>> I have made a R function 'convolve2' for convolution of two real
>> valued vectors based on Rs 'convolve' with option type="open" - see
>> below.
>> (exp.length and irf.length are variables set in another part of the program)
>>
>> I wish to implement the function convolve2 in C and use it in a
>> function used from R with .Call - e.g. I need to call fft in C.
>> All I can find in the source code is do_fft in Internals.h - but how
>> do I use do_fft? Or should I call another C routine (and how)?
>>
>> How do I solve the problem in the most appropriate way?
>>
>> convolve2=function2(x,y)
>> {
>> x<- c(rep.int(0,exp.length-1),x)
>> n <- length(y<-c(y, rep.int(0, irf.length -1)))
>> x <- fft(fft(x) * Conj(fft(y)), inverse=TRUE)
>> return(Re(x)/n)
>> }
>>
>> --
>> Best wishes/bedste hilsner
>>
>> Gunnar Hellmund
>>
>> cand. scient., PhD
>> http://staff.pubhealth.ku.dk/~guhe/
>>
>> ---
>> “If everyone is thinking alike, then somebody isn't thinking.”
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
--
Best wishes/bedste hilsner
Gunnar Hellmund
PhD, Scientific Assistant
http://staff.pubhealth.ku.dk/~guhe/
---
“If everyone is thinking alike, then somebody isn't thinking.”
More information about the R-help
mailing list