[Codesys] which of the two filtering methods is faster?

Source: Internet
Author: User
Method 1

(* Method 1 *)
(* --------------- Declaration part ----------------------*)
FUNCTION_BLOCK Filter_ActLoad
VAR_INPUT
Act_ B: REAL;
END_VAR
VAR_OUTPUT
Act_F: REAL;
END_VAR
VAR
Arr: ARRAY [0 .. 6] of real: = 7 (0 );
MaxValue, MinValue: REAL: = 0;
I: INT;
END_VAR

(* --------------- Implementation part ----------------------*)

Arr [6]: = Arr [5];
Arr [5]: = Arr [4];
Arr [4]: = Arr [3];
Arr [3]: = Arr [2];
Arr [2]: = Arr [1];
Arr [1]: = Arr [0];
Arr [0]: = Act_ B;

MaxValue: = Arr [0];
MinValue: = Arr [0];

FOR I: = 0 TO 6 DO
IF arr [I]> MaxValue THEN
MaxValue: = arr [I];
END_IF

IF arr [I] <MinValue THEN
MinValue: = arr [I];
END_IF
END_FOR

Act_F: = (Arr [0] + Arr [1] + Arr [2] + Arr [3] + Arr [4] + Arr [5] + Arr [6]-MaxValue-MinValue) /5.0;

 

Method 2

(* Method 2 *)
(* --------------- Declaration part ----------------------*)
FUNCTION_BLOCK Filter_ActLoad _
VAR_INPUT
Act_ B: REAL;
END_VAR
VAR_OUTPUT
Act_F: REAL;
END_VAR
VAR
A1, A2, A3, A4, A5, A6, A7: REAL: = 0;
MaxValue, MinValue: REAL;
END_VAR

(* --------------- Implementation part ----------------------*)

Arr [6]: = Arr [5];
Arr [5]: = Arr [4];
Arr [4]: = Arr [3];
Arr [3]: = Arr [2];
Arr [2]: = Arr [1];
Arr [1]: = Arr [0];
Arr [0]: = Act_ B;

MaxValue: = Arr [0];
MinValue: = Arr [0];

FOR I: = 0 TO 6 DO
IF arr [I]> MaxValue THEN
MaxValue: = arr [I];
END_IF

IF arr [I] <MinValue THEN
MinValue: = arr [I];
END_IF
END_FOR

Act_F: = (Arr [0] + Arr [1] + Arr [2] + Arr [3] + Arr [4] + Arr [5] + Arr [6]-MaxValue-MinValue) /5.0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.