2

My question seems to be simple but still I could not find any answer for that. Assume that we have a vector and its DFT which I computed it in R.

> x <- c(3,9,4,2,5,6,2,6)
> x
[1] 3 9 4 2 5 6 2 6
> fft(x)
[1] 37.000000+0.000000i  2.949747-1.292893i  2.000000-7.000000i -6.949747+2.707107i -9.000000+0.000000i -6.949747-2.707107i  2.000000+7.000000i  2.949747+1.292893i

I stored the DFT coefficients in input.txt. Now, I want to plot these complex numbers stored in input.txt with tikz/pgfplots. I read this link, but it is just based on the exponential form of the complex numbers. So, I have no idea if it is possible to draw the plot without converting the complex numbers to the exponential form.

  • Hi and welcome. What are DFT coefficients? – AndréC Jul 26 '20 at 09:03
  • Hi, take a look at here: https://en.wikipedia.org/wiki/Discrete_Fourier_transform. @AndréC – ThisIsMe Jul 30 '20 at 12:56
  • 1
    It's better when you make it clear. Thank you. In french it's TFD – AndréC Jul 30 '20 at 13:02
  • I'm having trouble understanding this as well but I'm pretty sure you will find the sagetex package can handle this without any problems. It relies on the open source CAS, called Sage, which can handle Python, R, numpy, and much more. Discrete Fourier Transform documentation here. I can easily get your coefficients with Sage and I've created a plot. It doesn't look like the plot you linked to below though. – DJP Mar 18 '22 at 23:44

1 Answers1

1

mwe

I don't know if this is the type of plot that you are looking for, but anyway the file MWE.Rnw below should serve to get the idea of the alternative way to obtain your desired plot with knitr.

MWE.Rnw

\documentclass{article}
\begin{document}
<<myplot,dev='tikz', echo=F,warning=F, fig.height=3, fig.width=3>>=
x <- c(3,9,4,2,5,6,2,6)    
plot(sort(x),sort(fft(x)),type='l',col="red",
xlab="$x$",ylab="\\texttt{fft($x$)}")
@
\end{document}
Fran
  • 80,769