Created
June 5, 2020 10:53
-
-
Save fcgdam/a353edb3add38c254ab71d9279534fdb to your computer and use it in GitHub Desktop.
DSM501a IIR LPF - Infinite Response Low Pass filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"fa93e49d.59c9d","type":"function","z":"44ba6b13.5c4d64","name":"IIR Low Pass Filter","func":"// IIR LPF factors\n f_a0 = 0.0010227586546542474; // Input factors\n f_a1 = 0.002045517309308495;\n f_a2 = 0.0010227586546542474;\n \n f_b1 = -1.9066459797557103; // Output factors\n f_b2 = 0.9107370143743273;\n\n// PPM 1.0 input variables\nvar i0_c10 = msg.payload.cPM10;\nvar i1_c10 = context.get('i1_c10') || 0;\nvar i2_c10 = context.get('i2_c10') || 0;\n\n// PPM 1.0 output variables\nvar o0_c10 = context.get('o0_c10') || 0;\nvar o1_c10 = context.get('o1_c10') || 0;\n\n\n// Calculate the IIR\nvar lpf = i0_c10 * f_a0 + \n i1_c10 * f_a1 + \n i2_c10 * f_a2 - // We add the negative output factors\n o0_c10 * f_b1 - \n o1_c10 * f_b2;\n \n// Memorize the variables\ncontext.set( 'i2_c10' , i1_c10 );\ncontext.set( 'i1_c10' , i0_c10 );\n\ncontext.set( 'o1_c10' , o0_c10 );\ncontext.set( 'o0_c10' , lpf );\n\n// PPM 2.5 input variables\nvar i0_c25 = msg.payload.cPM25;\nvar i1_c25 = context.get('i1_c25') || 0;\nvar i2_c25 = context.get('i2_c25') || 0;\n\n// PPM 1.0 output variables\nvar o0_c25 = context.get('o0_c25') || 0;\nvar o1_c25 = context.get('o1_c25') || 0;\n\n\n// Calculate the IIR\nvar lpf25 = i0_c25 * f_a0 + \n i1_c25 * f_a1 + \n i2_c25 * f_a2 - // We add the negative output factors\n o0_c25 * f_b1 - \n o1_c25 * f_b2;\n \n// Memorize the variables\ncontext.set( 'i2_c25' , i1_c25 );\ncontext.set( 'i1_c25' , i0_c25 );\n\ncontext.set( 'o1_c25' , o0_c25 );\ncontext.set( 'o0_c25' , lpf25 );\n\nmsg.payload = {}\nmsg.payload.cfP10 = lpf;\nmsg.payload.cfP25 = lpf25;\n\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":40,"wires":[["273cea4a.08db0e","5d303ca9.50fdcc"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment