# How to determine the -3dB frequency of a system

**URL:** https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755
**Category:** Modelling & Simulations
**Tags:** control, controlsystems
**Created:** [June 2, 2023, 8:39am UTC](https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755 "2023-06-02T08:39:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 2, 2023, 8:39am UTC](https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755/1 "2023-06-02T08:39:46Z")

</div>

I have the following system, controlled with a PI controller:

```julia
using ControlSystemsBase, Plots

P_sc = 4.42616018443722e6
I_sc = 11838.3957271545*4

P = tf(-1.898e-8, [1, 0.01934])
C = -pid(P_sc, I_sc)

PC = feedback(P*C)

```

I can create a bodeplot of the plant or the feedback system, but how can I get the -3db frequency as a number?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 2, 2023, 10:11am UTC](https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755/2 "2023-06-02T10:11:45Z")

</div>

OK, first I need the DC gain. I use this function to determine it:

```julia
function dc_gain(sys)
     sys.matrix[1].num[0] / sys.matrix[1].den[0]
end

```

I guess this will not work for all types of systems, not sure for which it works and for which not…

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 2, 2023, 10:35am UTC](https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755/3 "2023-06-02T10:35:04Z")

</div>

OK, this code does what I want, but I would be pleased for any comments how to improve it:

```julia
using ControlSystemsBase, Roots

P = tf(-1.898e-8, [1, 0.01934])

function dc_gain(sys)
     sys.matrix[1].num[0] / sys.matrix[1].den[0]
end

# calculate the 3db bandwidth of a low-pass like system
function w_3db(sys)
    gain_3db = abs(dc_gain(sys)) * exp10(-3/20)
    function res(w)
        mag = bode(sys, [w])[1][1]
        mag - gain_3db
    end
    res = find_zero(res, (exp10(-4), exp10(1)))
    return res
end

println(w_3db(P))

```

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [June 2, 2023, 1:24pm UTC](https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755/4 "2023-06-02T13:24:13Z")

</div>

Is there anything wrong with the built-in `dcgain`?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [June 2, 2023, 4:06pm UTC](https://discourse.julialang.org/t/how-to-determine-the-3db-frequency-of-a-system/99755/5 "2023-06-02T16:06:44Z")

</div>

Nothing wrong with it, just that I did not know that it exists…

```julia
dcgain(sys)[1]

```

works also fine…
