this is my first question here on stackoverflow and I hope I will not make huge mistakes. I am analyzing a set of time series with sampling rate of 1 Hz. I need to plot their fourier transform in order to study their spectra.

Here it is my piece of code:

from obspy.core import read
import numpy as np 
import matplotlib.pyplot as plt

st = read('../SC_noise/*HEC_109C*_s', format='SAC')
stp = st.copy()
stp.detrend('linear')
stp.taper('cosine')

for tr in stp:
  dataonly = tr.data
  spec = np.fft.rfft(dataonly)
  plt.plot(abs(spec))
  plt.show()

This works just fine: the plot is the same I get using SAC. But the xaxis does not show frequencies. I've wandered around a little bit and found different ideas: none of them is working. For example in the case of a fft (here I am using a rfft) this should do the job

samp_rate=1
freq = np.fft.fftfreq(len(spec), d=1./samp_rate)

But if I use it it would give me negative frequencies.

Does anybody have an idea? Thank you very much in advance for all the help!

Piero

Edit
Report