pythonpython-2.7numpyhamming-window

How to input data to FFT


So I do have a two arrays of data:

Bx = [  -59.57011259   -74.20675537   -90.53224156 ..., -1676.9703173
-1676.9703173  -1676.9703173 ]
By = [  1.48413511e+00   4.96417605e+00   8.39303992e+00 ...,  -1.67697032e+03
-1.67697032e+03  -1.67697032e+03]

how do I put them to receive FFT which looks like this? enter image description here

I have a program which shows me this data, but I need to get it done in Python2.7. I tried to use that code, which I found in this topic (Plotting a Fast Fourier Transform in Python), but to be honest I have troubles with understanding FFT, can you help?

# Number of samples
N = 600
# Sample spacing
T = 300.0 / 266336
x = np.linspace(0.0, N*T, N)
y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
plt.plot(xf, 2.0/N * np.abs(yf[0:N/2]))
plt.grid()
plt.show()

Some info about my data: number of records/samples 266336; time 300s = 300000ms

I also need to implement somehow blackman or hamming window, can you help?


Solution

  • I've used Welch method which was a good idea. End of post. Problem solved.

    # Loop for FFT data
    for dataset in [fft1]:
        dataset = np.asarray(dataset)
        freqs, psd = welch(dataset, fs=266336/300, window='hamming', nperseg=8192)
        plt.semilogy(freqs, psd/dataset.size**2, color='r')
    
    for dataset2 in [fft2]:
        dataset2 = np.asarray(dataset2)
        freqs2, psd2 = welch(dataset2, fs=266336/300, window='hamming', nperseg=8192)
        plt.semilogy(freqs2, psd2/dataset2.size**2, color='b')