{"id":178,"date":"2015-02-03T22:21:31","date_gmt":"2015-02-03T21:21:31","guid":{"rendered":"http:\/\/www.sevenwatt.com\/main\/?p=178"},"modified":"2015-03-02T22:59:07","modified_gmt":"2015-03-02T21:59:07","slug":"evaluation-noise-filtering-weak-ook-signals-rfm69","status":"publish","type":"post","link":"https:\/\/www.sevenwatt.com\/main\/evaluation-noise-filtering-weak-ook-signals-rfm69\/","title":{"rendered":"Evaluation noise filtering weak OOK signals &#8211; RFM69"},"content":{"rendered":"<p>As explained in a previous post , noise can spoil the reception of OOK signals from remote sensors. One solution to deal with the noise filtering of spikes in the ON\/OFF binary signals is to apply a moving average filter of the last <em>n<\/em> received samples. When <em>n<\/em> is odd, the &#8220;average&#8221; is one if more then half the bits in the filter buffer is one, and otherwise zero. With a filter length of <em>n=3<\/em> a single outlier sample will not disturb the intended signal. With a filter length of 5, spikes with a duration of two samples can be handled. Clean signals are as snappy as the where, and timings can be determined to the accuracy of the sample rate.<\/p>\n<p>To find the optimal length of the moving average filter, a setup was created with a remote sensor giving a signal that was not received all the time. For each filter length, 100 transmissions where listened to. The graph below shows the success rate as function of the filter length.<br \/>\n<a href=\"http:\/\/www.sevenwatt.com\/main\/wp-content\/uploads\/2015\/02\/433OOK_mov_avg_eval.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-179\" src=\"http:\/\/www.sevenwatt.com\/main\/wp-content\/uploads\/2015\/02\/433OOK_mov_avg_eval.png\" alt=\"433OOK_mov_avg_eval\" width=\"483\" height=\"291\" srcset=\"https:\/\/www.sevenwatt.com\/main\/wp-content\/uploads\/2015\/02\/433OOK_mov_avg_eval.png 483w, https:\/\/www.sevenwatt.com\/main\/wp-content\/uploads\/2015\/02\/433OOK_mov_avg_eval-300x180.png 300w\" sizes=\"auto, (max-width: 483px) 100vw, 483px\" \/><\/a><\/p>\n<p>The binary ON\/OFF signal was sampled on the DATA\/DIO2 pin of the RFM69 with sample rate 25\u00b5s. The bitrate was set to 4000bps. With this setting, the internal sampling rate of the RFM69 is 10\u00b5s. This &#8220;guarantees&#8221; a noisy signal for test purposes. The filter length <em>n=1<\/em> is actually unfiltered data at 25\u00b5s\/sample offered to the decoders. The longest filter length <em>n=15<\/em> takes an averaging window of 375\u00b5s. This is resiliant to noisy spikes (either ON or OFF) of 7 times the sample rate, thus 175\u00b5s. The minimum pulse duration of the received signal, the Oregon Scientific V1 sensor, is about 1100\u00b5s, and obviously can stand the long filter periods.<\/p>\n<p>For OOK signals that vary quicker, possibly a shorter filter length should be taken. The shortest pulse durations of OOK sensors and remote controls is around 300\u00b5s.<\/p>\n<p>The design of the filter is simply an unbsigned integer, in which the most recent reading (1 or 0) is shifted in from the right. The filter length is enforced by only looking at the least significant\u00a0<em>n<\/em> bits. Deciding on the filtered value is a matter of counting the one-bits in the filter.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/moving average buffer, max length = 31!\r\nstatic uint32_t filter= 0;\r\nstatic uint8_t avg_len = 7;\r\nstatic uint32_t sig_mask = (1 &lt;&lt; avg_len) - 1;\r\n\r\nvoid receiveOOK() {\r\n    while (....) {\r\n        filter = (filter &lt;&lt; 1) | (data_in &amp; 0x01);\r\n\r\n        \/\/efficient bit count, from literature\r\n        uint8_t c = 0;\r\n        uint32_t v = filter &amp; sig_mask;\r\n        for (c = 0; v; c++)\r\n        {\r\n          v &amp;= v - 1; \/\/ clear the least significant bit set\r\n        }\r\n        uint8_t data_out = (c &gt; (avg_len &gt;&gt; 1)); \/\/bit count moving average\r\n\r\n        \/\/decode OOK signal\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As explained in a previous post , noise can spoil the reception of OOK signals from remote sensors. One solution to deal with the noise filtering of spikes in the ON\/OFF binary signals is to apply a moving average filter of the last n received samples. When n is odd, the &#8220;average&#8221; is one if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7,27,15],"tags":[6,32,28,33,58],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-ook","category-picos-arm","category-rfm69","tag-868mhz","tag-arduino","tag-jeenode","tag-nucleo","tag-ook"],"_links":{"self":[{"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":5,"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/posts\/178\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sevenwatt.com\/main\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}