{"id":3577,"date":"2026-07-23T11:28:13","date_gmt":"2026-07-23T15:28:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=3577"},"modified":"2026-07-23T11:28:13","modified_gmt":"2026-07-23T15:28:13","slug":"matlab-kalman-filtering-for-thingspeak-sensor-data","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2026\/07\/23\/matlab-kalman-filtering-for-thingspeak-sensor-data\/","title":{"rendered":"MATLAB Kalman Filtering for ThingSpeak Sensor Data!?"},"content":{"rendered":"<p>I was just reading our doc page on <a href=\"https:\/\/www.mathworks.com\/help\/control\/ug\/kalman-filtering.html\">Kalman Filtering<\/a> in MATLAB. This gave me an idea. Could I apply this to ThingSpeak IoT data? And, if so, why?<\/p>\n<p>Turns out we have a weather station at the MathWorks Apple Hill building. This weather station has been producing data for 10 years on <a href=\"https:\/\/thingspeak.mathworks.com\/channels\/12397\">ThingSpeak Channel 12397<\/a>.<\/p>\n<p><a href=\"https:\/\/thingspeak.mathworks.com\/channels\/12397\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" src=\"https:\/\/blogs.mathworks.com\/iot\/wp-content\/blogs.dir\/15\/files\/2015\/11\/MathWorks_Weather_Station.png\" alt=\"MathWorks Weather Station mounted to building\" width=\"327\" height=\"436\" \/><\/a><\/p>\n<p><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">A\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">Kalman\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">filter\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">is\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">a\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">classic\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">method\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">for\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">estimating\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">the\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">true\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">value\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">of\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">something\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">you\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">can\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">only\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">measure\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">noisily.\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">It\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">keeps\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">a\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">running\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">best\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">estimate\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">and\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">updates\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">it\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">with\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">each\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">new\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">reading,\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">blending\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">what\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">it\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">expected\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">with\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">what\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">the\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">sensor\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">reported\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">and\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">leaning\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">on\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">whichever\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">it\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">trusts\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">more.\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">It\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">can\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">also\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">track\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">things\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">you\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">never\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">measured\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">directly,\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">like\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">how\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">fast\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">a\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">value\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">is\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">changing.\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">Noisy\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">readings\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">go\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">in;\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">a\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">cleaner\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">signal,\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">and\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">its\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">trend,\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">come\u00a0<\/span><span class=\"_wordAnimating_yu34g_11\" data-wf=\"\">out.<\/span><\/p>\n<p>To give this a try in MATLAB, you can use the <a href=\"https:\/\/www.mathworks.com\/help\/thingspeak\/thingspeakread.html\">thingSpeakRead<\/a> function and pass in the channel number. The pressure sensor data is a good example of the type of sensor data suited for a Kalman Filter. Pressure changes slowly and smoothly. Barometric pressure drifts over hours, it does not jump around, so the filter&#8217;s core assumption, that the value moves at a roughly steady rate between readings, holds up well. The sensor&#8217;s noise is right on the scale of the real changes. Our station reports pressure in steps of 0.01 inches of mercury, and the hour-to-hour movement is often about that same size, so the raw signal comes through as a jagged little staircase, exactly the kind of noise a Kalman filter is built to smooth away.<\/p>\n<p>So, why Kalman? For me, the thing I care about with pressure is the trend. Falling pressure means weather is on the way, rising pressure means it is clearing. You cannot read that reliably off a jumpy line, but the filter estimates the rate of change directly and clearly shows you the trend.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-3579\" src=\"https:\/\/blogs.mathworks.com\/iot\/files\/2026\/07\/thingspeak_kalman.png\" alt=\"\" width=\"1579\" height=\"909\" \/><\/p>\n<p>Reading the trend, I can see the pressure is going up. It might be counterintuitive, but this doesn&#8217;t mean it&#8217;s going to rain in New England like yesterday. A climbing barometer is a sign of high pressure moving in, which usually means clearing skies and fair weather. The overnight dip to 996 hPa was the unsettled part; the steady rise that followed is the atmosphere settling down. The filter helped us understand what&#8217;s going on&#8230; a little bit more. It is worth noting that pressure is only one clue in weather forecasting. And I am not a meteorologist.<\/p>\n<p>Over to you&#8230; what else can you find deep in the MATLAB documentation and apply to IoT sensor data?<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/iot\/files\/2026\/07\/thingspeak_kalman.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>I was just reading our doc page on Kalman Filtering in MATLAB. This gave me an idea. Could I apply this to ThingSpeak IoT data? And, if so, why?<br \/>\nTurns out we have a weather station at the MathWorks&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/iot\/2026\/07\/23\/matlab-kalman-filtering-for-thingspeak-sensor-data\/\">read more >><\/a><\/p>\n","protected":false},"author":148,"featured_media":3579,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[291],"tags":[210,209,8,124],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/3577"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/comments?post=3577"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/3577\/revisions"}],"predecessor-version":[{"id":3580,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/3577\/revisions\/3580"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media\/3579"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=3577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=3577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=3577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}