# Filtfilt in DSP.jl - I really don't get it

**URL:** <https://discourse.julialang.org/t/filtfilt-in-dsp-jl-i-really-dont-get-it/10437>\
**Category:** Signal and Image Processing\
**Tags:** dsp\
**Created:** [April 19, 2018, 3:22pm UTC](https://discourse.julialang.org/t/filtfilt-in-dsp-jl-i-really-dont-get-it/10437 "2018-04-19T15:22:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceysa75](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ceysa75/32/19121_2.png) [@ceysa75](https://discourse.julialang.org/u/ceysa75)\
**Post date:** [April 19, 2018, 3:22pm UTC](https://discourse.julialang.org/t/filtfilt-in-dsp-jl-i-really-dont-get-it/10437/1 "2018-04-19T15:22:01Z")

</div>

Hi dear community members,

while making bigger steps forwards switching completely from Matlab to Julia here and there I am often struggling to solve some issues. This is mainly due to the poor/missing documentation of the packages. At the moment I am trying to make the filtfilt function run in DSP.jl (BTW: I am not an expert in filter designing…). Just to make it simple: My corresesponding matlab code is given below. But for hours now I have no idea how to realize that with DSP.jl. Anyone able to help ? Thank you…

Bandpass Filter in Matlab  
Wn=[0.5 15]/((1/dt)/2); % Cut off frequencies 0.5 Hz & 15 Hz  
[b,a] = butter(4,Wn,‘bandpass’); % Filter coefficients for bandpass  
filtered\_signal = filtfilt(b,a,raw\_signal); % Application of the filter

---

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [April 19, 2018, 4:43pm UTC](https://discourse.julialang.org/t/filtfilt-in-dsp-jl-i-really-dont-get-it/10437/2 "2018-04-19T16:43:16Z")

</div>

```julia
julia> using DSP

julia> myfilter = digitalfilter(Bandpass(0.1,0.15),Butterworth(2));

julia> mydata = rand(100);

julia> filtfilt(myfilter,mydata)

```

This seems to work, hopefully it will help you make some progress. This is adapted from the example section on this page: [https://juliadsp.github.io/DSP.jl/latest/filters.html#Filter-design-1](https://juliadsp.github.io/DSP.jl/latest/filters.html#Filter-design-1)

---

<div class="post-metadata">

**Author:** ![jrson](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jrson](https://discourse.julialang.org/u/jrson)\
**Post date:** [February 17, 2020, 10:59pm UTC](https://discourse.julialang.org/t/filtfilt-in-dsp-jl-i-really-dont-get-it/10437/3 "2020-02-17T22:59:28Z")

</div>

It was a simple and nice answer, but can I ask you one more, plz?

What should I do to use the Bandpass with high frequencies, such as 500 ~ 800 Hz?  
I am not sure how to control the Nyquest frequency or time step in your Julia code example.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [February 17, 2020, 11:21pm UTC](https://discourse.julialang.org/t/filtfilt-in-dsp-jl-i-really-dont-get-it/10437/4 "2020-02-17T23:21:49Z")

</div>

You can type `?Bandpass` in REPL after `using DSP`

```julia
help?> Bandpass
search: Bandpass filter_type_bandpass

  Bandpass(Wn1, Wn2[; fs])

  Band pass filter with normalized pass band (Wn1, Wn2). If fs is not specified, Wn1 and Wn2 are interpreted as
  normalized frequencies in half-cycles/sample.

```

So you can either specify cutoff frequencies in Hz and the sampling frequency fs, or specify cutoff frequencies normalized to fs/2.

> **[Normalized frequency (signal processing)](https://en.wikipedia.org/wiki/Normalized_frequency_(unit))**
>
> In digital signal processing (DSP), normalized frequency (f') is a quantity having dimension of frequency expressed in units of "cycles per sample". It equals f'=f/fs, where f is an ordinary frequency quantity (in "cycles per second") and fs is the sampling rate (in "samples per second").
> For regularly spaced sampling, the continuous time variable, t (with units of seconds), is replaced by a discrete sampling count variable, n=t/T (with units of "samples"), upon division by the sampling interv...
