Filtering Seismograms

The following script shows how to filter a seismogram. The example uses a zero-phase-shift low-pass filter with a corner frequency of 1 Hz using 2 corners. This is done in two runs forward and backward, so we end up with 4 corners de facto.

The available filters are:

  • bandpass

  • bandstop

  • lowpass

  • highpass

import numpy as np
import matplotlib.pyplot as plt

import obspy

# Read the seismogram
st ="")

# There is only one trace in the Stream object, let's work on that trace...
tr = st[0]

# Filtering with a lowpass on a copy of the original Trace
tr_filt = tr.copy()
tr_filt.filter('lowpass', freq=1.0, corners=2, zerophase=True)

# Now let's plot the raw and filtered data...
t = np.arange(0, tr.stats.npts / tr.stats.sampling_rate,
plt.plot(t,, 'k')
plt.ylabel('Raw Data')
plt.plot(t,, 'k')
plt.ylabel('Lowpassed Data')
plt.xlabel('Time [s]')

(Source code, png)