Fourier transform in Python

I am new to signal processing using Python. I want to know how to convert the magnitude value of the accelerometer to the frequency domain. My example code is 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

Here I want to plot data at the frequency of the domain. The desired output might be like this: Graph of the intended output

+3


source to share


1 answer


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

+5


source







All Articles