01-01-2017 03:08 PM
Hello everyone,
I have a device which generates a series of numbers at sampling times, let's say every 1s.
The series of numbers is denoted as x0, x1, x2, ..., xk. I want to get the result at each sampling time Res = xk - x(k-n). If n=4, that is Res4 = x4 - x0, Res5 = x5 - x1....For the first 4 numbers, Res3 = x3 - x0, Res2 = x2 - x0, and Res1 = x1 - x0.
My codeing idea is that
Res1 = (x1 - x0) + 0 + 0 + 0;
Res2 = (x2 - x1) + (x1 - x0) +0 + 0;
Res3 = (x3 - x2) + (x2 - x1) + (x1 - x0) + 0;
Res4 = (x4 - x3) + (x3 - x2) + (x2 - x1) + (x1 - x0);
Res5 = (x5 - x4) + (x4 - x3) + (x3 - x2) + (x2 - x1);
...
Because n is supposed to be a variable, I can not use shifters directly. I try to use the for loop with the loop count N being variable n. The attached file is a test vi.
Can you help me please? Thank you.
Happy New Year!
Qun
Solved! Go to Solution.
01-01-2017 08:07 PM - edited 01-01-2017 08:16 PM
having not looking at your code.....
note: manipulate the array to start at the first or last element, also feed the n# to the for loop to run
01-02-2017 01:10 AM
01-02-2017 10:44 AM
The array is aquired online instead of a given array. And the sum of difference is not calculated by all elements, it is calculated by the latest n elements. At each sample time, I get one result. I am still working on it. Thank you.
01-02-2017 11:15 AM - edited 01-02-2017 11:27 AM
Is this what do you mean? (Bg is a subvi to obtain data from device at sampling times). Thank you.
01-02-2017 01:59 PM
01-03-2017 04:22 PM
Hi Knight. GerdW,
I thought there should have some subvi with the function storing certain length of some squence data. And that is Data Queue. Thank you very much.
Cheers,
Qun