Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need some help -- plot fast fourier transform

1,023 views
Skip to first unread message

daku...@gmail.com

unread,
Nov 20, 2015, 11:56:31 PM11/20/15
to
Could some Gnuplot guru please provide any simple
example script for plotting FFT(fast fourier
transform). Currently I am just able to create
scatter plots of FFT output, but I would much
rather have the simple line graphs. All hints/
suggestions would be greatly appreciated - thans
in advance for your help.

Karl-Friedrich Ratzsch

unread,
Nov 21, 2015, 5:43:09 AM11/21/15
to
This doesn't explain your problem, just the direction from where it
landed on your feet.

I'd say you don't want a guru, you want a nanny. Sorry.

Richard Owlett

unread,
Nov 21, 2015, 11:07:11 AM11/21/15
to
Browse https://www.google.com/search?q=how+to+ask+questions
[Hint] You didn't tell us what you used or did ;/

P.S. You're not first [not last] to poorly frame a question.


daku...@gmail.com

unread,
Nov 21, 2015, 10:13:38 PM11/21/15
to
The problem is self-explanatory.
I have generated a set of Fast
Fourier Transform values(amplitude,
phase) using a simple C language
program, and the implementation is
based on the steps described in
Numerical Recipes in C. The C
language program is compiled with
GCC, running on a Fedora 18 machine.
If I start gnuplot, and use use
the command line
plot 'testout' using 1:2 with lines;
I get a beautiful symmetrical flower
like pattern in the plot window NOT
the set of symmetrical spikes
associated with a spectrum.
I have used Gnuplot for years, with
no complaints. I tried other commamds
as:
plot 'testout' using 1:2 pt 5 ps 7
and now I get a set of symmetrical
little squares in the plot window,
where each square represents the
peak of each spike, but I DO NOT
see the spikes. So, obviously
there must be some other commands
that I need to use, which I do not
know. May I know what these other
commands are ?
I am sure I have explained the problem
clearly. I expect meaningful response.

Richard Owlett

unread,
Nov 22, 2015, 5:58:09 AM11/22/15
to
On 11/21/2015 9:13 PM, daku...@gmail.com wrote:
> On Saturday, November 21, 2015 at 5:43:09 AM UTC-5, Karl-Friedrich Ratzsch wrote:
>> Am 21.11.2015 um 05:56 schrieb daku...@gmail.com:
>>> Could some Gnuplot guru please provide any simple
>>> example script for plotting FFT(fast fourier
>>> transform). Currently I am just able to create
>>> scatter plots of FFT output, but I would much
>>> rather have the simple line graphs. All hints/
>>> suggestions would be greatly appreciated - thans
>>> in advance for your help.
>>
>> This doesn't explain your problem, just the direction from where it
>> landed on your feet.
>>
>> I'd say you don't want a guru, you want a nanny. Sorry.
>
> The problem is self-explanatory.
> I have generated a set of Fast
> Fourier Transform values(amplitude,
> phase) [SNIP;]
> I get a beautiful symmetrical flower
> like pattern in the plot window [snip]
> I am sure I have explained the problem
> clearly. I expect meaningful response.

Gnuplot worked.
Ask yourself:
1. What is an independent variable?
2. What is a dependent variable?

Thomas Wagner

unread,
Nov 24, 2015, 6:51:08 PM11/24/15
to
When reading about the flower like plot my first suspicion was that your
data file may probably not contain sorted data. A line plot will then
show such funny figures, a point plot of the same data set would not
reveal unsorted data. I have used NRC's FFT algorithms myself many years
ago and I vaguely remember that the data returned by the functions had
to be sorted manually.

Gnuplot plots data as presented in the data files unchanged unless you
tell gnuplot to do so. That is why I would check the contents of the
data file first.

Hope this helps,
Thomas

Hans-Bernhard Bröker

unread,
Nov 24, 2015, 7:25:51 PM11/24/15
to
Am 22.11.2015 um 04:13 schrieb daku...@gmail.com:

> The problem is self-explanatory.

No, it really is not.

How is anybody not sitting in front of your machine supposed to know
what the output of that entirely unknown FFT program of yours looks
like, without being shown as much as a small sample of it?

> I am sure I have explained the problem clearly.

Not really.

> I expect meaningful response.

And that's exactly the kind of attitude that makes me _not_ want to help
you. If you want to use that kind of language, you'll have to pay
someone to put up with it.

drmcn...@gmail.com

unread,
Jan 28, 2017, 8:08:17 PM1/28/17
to
Assuming you have two columns, real and complex, you might looking for something like

plot 'myfftfile' using 0:($1**2+$2**2)

That will plot the amplitude versus bin number

drmcn...@gmail.com

unread,
Jan 28, 2017, 8:47:56 PM1/28/17
to
Here is a more complete answer:

The output of an FFT is a list of complex values. If you use the realft algorothm from Numrec or something similar, for N discrete sampled real values, you get N/2 complex values, or N/2 pairs of real and imaginary values.

As I recall, NumRec packs them into doubles. The array elements at even indices are the real part and the array elements at odd indices are the imaginary part.

You need to output them from your c program as two columns, d[2*i], d[2*i+1], or output the square magnitude of each pair (d[2*i]*d[2*i]+d[2*i+1]*d[2*i+1])

If you output them as two columns, you plot them as

sqrmag(a,b) = a**2 +b**2

plot 'myfile' using 0:(sqrmag($1,$2))

or if you output them as the square magnitude, you plot them as

plot 'myfile' using 0:1

Note that these command graph the spectrum versus bin number.

If you want to plot them versus frequency, replace the "0" by

(($0/Ndata)*samplingrate)

where the number of frequency bins Nbins = Ndata/2, or you can do that in your program and output an extra column for the frequency and adjust the plot commands accordingly.

John Edwards

unread,
Jan 31, 2017, 7:18:36 AM1/31/17
to
An old thread come back to life, that I didn't see the first time around.
I regularly plot FFT (and other DSP) results from C/C++. I used to hack new functions every time I wanted to plot a new dataset. In the end I realized that it would save me a lot of time to put these into a library. It is available here : https://sourceforge.net/projects/gnuplotc/.
Enjoy
John

0 new messages