Untitled
unknown
python
a year ago
1.1 kB
12
Indexable
import numpy as np
import matplotlib.pyplot as plt
from numpy.fft import fft, fftfreq
data = np.loadtxt('table.txt')
x = data[:, 0]
y = data[:, 1]
'''
data sub-sample korsi cause sub-sample korar
por actual shape er kono change hoyna, and it
leads to faster result, also, frequency er max
range ta plotting e kome jay so fft er plot
dekhte shubidha hoy,
(max freq range in plotting = sampling frequency / 2 ).
(tui parle Discrete Fourier Transform er ektu thoery dekhis).
Per 100 ta theke 1ta kore data nisi.
'''
x = x[::100]
y = y[::100]
'''
remove avg of y from y to make it zero mean.
0 frequency er component ta remove korsi.
'''
y = y - np.mean(y)
plt.plot(x, y)
plt.xlabel('t')
plt.ylabel('M_z')
plt.title('Data Plot')
fft_y = fft(y)
freq = fftfreq(len(y), x[1] - x[0])
half_length = int(len(freq)/2)
plt.figure()
plt.plot(freq[0:half_length], np.abs(fft_y[0:half_length]))# half length freq nisi because of symmetry
plt.xlabel('Frequency')
plt.ylabel('Amplitude')
plt.title('Fourier Transform')
plt.show()Editor is loading...
Leave a Comment