[R] Plotting the complex fft in 3D?
Duncan Murdoch
murdoch at stats.uwo.ca
Thu Sep 4 23:02:49 CEST 2008
On 04/09/2008 4:44 PM, Oliver Bandel wrote:
> Zitat von Duncan Murdoch <murdoch at stats.uwo.ca>:
>
>> Oliver Bandel wrote:
>>> 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?
>> 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))
> [...]
>
> 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.
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. Alternatively, play3d(spin3d())
will spin it, or par3d(userMatrix=rotationMatrix(...)) for a fixed setting.
Duncan Murdoch
More information about the R-help
mailing list