markov zain
markov zain

Reputation: 12935

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

Upvotes: 4

Views: 11136

Answers (1)

Julien Spronck
Julien Spronck

Reputation: 15433

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

Upvotes: 8

Related Questions