Linux IIO development
 help / color / mirror / Atom feed
From: ASSI <Stromeko@nexgo.de>
To: linux-iio@vger.kernel.org
Subject: Re: [bmp280 v1 4/6] iio: pressure: bmp280: enable filter settings for BMx280
Date: Tue, 12 Aug 2025 21:34:35 +0200	[thread overview]
Message-ID: <87pld0nxkk.fsf@Gerda.invalid> (raw)
In-Reply-To: 20250811211423.3e52a67a@jic23-huawei

Jonathan Cameron writes:
> We stuck to 3DB point for these because all most anything else is annoyingly
> filter type dependent with no real consistency of meaning.  At least 3dB is
> something you can establish if you have a reasonable amount of info about the
> filter (or a plot!)

If you look at my .sig you might glean I probably know the odd thing or
two about filters… and 3dB frequency is just as meaningless without
knowing the filter type even before one enters into whether or not there
is peaking and resonance.

> Obviously they are almost always effected by sampling frequency so that maths
> can be rather non trivial.
>
> Vs a completely misleading tap length control, an approx 3dB eyeballed
> off a plot is an improvement. 

Donning my hat as a user: I beg to differ.  I know this device has 8
different settings for the tap length of some otherwise unspecified
filter (you can deduce that it must be a a recursive shift and
accumulate type thing) and more taps mean larger timeconstant / somewhat
better smoothing.  I really just want to chose among these eight
settings and not calculate a 3dB frequency that isn't in the datasheet
(and maybe even a different one depending on the four other three-bit
choices I have w.r.t. device settings).

I imagine the reason this particular device uses this attribute is
purely due to the fact that it was already available and corresponds
roughly to what the control does.

> Adding more filter parameters is likely to end up with a very complex
> userspace, so if we have any way to get an approx 3dB point, stick to
> that.

Filter settings: 0, 2, 4, 8, 16 (see datasheet, that's 2**i below)

That's the simplest I can think of, really.  Per the datasheet, the
actual filter is:

  y(t) = ( (y(t-1) << i) - y(t-1) + x(t) ) >> i
       = 2**-i * x(t) (2**i-1)*2**-i * y(t-1) )

