0
$\begingroup$

To fully understand the Fourier Transform I have been working on a rather standard implementation of the FFT algorithm. I tried generating a 440 Hz sin wave and passing it through the algorithm, however, when plotting the real part of the result, I get a spiky mess, whereas I was expecting two spikes (as from my understanding it's mirrored, since the second half is just a representation of the first's complex conjugate).

Disappointed, I tried passing the sin wave through a third party library, but achieved the same result, so I suspect I am misunderstanding what the FFT actually outputs.

This is the result I get

Not sure how useful it is, but here is the GitHub project https://github.com/kradicati/fourier-transform

The two most important classes are: https://github.com/kradicati/fourier-transform/blob/master/src/test/kotlin/me/krb/transform/FastFourierTransformTest.kt (where the actual plotting is done) https://github.com/kradicati/fourier-transform/blob/master/src/main/kotlin/me/krb/transform/FastFourierTransform.kt (the FFT implementation)

$\endgroup$
5
  • $\begingroup$ What is the sample rate for your input signal? Can you add that to the question? $\endgroup$ Jan 15, 2022 at 17:27
  • $\begingroup$ Assuming I didn't make a mistake in the wave generation it should be 1000 samples per second $\endgroup$
    – kradicati
    Jan 15, 2022 at 17:30
  • $\begingroup$ Thank you, just wanted to make sure your sampling rate is high enough for you signal and it appears to be fine. $\endgroup$ Jan 15, 2022 at 17:42
  • $\begingroup$ Your sample rate is 16384 Hz since you create a time vector of 1 second length with 16384 points (or maybe 16385 depending on numerical behavior). Your y-axis is very strange. This seems to be primarily noise. It's way to small and is simply a small DC offset with some numerical noise on top of it. Suggestion: start with a unit impulse of 16 points and debug manually from there. $\endgroup$
    – Hilmar
    Jan 15, 2022 at 17:51
  • $\begingroup$ I did what the answer suggested, which is plotting the absolute value of the complex number, which ended up being exactly what I was looking for. And thank you for the clarification, I had misunderstood! $\endgroup$
    – kradicati
    Jan 15, 2022 at 18:09

1 Answer 1

2
$\begingroup$

Looking at the y-axis (vertical scale) on your plot I see the values are really small. I am assuming that your input signal is of magnitude order one. This suggests that all you are seeing is roundoff error.

This is to be expected for a sine signal if you are only plotting the real part of the FFT. For a sine signal the Fourier transform is pure imaginary.

What you should probably be plotting is the absolute value of the FFT to see the combined magnitude of the real and imaginary part. You may also want to plot both the real and imaginary part of the result on the dame figure to be able to see the relationship between the two components.

From Wikipedia:

$$\mathcal {F}[\sin(ax)] = \frac{\delta\left(\xi-\frac{a}{2\pi}\right)-\delta\left(\xi+\frac{a}{2\pi}\right)}{2i}$$

where $\xi$ is the frequency, $\delta()$ is the Dirac delta function, and $i$ is the imaginary unit.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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