1

I have a set of data. It is obviously have some periodic nature. I want to find out what frequency it has by using the fourier transformation and plot it out.

Here is a shot of mine, but it seems not so good.enter image description here

This is the corresponding code, I don't konw why it fails:

import numpy
from pylab import *
from scipy.fftpack import fft,fftfreq
import matplotlib.pyplot as plt
dataset = numpy.genfromtxt(fname='data.txt',skip_header=1)
t = dataset[:,0]
signal = dataset[:,1]
npts=len(t)

FFT = abs(fft(signal))
freqs = fftfreq(npts, t[1]-t[0])
subplot(211)
plot(t[:npts], signal[:npts])
subplot(212)
plot(freqs,20*log10(FFT),',')
xlim(-10,10)
show()

My question is:Since the original data is very periodic looking, and I expect to see that in the frequency domain the peak is very sharp; how can I make the peak nicer looking?

2
  • what's not right about it? what were you expecting? Commented Apr 27, 2015 at 6:53
  • @PaulH Why the peak so broad, I see that the period of the original data is very nice. How can I make the frequency more obvious? Commented Apr 27, 2015 at 7:17

1 Answer 1

5

It's a problem of data analysis.

  • FFT works with complex number so the spectrum is symmetric on real data input : restrict on xlim(0,max(freqs)) .
  • The sampling period is not good : increasing period while keeping the same total number of input points will lead to a best quality spectrum on this exemple.

EDIT. with :

 dataset = numpy.genfromtxt(fname='data.txt',skip_header=1)[::30];
 t,signal = dataset.T
 (...)
 plot(freqs,FFT)
 xlim(0,1)
 ylim(0,30)    

the spectrum is

spectum

For best quality spectrum , just reacquire the signal for a long long time (for beautiful peaks), with sampling frequency of 1 Hz, which will give you a [0, 0.5 Hz] frequency scale (See Nyquist criterium).

Sign up to request clarification or add additional context in comments.

4 Comments

I got your first point, can you give a more detailed explaination of your second point? should I replace "t[1]-t[0]" to "10*(t[1]-t[0])"? It is not nice either.
Just a check of my understanding. The sampling rate of yours is $1/(30*0.005s)=6.67Hz$, so according to Nyquist criterium. This sample rate gurantee that we can recover the information of the signal with frequency $f< 6.67/2=3.33Hz$. So acctually we should draw the x-axis from 0 to 3.4Hz.
However, I still don't understand the magic that you you choose less points can make the graph looks better, can you explain this part in your answer. Thank you!
it is just a zoom on the interesting part of the Spectrum. It seems to be no information after 0.5 Hz so the signal is oversampled. This graph looks better in linear scale for such data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.