Skip to content

Plotting the complex fft in 3D?

8 messages · Duncan Murdoch, Martin Maechler, oliver +1 more

#
Hello,


I'm new to R (using it since about two weeks),
but absolutely a fan of it from the beginning on. :-)

Best tool for working with data I found. :-)

I tried using the fft() and other funcitons for
analysing time series.

What I would be glad to have, would be a
convenient way to display the complex result
of a fft in a way, that real and imaginary parts
each use an axis for themselves, and the index of the
resulting values use the third axe.

When displaying this as a 3D->2D picture,
it also would be nice, to change the view,
like it can be done with persp().

Is there already a package or script for preparing the data
of an fft to be displayed in this way?

Ciao,
   Oliver
#
Oliver Bandel wrote:
I don't find this very enlightening, but here you go:

x <- rnorm(1000)
f <- fft(x)

library(rgl)
plot3d(1:length(f), Re(f), Im(f))


Duncan Murdoch
#
Zitat von Duncan Murdoch <murdoch at stats.uwo.ca>:
[...]

Ok, this is a starting point. :-)

It would be enlightening, if you have a timeseries that is not
noise only, and if the plot would not use dots.
So, using a timeseries that is derived from some  data
could be very interesting. But rnorm creates noise only,
and not a deterministic signal. So the resulting fft values
look quite boring ;-)

Instead of dots, a line from the index-axis at Re=0, Im=0
to the value of the fft at that index should be drawn.

BTW: how to change the perspective? I did not found an
angle-parameter for the plot3d()-function.

Ciao,
   Oliver
#
On 04/09/2008 4:44 PM, Oliver Bandel wrote:
plot3d doesn't support that directly, but you could plot with type='n', 
then use segments3d to add the lines.
Just grab it with your mouse and drag.  Alternatively, play3d(spin3d()) 
will spin it, or par3d(userMatrix=rotationMatrix(...)) for a fixed setting.

Duncan Murdoch
#
Zitat von Duncan Murdoch <murdoch at stats.uwo.ca>:
[...]
Wow, coool! :-)

Well, rgl.... I think "gl" stands for OpenGl.

Fine. :-)
Ok, some thinsg to play with.

Thank you.


Ciao,
   Oliver
1 day later
#
Just another remakr on this thread.

I you have  time series and think about its fourier transform
(EE language) then you should know that the statistical language
of that is "spectral analysis" or maybe
 "frequency domain time-series analysis"
and the R function to consider should definitely be

spectrum()  which is a wrapper (among others) to spec.pgram()
-- which calls fft() -- for computing the so-called
"periodogram".
If you learn more about the topic, you will learn that in almost
all cases you'd consider a *smoothed* version of the
periodogram, etc etc (because the so-called *raw* periodgram is
*in*consistent as an estimate fo the underlying true spectrum).
The Time-Series chapter/section of the MASS book is very helpful
here, IIRC.

Martin Maechler, ETH Zurich
OB> Zitat von Duncan Murdoch <murdoch at stats.uwo.ca>:
>> On 04/09/2008 4:44 PM, Oliver Bandel wrote:
>> > Zitat von Duncan Murdoch <murdoch at stats.uwo.ca>:
    >> >
>> >> Oliver Bandel wrote:
>> >>> Hello,
    >> >>>
    >> >>>
    OB> [...]


    >> plot3d doesn't support that directly, but you could plot with
    >> type='n',
    >> then use segments3d to add the lines.
    >> 
    >> >
    >> > BTW: how to change the perspective? I did not found an
    >> > angle-parameter for the plot3d()-function.
    >> 
    >> Just grab it with your mouse and drag.

    OB> Wow, coool! :-)

    OB> Well, rgl.... I think "gl" stands for OpenGl.

    OB> Fine. :-)


    >> Alternatively,
    >> play3d(spin3d())
    >> will spin it, or par3d(userMatrix=rotationMatrix(...)) for a fixed
    >> setting.

    OB> Ok, some thinsg to play with.

    OB> Thank you.


    OB> Ciao,
    OB> Oliver

    OB> ______________________________________________
    OB> R-help at r-project.org mailing list
    OB> https://stat.ethz.ch/mailman/listinfo/r-help
    OB> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    OB> and provide commented, minimal, self-contained, reproducible code.
#
Hello Martin,

Zitat von Martin Maechler <maechler at stat.math.ethz.ch>:
[...]

"Yes, I'm coming from the EE world, but I also know the other terms.
The term "spectral analysis" is also used in EE, maybe not that often.
Also "frequency domain time-series analysis" is used in EE, but
maybe only at the university, later at the job, short terms
"spectral analysis" or "fft" are used. (But it may differ from country
to country.)


I tried "spectrum" now on my example data, and it looks quite different
to the result of fft().
It looks very close to what one gets as output from a spectrum analyzer
(measurement harware).
So it's quite nice to use this. :-)
Well, what do you mean with inconcistent?
And why is spectrum() better?

Do you talk about things like windowing for becoming more appropriate
results?

Even if the output from spectrum() looks more like what I know from
measurement hardware, it might not always be better.
Can yo explain, why better using this?
The FFT only creates coefficients for certain seperated
frequencies. It depends on number of samlpes how accurate the
result is. And if the samples aren't an integer multiple of the
frequency in the measured signal, this creates errors in the results.

Possibly this is, what you are talking about?

Why is spectrum() better? Would be nice to have an explanation,
on how it's results are created, so that I can understand,
when which kind of analysis is better.

For the non-EE analysis, why is there fft() used and not
spectrum()?

For what kind of analysis is what function better?
"MASS book"? Do you mean the documentation of the MASS package?

Well, so much packages.... R is very powerful and provides a lot of
things.

But where to start?

Any idea?  I started with some introductional papers and got a
good overview. But a more systematical approach might be better.

Can you recommend some things to read?
I also have seen that there is one german book about programming in R.
I will look at it in more detail, when the new edition will be published
(sept/oct).

But maybe you can recommend other readings as well?

Thanks,
      Oliver
#
Oliver Bandel wrote:
spectrum() and spec.pgram() use fft() to calculate results. But some 
information is thrown away, some information is merged appropriately, 
and maybe tapering and padding is applied. Well, it really depends on 
your tasks which functions to use. I found myself frequently using fft() 
and doing the rest manually, because spectrum() is sometimes too 
intelligent for me ...
No, the other way round: the Springer book "Modern Applied Statistics 
with S, 4th edition, 2002, by Venables and Ripley has some package 
(MASS) as supplementary material.

Best wishes,
Uwe Ligges