# Understanding the behaviour of Butterworth filter in DSP

**URL:** <https://discourse.julialang.org/t/understanding-the-behaviour-of-butterworth-filter-in-dsp/107396>\
**Category:** Signal and Image Processing\
**Tags:** dsp, digital-filters\
**Created:** [December 11, 2023, 12:24am UTC](https://discourse.julialang.org/t/understanding-the-behaviour-of-butterworth-filter-in-dsp/107396 "2023-12-11T00:24:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [December 11, 2023, 12:24am UTC](https://discourse.julialang.org/t/understanding-the-behaviour-of-butterworth-filter-in-dsp/107396/1 "2023-12-11T00:24:33Z")

</div>

Hi all,  
I’m using a highpass filter to isolate the oscillations from the trend in my signal. The filter I use for my time series signal is:

```julia
response = Highpass((𝑓/1); fs)
design = Butterworth(2)
filtered = filt(digitalfilter(response,design), signal)

```

Where `fs` is the sampling frequency, and `𝑓` is the frequency of the oscillations.

For some reason, the result is this:  
 ![Julia-Discourse-Buterworth](https://global.discourse-cdn.com/julialang/original/3X/6/8/68997a53f3125bde32d7c36005b49ea679f5f98e.png)

Can someone explain to me why I get this behavior at the beginning of the filtered signal? This drop is something I can’t really pinpoint the reason to, and not sure how to fix it.

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [December 11, 2023, 12:33am UTC](https://discourse.julialang.org/t/understanding-the-behaviour-of-butterworth-filter-in-dsp/107396/2 "2023-12-11T00:33:24Z")

</div>

> [@PeX](#):
>
> Can someone explain to me why I get this behavior at the beginning of the filtered signal?

That’s the filter transient. A filter’s frequency response assumes an infinite-duration sinusoidal input – anything else produces transients. [Transient response - Wikipedia](https://en.wikipedia.org/wiki/Transient_response)

---

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [December 11, 2023, 12:43am UTC](https://discourse.julialang.org/t/understanding-the-behaviour-of-butterworth-filter-in-dsp/107396/3 "2023-12-11T00:43:35Z")

</div>

Interesting thank you! Is there any possible way to create a filter that minimizes this effect in this case?

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [December 11, 2023, 12:57am UTC](https://discourse.julialang.org/t/understanding-the-behaviour-of-butterworth-filter-in-dsp/107396/4 "2023-12-11T00:57:52Z")

</div>

The usual approach is to ignore the transient – just ignore the first few output samples. Another possibility is to use a FIR filter, which may have a shorter transient; in any case, their transient length is easier to predict (roughly half the filter order).

Another interesting resource here: [Transient Response, Steady State, and Decay | Introduction to Digital Filters](https://www.dsprelated.com/freebooks/filters/Transient_Response_Steady_State.html)

You may also consider using filters especially conceived to remove DC trends; there’s a good selection here: [Linear-phase DC Removal Filter - Rick Lyons](https://www.dsprelated.com/showarticle/58.php)
