convert sac to wav


Not sure if this helps, but with, you have to normalize and scale the amplitudes like in the example below.


import as wav

xspd = 200. # speed up by factor of 200
fswav = fs*xspd
wscal = p[0:M]/max(np.absolute(p[0:M])) # scale to -1 <= p <= 1; p is vector length M
wscal = 0.99*wscal # avoid clipping
convert_16_bit = float(2**15) # convert to int16 format for wavwrite
wscal = np.int16( wscal * convert_16_bit ) # convert to int16 format for wavwrite


the WAV format is written by default as int32. And by default obspy
does not rescale the data. Most probable, your WAV file viewing tool
limits the yaxis to maximum [-1, +1], which corresponds to integer
[-2**31-1, 2**31-1]. If you zoom in a lot (approx factor 2E+9), you
will see the data.

To rescale the data to [-1, +1] use the rescale flag of st.write::

  from obspy.core import read
  st = read(‘’)
  st.write(‘myfile.wave’, format=‘WAV’, framerate=7000, rescale=True)

See also:


Robin's code or rescale=True or audacity produce similar results.

rescale=False is the default in writeWAV, but rescale=True seems more
useful "out of the box"...

thanks for all the tips.