X-Received: by 10.107.138.233 with SMTP id c102mr4409998ioj.18.1485654475407; Sat, 28 Jan 2017 17:47:55 -0800 (PST) X-Received: by 10.157.43.215 with SMTP id u81mr1242780ota.15.1485654475380; Sat, 28 Jan 2017 17:47:55 -0800 (PST) Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.glorb.com!r185no1005441ita.0!news-out.google.com!78ni21824itm.0!nntp.google.com!r185no1005440ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.graphics.apps.gnuplot Date: Sat, 28 Jan 2017 17:47:54 -0800 (PST) In-Reply-To: <82271787-2bb8-4291-8705-e6eb4656b610@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=24.45.13.150; posting-account=i227SwoAAAD1oAKm4JdAo91Sg8cLhPKa NNTP-Posting-Host: 24.45.13.150 References: <82271787-2bb8-4291-8705-e6eb4656b610@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <23acc91e-8c60-44e4-a31d-fea3ce2a9c87@googlegroups.com> Subject: Re: Need some help -- plot fast fourier transform From: drmcnelson@gmail.com Injection-Date: Sun, 29 Jan 2017 01:47:55 +0000 Content-Type: text/plain; charset=UTF-8 Xref: csiph.com comp.graphics.apps.gnuplot:3550 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.