2
$\begingroup$

I posted this question on MathStackExchange. My question is in here now: How can I program a Fourier Tranform of a plot without knowing the function that generates the plot, assuming the funcion is of the form $$\sum_{n}\sin(2\pi n)?$$ As I said in my earlier post: This is an unrigorous project. Don't worry about real-world application or what would be the fastest way. I'm just very curious how one could program such a Transform in Mathematica.

$\endgroup$
7
  • $\begingroup$ So, how would you get the function? As a list of values? In other words, in what physical form should we expect the input of your Fourier transform? $\endgroup$
    – MarcoB
    Feb 18, 2021 at 22:56
  • $\begingroup$ What if I play an A4 note on my piano, without backgroundnoises, and record it? $\endgroup$ Feb 18, 2021 at 22:57
  • $\begingroup$ Use the command Fourier. It takes a list (like your sampled piano) and calculates the spectrum. $\endgroup$
    – bill s
    Feb 18, 2021 at 23:00
  • $\begingroup$ How does this command work? What are is the idea behind it? Can I program "my own" easy Fourier comman? $\endgroup$ Feb 18, 2021 at 23:02
  • 2
    $\begingroup$ @vitamind To be frank, that would only be interesting as an exercise for you, but nobody in their right mind will go re-implementing the FFT algorithm, when perfectly good standard implementations exist. In fact, I suspect that even the one in Mathematica probably relies on an underlying fast optimized library of some kind. To see how Fourier works, search Fourier transform on this website and you will find a ton of answers. FFT is a topic that comes up often. $\endgroup$
    – MarcoB
    Feb 18, 2021 at 23:14

1 Answer 1

4
$\begingroup$

Here is the slow Fourier transform... call it the SFT... it's basically the same as the FFT, but slower. On the positive side, it's not hard to program. Let x be the list that you want to take the transform of. The formula implemented is:

enter image description here

where N is the length of x. In Mathematica, this is:

 X[k_] :=  Sum[x[[n + 1]] Exp[-I 2 Pi k n/Length[x]], {n, 0, Length[x] - 1}]

You can evaluate this for all n terms using

X[#] & /@ Range[Length[x]]

OK. It's not really called the Slow Fourier Transform. It's called the "Discrete Fourier Transform," or DFT. MarcoB already thinks I'm not in my right mind, so I better stop here.

$\endgroup$
4
  • $\begingroup$ Time for you to do something. Take a lot of samples of your function, call them x, then the transform will be X as defined above. $\endgroup$
    – bill s
    Feb 19, 2021 at 0:23
  • $\begingroup$ I understand the mathematical computation now. Thank you very much. I will come back to inform you if I was able to program it. $\endgroup$ Feb 19, 2021 at 0:33
  • $\begingroup$ Okay I did it. Only one small question: What's the command to find a function-value of a plot? So I only I have plot, I put in $2$ and then I get the value of that plot at $2$. $\endgroup$ Feb 19, 2021 at 0:47
  • $\begingroup$ @bills Hehe. I like the Slow Fourier Transform though :-) $\endgroup$
    – MarcoB
    Feb 19, 2021 at 4:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.