From: Ben Collins <bcollins@kernel.org>
To: "David Lechner" <dlechner@baylibre.com>,
"Ben Collins" <bcollins@watter.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/5] iio: mcp9600: Add support for IIR filter
Date: Thu, 14 Aug 2025 09:38:02 -0400 [thread overview]
Message-ID: <2025081409-ubiquitous-cuckoo-76acbd@boujee-and-buff> (raw)
In-Reply-To: <2025081408-umber-axolotl-e6c6dd@boujee-and-buff>
[-- Attachment #1: Type: text/plain, Size: 2530 bytes --]
On Thu, Aug 14, 2025 at 09:06:39AM -0500, Ben Collins wrote:
> On Wed, Aug 13, 2025 at 05:52:04PM -0500, David Lechner wrote:
> > On 8/13/25 10:15 AM, Ben Collins wrote:
> > > MCP9600 supports an IIR filter with 7 levels. Add IIR attribute
> ...
> > > static int mcp9600_read(struct mcp9600_data *data,
> > > @@ -186,6 +189,9 @@ static int mcp9600_read_raw(struct iio_dev *indio_dev,
> > > case IIO_CHAN_INFO_THERMOCOUPLE_TYPE:
> > > *val = mcp9600_tc_types[data->thermocouple_type];
> > > return IIO_VAL_CHAR;
> > > + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> > > + *val = data->filter_level;
> >
> > We can't just pass the raw value through for this. The ABI is defined
> > in Documentation/ABI/testing/sysfs-bus-iio and states that the value
> > is the frequency in Hz.
> ...
> > For example, for 3 Hz sample rate (18-bit samples), I got:
> >
> > n f_3dB (Hz)
> > 1 0.58774
> > 2 0.24939
> > 3 0.12063
> > 4 0.05984
> > 5 0.02986
> > 6 0.01492
> > 7 0.00746
> >
> > I had to skip n=0 though since that is undefined. Not sure how we
> > handle that since it means no filter. Maybe Jonathan can advise?
>
> Thanks for notes. If I'm reading for datasheet formula right,
>
> k = 2 / (2^n + 1)
>
> So n=0 would be k=1. I did this formula for n=[0-7] and get:
>
> n k
> 0 1.00000
> 1 0.66667
> 2 0.40000
> 3 0.22222
> 4 0.11765
> 5 0.06061
> 6 0.03077
> 7 0.01550
>
> I'm not versed in filter frequency, but would these be the correct
> values to use for the coefficients?
This seems to be what I was looking for:
Got it. For a 1-pole IIR low-pass of the form
y_t = y_{t-1} + k(x_t - y_{t-1}), the –3 dB cutoff is
f_c = \frac{-\ln(1-k)}{2\pi}\,f_s
Using your k=\frac{2}{2^n+1} and a sample rate f_s = 3\ \text{Hz}, the equivalent –3 dB cutoff frequencies are:
n k f_c (Hz) time constant τ (s) = 1/(2π f_c)
0 1.0000000000 ∞ 0.0000
1 0.6666666667 0.5245487288 0.3034
2 0.4000000000 0.2439012692 0.6525
3 0.2222222222 0.1199938006 1.3264
4 0.1176470588 0.0597609987 2.6632
5 0.0606060606 0.0298512716 5.3316
6 0.0307692308 0.0149219903 10.6658
7 0.0155038760 0.0074605397 21.3329
Notes:
• n=0 (k=1) is just “track the input” (no smoothing), so f_c\to\infty.
• If you’re using a different sampling rate, multiply the f_c values above by \frac{f_s}{3}.
--
Ben Collins
https://libjwt.io
https://github.com/benmcollins
--
3EC9 7598 1672 961A 1139 173A 5D5A 57C7 242B 22CF
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2025-08-14 13:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250813151614.12098-1-bcollins@watter.com>
2025-08-13 15:15 ` [PATCH v2 1/5] dt-bindings: iio: mcp9600: Add compatible for microchip,mcp9601 Ben Collins
2025-08-13 16:15 ` Krzysztof Kozlowski
2025-08-13 21:11 ` David Lechner
[not found] ` <2025081319-abiding-muskox-c434f3@boujee-and-buff>
2025-08-16 18:43 ` David Lechner
2025-08-13 15:15 ` [PATCH v2 2/5] iio: mcp9600: White space cleanup for tab alignment Ben Collins
2025-08-13 16:34 ` Andy Shevchenko
2025-08-13 15:15 ` [PATCH v2 3/5] iio: mcp9600: Add compatibility for mcp9601 Ben Collins
2025-08-13 16:40 ` Andy Shevchenko
2025-08-13 15:15 ` [PATCH v2 4/5] iio: mcp9600: Add support for dtbinding of thermocouple-type Ben Collins
2025-08-13 16:49 ` Andy Shevchenko
2025-08-13 21:19 ` David Lechner
2025-08-13 15:15 ` [PATCH v2 5/5] iio: mcp9600: Add support for IIR filter Ben Collins
2025-08-13 16:53 ` Andy Shevchenko
2025-08-13 22:52 ` David Lechner
2025-08-14 13:06 ` Ben Collins
2025-08-14 13:38 ` Ben Collins [this message]
2025-08-16 9:54 ` Jonathan Cameron
2025-08-16 13:12 ` Ben Collins
2025-08-16 15:08 ` Jonathan Cameron
2025-08-16 15:19 ` Ben Collins
2025-08-16 15:33 ` Ben Collins
2025-08-16 17:16 ` David Lechner
2025-08-17 17:11 ` Jonathan Cameron
2025-08-17 17:13 ` 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=2025081409-ubiquitous-cuckoo-76acbd@boujee-and-buff \
--to=bcollins@kernel.org \
--cc=andy@kernel.org \
--cc=bcollins@watter.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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
all inboxes | Powered by JetHome®