0
$\begingroup$

I Would like to be able to reconstruct every individual sinusoid that makes up a Discrete signal. I Have the following signal: (I am working in Python) enter image description here

The signal is essentially an array with about 400 elements that varies with time. In Python after calling the fft function on the data

 dft= rfft(dat)/len(dat)  #real fft

I receive the figure below: enter image description here

I am aware that I can use the result of the fft to obtain the individual Fourier series components, but I am unsure exactly how. The code I have yields me an array of magnitudes for each harmonic of the signal, how do I use that to get each individual component of the Fourier series?

$\endgroup$
  • $\begingroup$ now the Fourier Series is specifically for periodic signals. (and the DFT or FFT will directly get your Fourier series coefficients from the sampled periodic signal.) are you sure your data is periodic? $\endgroup$ – robert bristow-johnson May 6 '17 at 4:51
  • $\begingroup$ Could i just perform a periodic extension on the data? $\endgroup$ – Mustard Tiger May 6 '17 at 4:59
  • $\begingroup$ yes, you can. and that is inherently what happens when you pass your data to the FFT. the DFT treats your $N$ samples of data supplied as a single period of a periodic function or sequence. but your data above has a nasty discontinuity between the end (at 2082) and the beginning (at 2091). periodically extending that data without windowing might look bad after the FFT. $\endgroup$ – robert bristow-johnson May 6 '17 at 5:59
1
$\begingroup$

If you assume that your signal is one period of the original signal, then the FFT gives you the Fourier Series coefficients up to frequency $F_s/2$ (due to Nyquist theorem). The DFT result are exactly the coefficients of the complex Fourier Series. You can convert the complex coefficients to $a_n$ and $b_n$ of the real Fourier series (with sines and cosines) according to Wikipedia. Also, two of my articles (Complex Fourier Series, Spectral Leakage) might help you understand further.

$\endgroup$
1
$\begingroup$

I am no expert in this topic, but have some useful examples to share.

1 component example

To keep the i-eth Fourier component, you can zero the rest of the components:

n = len(y)
Y = numpy.fft.fft(y)
numpy.put(Y, range(0, i), 0.0)
numpy.put(Y, range(i+1, n), 0.0)
# Now Y holds 1 imaginary coefficient corresponding with the i-eth Fourier component

If you're looking for the Real signal corresponding to the chosen i-eth component, you can afterwards perform the inverse transform through ifft:

ifft = numpy.fft.ifft(Y) # the sinusoid you're looking for

Multiple components example

The more Fourier components you keep, the closer you'll mimic the original signal. This example shows what happens when you keep 10, 20, ...up tp n components.

Assuming x and y are your data vectors.

import numpy
from matplotlib import pyplot as plt

n = len(y)
COMPONENTS = [10, 20, n]

for c in COMPONENTS:
    colors = numpy.linspace(start=100, stop=255, num=c)
    for i in range(c):
        Y = numpy.fft.fft(y)
        numpy.put(Y, range(i+1, n), 0.0)
        ifft = numpy.fft.ifft(Y)
        plt.plot(x, ifft, color=plt.cm.Reds(int(colors[i])), alpha=.70)

    plt.title("First {c} fourier components".format(c=c))
    plt.plot(x,y, label="Original dataset")
    plt.grid(linestyle='dashed')
    plt.legend()
    plt.show()

First 10 Fourier components First 20 Fourier components First 306 Fourier components

...see how it mimics the original signal?

$\endgroup$
0
$\begingroup$

A DFT result vector will only provide you with the Fourier series coefficients if (1) the signal is exactly integer periodic within the DFT/FFT length, and (2) the signal (before sampling) is perfectly band-limited to frequencies below Fs/2. Otherwise, the DFT will contain either window artifacts and/or frequency aliasing.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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