{"action":"created","issue":{"url":"https://api.github.com/repos/betaflight/betaflight/issues/5231","repository_url":"https://api.github.com/repos/betaflight/betaflight","labels_url":"https://api.github.com/repos/betaflight/betaflight/issues/5231/labels{/name}","comments_url":"https://api.github.com/repos/betaflight/betaflight/issues/5231/comments","events_url":"https://api.github.com/repos/betaflight/betaflight/issues/5231/events","html_url":"https://github.com/betaflight/betaflight/pull/5231","id":298167634,"number":5231,"title":"Biquad RC+FIR2: Fix 'k' calculation to match previous Q/R impl.","user":{"login":"fujin","id":6873,"avatar_url":"https://avatars1.githubusercontent.com/u/6873?v=4","gravatar_id":"","url":"https://api.github.com/users/fujin","html_url":"https://github.com/fujin","followers_url":"https://api.github.com/users/fujin/followers","following_url":"https://api.github.com/users/fujin/following{/other_user}","gists_url":"https://api.github.com/users/fujin/gists{/gist_id}","starred_url":"https://api.github.com/users/fujin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fujin/subscriptions","organizations_url":"https://api.github.com/users/fujin/orgs","repos_url":"https://api.github.com/users/fujin/repos","events_url":"https://api.github.com/users/fujin/events{/privacy}","received_events_url":"https://api.github.com/users/fujin/received_events","type":"User","site_admin":false},"labels":[{"id":664778742,"url":"https://api.github.com/repos/betaflight/betaflight/labels/RN:%20BUGFIX","name":"RN: BUGFIX","color":"0e8a16","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/betaflight/betaflight/milestones/6","html_url":"https://github.com/betaflight/betaflight/milestone/6","labels_url":"https://api.github.com/repos/betaflight/betaflight/milestones/6/labels","id":2278187,"number":6,"title":"Betaflight v3.3","description":" Feature freeze for v3.3: February 1, 2018","creator":{"login":"blckmn","id":6168871,"avatar_url":"https://avatars2.githubusercontent.com/u/6168871?v=4","gravatar_id":"","url":"https://api.github.com/users/blckmn","html_url":"https://github.com/blckmn","followers_url":"https://api.github.com/users/blckmn/followers","following_url":"https://api.github.com/users/blckmn/following{/other_user}","gists_url":"https://api.github.com/users/blckmn/gists{/gist_id}","starred_url":"https://api.github.com/users/blckmn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blckmn/subscriptions","organizations_url":"https://api.github.com/users/blckmn/orgs","repos_url":"https://api.github.com/users/blckmn/repos","events_url":"https://api.github.com/users/blckmn/events{/privacy}","received_events_url":"https://api.github.com/users/blckmn/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":418,"state":"open","created_at":"2017-01-25T19:22:10Z","updated_at":"2018-02-25T21:39:15Z","due_on":"2018-03-01T08:00:00Z","closed_at":null},"comments":141,"created_at":"2018-02-19T05:47:41Z","updated_at":"2018-02-26T14:27:28Z","closed_at":"2018-02-20T05:03:23Z","author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/betaflight/betaflight/pulls/5231","html_url":"https://github.com/betaflight/betaflight/pull/5231","diff_url":"https://github.com/betaflight/betaflight/pull/5231.diff","patch_url":"https://github.com/betaflight/betaflight/pull/5231.patch"},"body":"* When I initially implemented the ability to specify the cutoff frequency directly (#5144), I took the logic from the pt1FilterInit to generate (k), the filter gain, without testing that 'k' would be similar to the previous (Q/R) version.\r\n* It was shown by Saxin's MATLAB/Octave code that there was some divergence between the FKF code and the current Biquad RC+FIR2 code: https://github.com/betaflight/betaflight/pull/5215#issuecomment-366558358\r\n> The differences are small but they do exist:\r\n> Difference RMS = 0.4\r\n> Max absolute diff. = 16\r\n> Diff. Mean = 0.0015\r\n* glowtape supplied a simple calculation in https://github.com/betaflight/betaflight/pull/5215#issuecomment-366580888 which generates similar\r\n  'k' as the previous implementation. Notably, it is off for values of `Q=300 R=88` / `613Hz @ 32kHz` by `0.00254272`, but definitely closer than it was:\r\n\r\n![difference between FKF / BiquadRC+FIR2](https://user-images.githubusercontent.com/6873/36363685-cc280bb2-15a3-11e8-9ffb-6b767069e201.png)\r\n\r\nHere's the octave code previously shown by ledvinap modified to show both versions of 'k' calculation, and the difference (which you can see in your octave 'Workspace' section):\r\n``` octave\r\nlen = 1000;\r\n\r\nlastX = 0;\r\nq = 300 * 0.000001;\r\nr = 88 * 0.001;\r\np = 0;\r\n\r\nvx = zeros([len,1]);\r\nvk = zeros([len,1]);\r\n\r\ninput = rand([len,1]);\r\n\r\nx = 0;\r\n\r\n\r\nfor i = 1:length(input)\r\n  x += (x - lastX);\r\n\r\n  % update last state\r\n  lastX = x;\r\n\r\n  % prediction update\r\n  p = p + q;\r\n\r\n  % measurement update\r\n  k = p / (p + r);\r\n  x += k * (input(i) - x);\r\n  p = (1 - k) * p;\r\n\r\n  vx(i)=x;\r\n  vk(i)=k;\r\nendfor\r\n\r\n\r\nf_cut = 613;\r\ndT = 32 * 0.000001;\r\n\r\nq_r_k = 2 * 2 * sqrt(q) / (sqrt(q + 4 * r) + sqrt(q));  % RC filter k\r\nk = 1 - exp(-2 * pi * f_cut * dT); % glowtape's proposed 'k'\r\ndiff_k = k - q_r_k; % difference between the two (check workspace for value)\r\n\r\nb = [k/2, k/2, 0];\r\na = [1, -(1-k), 0];\r\n\r\nfx = filter(b,a,input);   % IIR filter input data\r\n\r\nplot(fx-vx);\r\n```\r\nResulting values from workspace:\r\n```\r\nk = 0.115958\r\nq_r_k = 0.113416\r\ndiff_k = 0.00254272\r\n```\r\n\r\nI'm opening this now for discussion in the hopes that we can come up with a minor modification to this commit which causes equivalence (e.g. diff_k = 0) while retaining the ability to specify the frequency cutoff.\r\n"},"comment":{"url":"https://api.github.com/repos/betaflight/betaflight/issues/comments/368520014","html_url":"https://github.com/betaflight/betaflight/pull/5231#issuecomment-368520014","issue_url":"https://api.github.com/repos/betaflight/betaflight/issues/5231","id":368520014,"user":{"login":"ledvinap","id":2318015,"avatar_url":"https://avatars2.githubusercontent.com/u/2318015?v=4","gravatar_id":"","url":"https://api.github.com/users/ledvinap","html_url":"https://github.com/ledvinap","followers_url":"https://api.github.com/users/ledvinap/followers","following_url":"https://api.github.com/users/ledvinap/following{/other_user}","gists_url":"https://api.github.com/users/ledvinap/gists{/gist_id}","starred_url":"https://api.github.com/users/ledvinap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ledvinap/subscriptions","organizations_url":"https://api.github.com/users/ledvinap/orgs","repos_url":"https://api.github.com/users/ledvinap/repos","events_url":"https://api.github.com/users/ledvinap/events{/privacy}","received_events_url":"https://api.github.com/users/ledvinap/received_events","type":"User","site_admin":false},"created_at":"2018-02-26T14:27:28Z","updated_at":"2018-02-26T14:27:28Z","author_association":"NONE","body":"Averaging filter is pretty suboptimal, main advantage is possibly faster implementation ... "}}
{"actor":{"display_login":"ledvinap"}}