3

I'm wondering if anyone can help me better understand the fourier series by seeing the output of a fourier transform actually used as the coefficients in the series of sine and cosine functions.

I have some function, I sample 4 times to get [0, 1, 0, 1], therefore N == 4. How do I express this as a fourier series? Using numpy, the fft gives me...[ 2.+0.j, 0.+0.j, -2.+0.j, 0.+0.j] Basically, I need to see the expansion of this, NOT in summation notation, just because otherwise I will just have a fear-induced cloudy mind. By expansion, I mean sin(something * x) + cos(something * x) + ...

bumble_bee_tuna
  • 3,533
  • 7
  • 43
  • 83
pepper
  • 2,097
  • 5
  • 23
  • 29

2 Answers2

2

The relationship between the Discrete Fourier Transform (DFT) and Fourier series can be summarized as follows,

The Fourier series coefficients of a periodic signal x are given by the DFT of one period of x, divided by N, were N is also the number of samples in each period.

This means that the Fourier series and the DFT are related only if the period of the signal is equal to N times its sampling rate, which is not the case in general.

Therefore in practice when you need the DFT, use scipy.fftpack.fft, while Fourier series coefficients can be calculated with a direct summation in python. There is plenty of literature on-line about both concepts, but do not mix the two as it will probably be mostly confusing, instead of being helpful.

rth
  • 10,680
  • 7
  • 53
  • 77
  • I disagree. If you need the Fourier series coefficient of a discretely sampled function, use `fft` to calculate the `dft`: it is far better optimized than any direct summation algorithm. Extracting the Fourier series coefficients from the coefficient of the `dft` is a piece of cake, as I hint above. – gg349 Jul 07 '15 at 03:35
  • LOL, if you are thorough and look at the other answers in that question you link, I realize now that one of the answers is mine, and actually clarifies in detail the link between DFT and Fourier series coefficients :-) – gg349 Jul 07 '15 at 03:37
  • @gg349 Well yes, FFT is well optimized and could be used to approximate the DFT. However, as would be presented in any signal processing textbook the classical way of approaching this topic is: Fourier series -> continuous Fourier transform (FT) -> FT of a sampled signal -> DFT. My point is that trying to link DFT to the Fourier series is a non trivial task (sampling and finite observation window effects) with underlying assumptions (taking only one period, integer number of samples per period) and is probably best avoided when learning about the DFT. – rth Jul 07 '15 at 13:32
  • Ok, I guess this is a matter of opinion. I find the link very straightforward, and necessary to get the overall picture. In any case, direct summation is not the way to go for a function that is defined only at a finite number of points. – gg349 Jul 07 '15 at 15:00
1

I guess you are looking for something like this:

from numpy.fft import fft
x = array([ 0.,  1.,  0.,  1.])
y = fft(x)

#first rescale it
nfft = len(x)
y /= nfft

n = arange(0,4)
# notice that y[1] and y[3] are identically zero:
x_reconstructed = y[0] +y[2] * cos(2*2*pi/nfft*n)

and now you have x_reconstructed==x. Now you can go to the page of the DFT, especially this equation, and understand summation notation based on the example above.

gg349
  • 21,996
  • 5
  • 54
  • 64