# Detecting glitches in waveforms

**URL:** https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314
**Category:** Usage Questions
**Created:** [October 30, 2025, 6:51am UTC](https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314 "2025-10-30T06:51:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tubbetay](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tubbetay/32/1129_2.png) [@Tubbetay](https://discourse.obspy.org/u/Tubbetay)
#### Post date: [October 30, 2025, 6:51am UTC](https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314/1 "2025-10-30T06:51:36Z")

</div>

Hi,  
I’m quite new to Obspy. I’m currently trying to make a program to detect distortions in the traces’ waveforms like the following:

 ![KLSM](https://discourse.obspy.org/uploads/default/original/2X/4/40a9d17993c13111bbfc8218eed3aeee48589846.png)  
 ![BGCI](https://discourse.obspy.org/uploads/default/original/2X/7/7cc68b86111d0230c49f8710d371859ff3fc6076.png)  
The problem is, I have no idea how to identify and isolate them correctly. I’ve tried using some baseline shift correction methods, but they don’t work well for ‘symmetrical’ signals like seismic signals. I’ve tried using `remove_response` but I don’t have the information whether the hardwares recorded the amplitude as acceleration/velocity/displacement. I tried a code from ![here](https://discourse.obspy.org/t/identifying-and-rejecting-bad-waveforms/1279/2) and although it’s the most straightforward as far, it got wrong a lot when detecting if the waveforms have or have no distortions. All in all, my attempts ended up having more ‘normal’ waveforms getting wrongly detected like the above waveforms. These are my attempts so far.  
[tester9part1zhang.py](https://discourse.obspy.org/uploads/short-url/guaoCtirdxhrjAYWmq3WELZ94Dq.py) (715 Bytes)  
[tester10part2beads.py](https://discourse.obspy.org/uploads/short-url/jzmhchGXGAQJzXBoqpNL6L7jnZR.py) (1.3 KB)  
[tester10part3median.py](https://discourse.obspy.org/uploads/short-url/sJEQG1yUI1zLEpFu9jz9X6UEn3n.py) (716 Bytes)  
[tester11part1responses.py](https://discourse.obspy.org/uploads/short-url/sNTChuaqbEYzZCMCwRwOIEdWAG2.py) (1.8 KB)  
[tester13part1glitches.py](https://discourse.obspy.org/uploads/short-url/NqmQKByrnyiHt2LqqvbbXZ0qKY.py) (2.1 KB)  
Thank you some much for any help you can give me.

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [October 30, 2025, 6:55am UTC](https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314/2 "2025-10-30T06:55:24Z")

</div>

You could try template matching, i.e. use one of the glitches as a template and use it for cross correlation. Its nested into the coincidence trigger, ~~but you can just use the one station and set the target coincidence sum to `1.0`~~.

Edit: I forgot how it was implemented, you can set a higher coincidence sum that is unreachable actually and just let it declare an event based on the similarity alone.

> **[Trigger/Picker Tutorial — ObsPy 1.4.2.post0+384.g5f3978502b.obspy.master...](https://docs.obspy.org/master/tutorial/code_snippets/trigger_tutorial.html#advanced-network-coincidence-trigger-example-with-similarity-detection)**

---

<div class="post-metadata">

### Author: ![Tubbetay](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tubbetay/32/1129_2.png) [@Tubbetay](https://discourse.obspy.org/u/Tubbetay)
#### Post date: [November 13, 2025, 6:38am UTC](https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314/3 "2025-11-13T06:38:22Z")

</div>

Thanks for the suggestion. I tried to use `coincidence_trigger` within the script below. Unfortunately, I got an error on that function, which pointed to `nlta` being longer than `len(data).

```python
Traceback (most recent call last):
  File "…\tester18part1.py", line 30, in <module>
    trig = coincidence_trigger(
           ^^^^^^^^^^^^^^^^^^^^
  File "…\latsar\Lib\site-packages\obspy\signal\trigger.py", line 715, in coincidence_trigger
    tr.trigger(trigger_type, **options)
  File "…\latsar\Lib\site-packages\decorator.py", line 235, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…\latsar\Lib\site-packages\obspy\core\trace.py", line 282, in _add_processing_info
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "…\latsar\Lib\site-packages\obspy\core\trace.py", line 1640, in trigger
    self.data = func(self.data, **options)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…\latsar\Lib\site-packages\obspy\signal\trigger.py", line 189, in classic_sta_lta
    raise Exception('ERROR %d stalta: len(data) < nlta' % errcode)
Exception: ERROR 1 stalta: len(data) < nlta

```

I got no idea where `nlta` came from, nor how to fix this error.  
[tester18part1.py](https://discourse.obspy.org/uploads/short-url/sowIDPuJUyRbpqxSOFygPGL3TfW.py) (1.0 KB)

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [January 26, 2026, 11:37am UTC](https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314/4 "2026-01-26T11:37:49Z")

</div>

There are explanations and references to literature in the trigger tutorial: [Trigger/Picker Tutorial — ObsPy 1.4.2.post0+421.ga1953b9eaa.obspy.master documentation](https://docs.obspy.org/master/tutorial/code_snippets/trigger_tutorial.html)

If you don’t want to trigger for template matching, the other option is to run a cross correlation of your glitch templates across the full waveforms, but that is way more costly in terms of CPU time.

---

<div class="post-metadata">

### Author: ![Tubbetay](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tubbetay/32/1129_2.png) [@Tubbetay](https://discourse.obspy.org/u/Tubbetay)
#### Post date: [February 10, 2026, 8:11am UTC](https://discourse.obspy.org/t/detecting-glitches-in-waveforms/2314/5 "2026-02-10T08:11:50Z")

</div>

I have tried your suggestion and it looked promising, thanks!

But I’d like to know what methods I can use for signals that look like the 2nd to last examples, because triggering only works for signals like the 1st example for now.

 ![Example 1](https://discourse.obspy.org/uploads/default/original/2X/c/cf4317795556159cee81b2de8b8f47a8f269a087.png)

 ![Example 2](https://discourse.obspy.org/uploads/default/original/2X/c/c7c69845839f91f9936374cd4c594f343aa96b6e.png)

 ![Example 3](https://discourse.obspy.org/uploads/default/original/2X/4/49e32e4eea879ed232efdae4aee080bb54b91a21.png)

 ![Example 4](https://discourse.obspy.org/uploads/default/original/2X/c/cb0b2451d85d9ea08ea4e9156e68aca0b53a89d8.png)
