TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Automated smooth Nth order derivatives of noisy data

146 pointsby hugohadfield8 months ago
This little project came about because I kept running into the same problem: cleanly differentiating sensor data before doing analysis. There are a ton of ways to solve this problem, I&#x27;ve always personally been a fan of using kalman filters for the job as its easy to get the double whammy of resampling&#x2F;upsampling to a fixed consistent rate and also smoothing&#x2F;outlier rejection. I wrote a little numpy only bayesian filtering&#x2F;smoothing library recently (<a href="https:&#x2F;&#x2F;github.com&#x2F;hugohadfield&#x2F;bayesfilter&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;hugohadfield&#x2F;bayesfilter&#x2F;</a>) so this felt like a fun and very useful first thing to try it out on! If people find kalmangrad useful I would be more than happy to add a few more features etc. and I would be very grateful if people sent in any bugs they spot.. Thanks!

12 comments

magicalhippo8 months ago
Looks really cool.<p>I stumbled over this[1] page recently, which has a method that&#x27;s apparently is better than the &quot;traditional&quot; Savitzky-Golay filters.<p>The idea seems to be to start with the desired frequency response, with lower frequencies close to the ideal differentiator, and higher frequencies tending smoothly to zero. This is then used to derive the filter coefficients through a set of equations.<p>The author generalizes it to irregularly sampled data near the end, so would be interesting to compare the approaches.<p>Just thought it&#x27;d throw it out there.<p>[1]: <a href="http:&#x2F;&#x2F;www.holoborodko.com&#x2F;pavel&#x2F;numerical-methods&#x2F;numerical-derivative&#x2F;smooth-low-noise-differentiators&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.holoborodko.com&#x2F;pavel&#x2F;numerical-methods&#x2F;numerical...</a>
fisian8 months ago
Great work!<p>I would&#x27;ve needed this recently for some data analysis, to estimate the mass of an object based on position measurments. I tried calculating the 2nd derivative with a Savitzky-Golay filter, but still had some problems and ended up using a different approach (also using a Kalman filter, but with a physics-based model of my setup).<p>My main problem was that I had repeated values in my measurements (sensor had a lower, non-integer divisible sampling rate than the acquisition pipeline). This especially made clear that np.gradient wasn&#x27;t suitable, because it resulted in erratic switches between zero and the calculated derivative. Applying, np.gradient twice made the data look like random noise.<p>I will try using this library, when I next get the chance.
评论 #41868449 未加载
评论 #41868323 未加载
jcgrillo8 months ago
This is great! I&#x27;ve taken sort of a passive interest in this topic over the years, some papers which come to mind are [1] and [2] but I don&#x27;t think I&#x27;ve seen a real life example of using the Kalman filter before.<p>[1] <a href="https:&#x2F;&#x2F;www.sciencedirect.com&#x2F;science&#x2F;article&#x2F;abs&#x2F;pii&#x2F;0021929081900762" rel="nofollow">https:&#x2F;&#x2F;www.sciencedirect.com&#x2F;science&#x2F;article&#x2F;abs&#x2F;pii&#x2F;002192...</a><p>[2] <a href="https:&#x2F;&#x2F;ieeexplore.ieee.org&#x2F;stamp&#x2F;stamp.jsp?tp=&amp;arnumber=9241009" rel="nofollow">https:&#x2F;&#x2F;ieeexplore.ieee.org&#x2F;stamp&#x2F;stamp.jsp?tp=&amp;arnumber=924...</a>
评论 #41871949 未加载
评论 #41865554 未加载
pm8 months ago
Congratulations! Pardon my ignorance, as my understanding of mathematics at this level is beyond rusty, but what are the applications of this kind of functionality?
评论 #41864774 未加载
评论 #41864688 未加载
评论 #41872941 未加载
评论 #41864699 未加载
评论 #41865843 未加载
theaussiestew8 months ago
I&#x27;m looking to calculate jerk from accelerometer data, I&#x27;m assuming this would be the perfect use case?
评论 #41864612 未加载
brody_slade_ai8 months ago
Kalman Filter helped me understand the mathematical concepts that make it a powerful tool for estimating values from noisy data<p>I made a simulation that forecasted a greenhouse&#x27;s temperature and humidity to help me understand the idea. I began by going over the basics of Gaussians and normal distribution once more. After that, I used NumPy and SciPy to develop the Kalman Filter in Python. To represent the system, I defined noise matrices (Q and R), a state transition matrix (F), and a control input matrix (B).
youoy8 months ago
Nice work! Just one quick question (maybe it&#x27;s clear but I have not looked at it in depth). It says it computes the derivative for non-uniformly sampled time series data and the example image shows this. Is this also well behaved if the sampled measurements have noise (it is not the case of the example)? Or should one use a different approach for that? Thanks!
评论 #41868758 未加载
tarlinian8 months ago
How did you choose the process noise covariance in your `grad` function? It doesn&#x27;t seem like a single process noise covariance structure should be globally applicable across all possible functions.
Animats8 months ago
That&#x27;s useful. Can it generate a simple filter for later real-time use, based on the statistics of the noise? That would be useful for self-tuning controllers.
评论 #41868274 未加载
seanhunter8 months ago
This looks cool. When you say &quot;there are tons of ways to solve this problem&quot;, presumably the canonical way is some sort of Fourier Analysis?
评论 #41868846 未加载
marmaduke8 months ago
This is really nice approach. We are doing some nonlinear system id, and faced with this kinda problem (not irregular spacing but low sample rate and noisy). Definitely will check it out.<p>What’s your opinion on ensemble KF? We’d like to use that for parameter estimations. I saw unscented in your bayesfilter, but not ensemble, so I’m curious. Thanks!
评论 #41868319 未加载
3abiton8 months ago
This got me thinking, is this used in supply chain problems?
评论 #41868863 未加载