Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fourier Transform in Python

I am a newbie in Signal Processing using Python. I want to find out how to transform magnitude value of accelerometer to frequency domain. My example code is following below:

In [44]:

  x = np.arange(30)
  plt.plot(x, np.sin(x))
  plt.xlabel('Number of Sample')
  plt.ylabel('Magnitude Value')
  plt.show()

Graph of the sample values

In here I want to plot the data to domain frequency. The desired output may be like this: Graph of the intended output

like image 663
markov zain Avatar asked Mar 17 '23 02:03

markov zain


1 Answers

numpy and scipy have a fourier transform module (http://docs.scipy.org/doc/numpy/reference/routines.fft.html).

x = np.linspace(0,5,100)
y = np.sin(2*np.pi*x)

## fourier transform
f = np.fft.fft(y)
## sample frequencies
freq = np.fft.fftfreq(len(y), d=x[1]-x[0])
plt.plot(freq, abs(f)**2) ## will show a peak at a frequency of 1 as it should.

enter image description here

like image 81
Julien Spronck Avatar answered Mar 25 '23 02:03

Julien Spronck