The canonical recursive single-pole LP has two coefficients, which
should be 1-d and d (d because it's the sample decay).

   2**-i + (2**i-1)*2**-i = 2**-1 * ( 1 + 2**i - 1 ) = 1

so check that.  The time constant (rise time to 63%) is then

  tau = -1/ln(d)

Oddly enough the data sheet gives time to >75%, but that is just a
scaling factor of ln(0.25) on the tau.  The nomalized corner frequency then is:

  fc/fs = -ln(d)/(2pi)

So lets check that:

|---+--------+--------+--------+--------+-----------+----------|
| i |    1-d |      d |    tau |  t>75% | datasheet |    fc/fs |
|---+--------+--------+--------+--------+-----------+----------|
| 0 |      1 |      0 |    --- |    --- |         1 |        1 |
| 1 |    0.5 |    0.5 |  1.443 |  2.000 |     1.443 | 0.110318 |
| 2 |   0.25 |   0.75 |  3.476 |  4.819 |     3.476 | 0.045786 |
| 3 |  0.125 |  0.875 |  7.489 | 10.382 |     7.489 | 0.021252 |
| 4 | 0.0625 | 0.9375 | 15.495 | 21.481 |    15.495 | 0.010272 |
|---+--------+--------+--------+--------+-----------+----------|

> Been way to long since I last did any digital filter stuff, but poking google
> ai thing with "IIR filter y_t = (a -1)/a * y_(t-1) + x_t/a"
> came back with 3dB in digital angular frequency as
>
> w_c = arccos ((2a^2 - 2a - 1) / (2a(a - 1)) 
> Which might be right.

Given that it says w_c and said angular frequency, I'd wager a guess
that there's a factor 2pi that needs to go.  Yep, close enough
numerically.  Next time I'm bored I will whip out the trigonometric
identities table in Bronstein/Semendjajew and see why that arccos
espression is the same as -ln(d).

I'd still rather specify the filter as integers than having to enter
those floating-point numbers to get the device set up.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+


  reply	other threads:[~2025-08-12 19:34 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 23:30 [PATCH v9 0/4] pressure: bmp280: Minor cleanup and interrupt support Vasileios Amoiridis
2024-10-17 23:30 ` [PATCH v9 1/4] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Vasileios Amoiridis
2025-06-28 18:45   ` ASSI
2025-06-28 20:57     ` David Lechner
2025-06-29  7:43       ` ASSI
2025-07-11 19:17       ` ASSI
2025-07-12 14:49         ` ASSI
2025-07-21 19:15           ` ASSI
2025-07-26 18:34           ` ASSI
2025-07-27 19:08             ` ASSI
2024-10-17 23:30 ` [PATCH v9 2/4] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Vasileios Amoiridis
2024-10-17 23:30 ` [PATCH v9 3/4] iio: pressure: bmp280: Add data ready trigger support Vasileios Amoiridis
2024-10-17 23:30 ` [PATCH v9 4/4] iio: pressure: bmp280: Move bmp085 interrupt to new configuration Vasileios Amoiridis
2024-10-19 13:55 ` [PATCH v9 0/4] pressure: bmp280: Minor cleanup and interrupt support Jonathan Cameron
2025-08-03 14:07 ` [bmp280 v1 0/6] Fixes and enhancements for the bmp280 driver Achim Gratz
2025-08-03 14:07   ` [bmp280 v1 1/6] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
2025-08-06 15:46     ` Jonathan Cameron
2025-08-06 17:53       ` ASSI
2025-08-10 18:04         ` Jonathan Cameron
2025-08-03 14:07   ` [bmp280 v1 2/6] iio: pressure: bmp280: reduce overhead on read with MODE_FORCED Achim Gratz
2025-08-03 20:12     ` Andy Shevchenko
2025-08-06 15:58     ` Jonathan Cameron
2025-08-06 18:00       ` ASSI
2025-08-03 14:07   ` [bmp280 v1 3/6] iio: pressure: bmp280: implement sampling_frequency for BMx280 Achim Gratz
2025-08-03 20:26     ` Andy Shevchenko
2025-08-04 17:29       ` ASSI
2025-08-10 18:11         ` Jonathan Cameron
2025-08-10 19:12           ` ASSI
2025-08-11 19:48             ` Jonathan Cameron
2025-08-12 19:53               ` ASSI
2025-08-17 15:10                 ` Jonathan Cameron
2025-08-17 16:36                   ` ASSI
2025-08-03 14:08   ` [bmp280 v1 4/6] iio: pressure: bmp280: enable filter settings " Achim Gratz
2025-08-03 20:28     ` Andy Shevchenko
2025-08-04 17:14       ` ASSI
2025-08-10 18:13     ` Jonathan Cameron
2025-08-10 19:01       ` ASSI
2025-08-11 20:14         ` Jonathan Cameron
2025-08-12 19:34           ` ASSI [this message]
2025-08-17 14:51             ` Jonathan Cameron
2025-08-03 14:08   ` [bmp280 v1 5/6] iio: pressure: bmp280: remove code duplication Achim Gratz
2025-08-03 20:30     ` Andy Shevchenko
2025-08-10 18:19     ` Jonathan Cameron
2025-08-03 14:08   ` [bmp280 v1 6/6] iio: pressure: bmp280: implement sampling_frequency calculation for BMx280 Achim Gratz
2025-08-03 20:37     ` Andy Shevchenko
2025-08-04 17:20       ` ASSI
2025-08-03 19:20   ` [bmp280 v1 0/6] Fixes and enhancements for the bmp280 driver Andy Shevchenko
2025-08-10 18:58 ` [RFC PATCH v2 0/9] " Achim Gratz
2025-08-10 18:58   ` [RFC PATCH v2 1/9] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
2025-08-17 15:16     ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 2/9] iio: pressure: bmp280: implement adaptive wait for BMx280 devices Achim Gratz
2025-08-10 19:49     ` Andy Shevchenko
2025-08-16 18:42       ` ASSI
2025-08-10 18:58   ` [RFC PATCH v2 3/9] iio: pressure: bmp280: implement adaptive wait for BMP380 devices Achim Gratz
2025-08-10 18:58   ` [RFC PATCH v2 4/9] iio: pressure: bmp280: refactoring Achim Gratz
2025-08-17 15:23     ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 5/9] iio: pressure: bmp280: remove code duplication Achim Gratz
2025-08-10 18:58   ` [RFC PATCH v2 6/9] iio: pressure: bmp280: enable filter settings for BMx280 Achim Gratz
2025-08-17 16:37     ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 7/9] iio: pressure: bmp280: implement sampling_frequency " Achim Gratz
2025-08-17 16:53     ` Jonathan Cameron
2025-08-17 17:36       ` ASSI
2025-08-10 18:58   ` [RFC PATCH v2 8/9] iio: pressure: bmp280: implement sampling_frequency calculation " Achim Gratz
2025-08-17 17:04     ` Jonathan Cameron
2025-08-17 17:40       ` ASSI
2025-08-18 17:52         ` Jonathan Cameron
2025-08-10 18:58   ` [RFC PATCH v2 9/9] iio: pressure: bmp280: test longer autosuspend (WIP) Achim Gratz
2025-08-17 17:05     ` Jonathan Cameron
2025-08-17 17:44       ` ASSI
2025-08-11 12:14   ` [RFC PATCH v2 0/9] Fixes and enhancements for the bmp280 driver Andy Shevchenko
2025-08-11 20:17   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pld0nxkk.fsf@Gerda.invalid \
    --to=stromeko@nexgo.de \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox