# How to implement Lyons’ Differentiator

**URL:** <https://discourse.julialang.org/t/how-to-implement-lyons-differentiator/109438>\
**Category:** Signal and Image Processing\
**Tags:** question\
**Created:** [January 30, 2024, 9:46am UTC](https://discourse.julialang.org/t/how-to-implement-lyons-differentiator/109438 "2024-01-30T09:46:11Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 30, 2024, 3:46pm UTC](https://discourse.julialang.org/t/how-to-implement-lyons-differentiator/109438/6 "2024-01-30T15:46:55Z")

</div>

> [@ufechner7](#):
>
> I am trying to implement a discrete time differentiator, Lyons’ Differentiator type two, see: [Design of a Discrete-Time Differentiator | Wireless Pi](https://wirelesspi.com/design-of-a-discrete-time-differentiator/)

Maybe offtopic, but I don’t see why these differentiator filters are so great. They are not min-max optimal (unlike Parks–McClellan), I think? Lyons [doesn’t really explain](https://www.dsprelated.com/showarticle/814.php) how he came up with it or by what criteria it is optimal.

For comparison, if you simply generate 5-point and 7-point finite-difference stencils using `stencil(-2:2, 0//1)` and `stencil(-3:3, 0//1)` from [this post](https://discourse.julialang.org/t/generating-finite-difference-stencils/85876/5), respectively, then I get a frequency response that is pretty good compared to the ones Lyons proposes. (Though for broadband you should probably do a whole-band optimization like Parks–McClellan, whereas `stencil` is designed to be much more accurate as \omega \to 0.)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/b/4b086f1419027c0577530d5ebcfce1262769d82d.png)

Am I missing something? What is special about the filter coefficients proposed by Lyons?

I guess they could be viewed as slightly better than the high-order stencil in a min-max (L\_\infty) sense over certain bandwidths, e.g. if you look at the right plot and ask over what bandwidth the |error| is \< 0.1 it is a bit wider for lyons5 than stencil5. But if you care about L\_\infty error over such a wide bandwidth, why not use Parks–McClellan?

Lyons mentions that his filter “can be implemented, if need be, without performing numerical multiplications”, by which I guess he means that the denominators are powers of two so that they can be implemented by bit shifts if you are using fixed-point arithmetic. (This isn’t true of the high-order finite-difference stencils.) Is that the key advantage? If so, it doesn’t apply to you since you are using floating-point calculations.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-implement-lyons-differentiator/109438)._
