{"action":"created","issue":{"url":"https://api.github.com/repos/arduino/Arduino/issues/3934","labels_url":"https://api.github.com/repos/arduino/Arduino/issues/3934/labels{/name}","comments_url":"https://api.github.com/repos/arduino/Arduino/issues/3934/comments","events_url":"https://api.github.com/repos/arduino/Arduino/issues/3934/events","html_url":"https://github.com/arduino/Arduino/issues/3934","id":110361368,"number":3934,"title":"Tutorial/Smoothing algorithm is a poor choice","user":{"login":"bdlow","id":7970559,"avatar_url":"https://avatars.githubusercontent.com/u/7970559?v=3","gravatar_id":"","url":"https://api.github.com/users/bdlow","html_url":"https://github.com/bdlow","followers_url":"https://api.github.com/users/bdlow/followers","following_url":"https://api.github.com/users/bdlow/following{/other_user}","gists_url":"https://api.github.com/users/bdlow/gists{/gist_id}","starred_url":"https://api.github.com/users/bdlow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdlow/subscriptions","organizations_url":"https://api.github.com/users/bdlow/orgs","repos_url":"https://api.github.com/users/bdlow/repos","events_url":"https://api.github.com/users/bdlow/events{/privacy}","received_events_url":"https://api.github.com/users/bdlow/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/arduino/Arduino/labels/Component:%20Documentation","name":"Component: Documentation","color":"009800"}],"state":"closed","locked":false,"assignee":{"login":"agdl","id":2743774,"avatar_url":"https://avatars.githubusercontent.com/u/2743774?v=3","gravatar_id":"","url":"https://api.github.com/users/agdl","html_url":"https://github.com/agdl","followers_url":"https://api.github.com/users/agdl/followers","following_url":"https://api.github.com/users/agdl/following{/other_user}","gists_url":"https://api.github.com/users/agdl/gists{/gist_id}","starred_url":"https://api.github.com/users/agdl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agdl/subscriptions","organizations_url":"https://api.github.com/users/agdl/orgs","repos_url":"https://api.github.com/users/agdl/repos","events_url":"https://api.github.com/users/agdl/events{/privacy}","received_events_url":"https://api.github.com/users/agdl/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/arduino/Arduino/milestones/15","html_url":"https://github.com/arduino/Arduino/milestones/Release%201.6.6","labels_url":"https://api.github.com/repos/arduino/Arduino/milestones/15/labels","id":1158070,"number":15,"title":"Release 1.6.6","description":"","creator":{"login":"ffissore","id":510465,"avatar_url":"https://avatars.githubusercontent.com/u/510465?v=3","gravatar_id":"","url":"https://api.github.com/users/ffissore","html_url":"https://github.com/ffissore","followers_url":"https://api.github.com/users/ffissore/followers","following_url":"https://api.github.com/users/ffissore/following{/other_user}","gists_url":"https://api.github.com/users/ffissore/gists{/gist_id}","starred_url":"https://api.github.com/users/ffissore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ffissore/subscriptions","organizations_url":"https://api.github.com/users/ffissore/orgs","repos_url":"https://api.github.com/users/ffissore/repos","events_url":"https://api.github.com/users/ffissore/events{/privacy}","received_events_url":"https://api.github.com/users/ffissore/received_events","type":"User","site_admin":false},"open_issues":42,"closed_issues":841,"state":"open","created_at":"2015-06-10T07:48:32Z","updated_at":"2015-10-29T08:58:18Z","due_on":null,"closed_at":null},"comments":63,"created_at":"2015-10-08T02:40:16Z","updated_at":"2015-10-29T09:23:47Z","closed_at":"2015-10-28T16:04:44Z","body":"The algorithm used in the Smoothing tutorial (https://www.arduino.cc/en/Tutorial/Smoothing) uses a simple moving average of 10 samples, storing the samples in an array.\r\n\r\nWhilst useful in some applications, for simply removing noise from an analog input a simple moving average (IIR filter) is a more efficient and less convoluted method. e.g.:\r\n\r\n    const int filterWeight = 4;  // higher numbers = heavier filtering\r\n    const int numReadings = 10;\r\n\r\n    int average = 0;                // the average\r\n\r\n    void setup() {\r\n      // initialize serial communication with computer:\r\n      Serial.begin(9600);\r\n      // seed the filter\r\n      average = analogRead(inputPin);\r\n    }\r\n    void loop() {\r\n      for (int i = 0; i < numReadings; i++) {\r\n        average = average + (analogRead(inputPin) - average) >> filterWeight;\r\n      }\r\n      Serial.println(average);\r\n      delay(1);\r\n    }\r\n"},"comment":{"url":"https://api.github.com/repos/arduino/Arduino/issues/comments/152125088","html_url":"https://github.com/arduino/Arduino/issues/3934#issuecomment-152125088","issue_url":"https://api.github.com/repos/arduino/Arduino/issues/3934","id":152125088,"user":{"login":"VogonJeltz","id":11213519,"avatar_url":"https://avatars.githubusercontent.com/u/11213519?v=3","gravatar_id":"","url":"https://api.github.com/users/VogonJeltz","html_url":"https://github.com/VogonJeltz","followers_url":"https://api.github.com/users/VogonJeltz/followers","following_url":"https://api.github.com/users/VogonJeltz/following{/other_user}","gists_url":"https://api.github.com/users/VogonJeltz/gists{/gist_id}","starred_url":"https://api.github.com/users/VogonJeltz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VogonJeltz/subscriptions","organizations_url":"https://api.github.com/users/VogonJeltz/orgs","repos_url":"https://api.github.com/users/VogonJeltz/repos","events_url":"https://api.github.com/users/VogonJeltz/events{/privacy}","received_events_url":"https://api.github.com/users/VogonJeltz/received_events","type":"User","site_admin":false},"created_at":"2015-10-29T09:23:47Z","updated_at":"2015-10-29T09:23:47Z","body":"not the basic average (mean) - the weighted average, in this case the weighted floating average.\r\nfor x=0.5 it's the basic average (mean) though:\r\n\r\navg = 0.5*SensorValue + (1 - 0.5)*avg_old =  0.5*(SensorValue + avg_old) = (SensorValue + avg_old) / 2\r\n"}}