LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Subtraction between the current sample value and the one several sampling times before

Solved!
Go to solution

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 

0 Kudos
Message 1 of 7
(3,289 Views)

having not looking at your code.....

  • put the series of numbers into an array
  • feed into a for loop
  • numbers go into a double pulled down shift register
  • take the difference
  • feed that number to another shift register with the addition function
  • oputput of that shift register will give you the last value

note: manipulate the array to start at the first or last element, also feed the n# to the for loop to run

0 Kudos
Message 2 of 7
(3,244 Views)

Hi,

 

check.png

Why use loops and shift registers?

 

All you need to do is collecting your samples in an array…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(3,215 Views)

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. 

0 Kudos
Message 4 of 7
(3,191 Views)

20170102.PNG

Is this what do you mean? (Bg is a subvi to obtain data from device at sampling times). Thank you.

0 Kudos
Message 5 of 7
(3,186 Views)
Solution
Accepted by topic author chalkwu

Hi chalkwu,

 

why do you put the whole array into the shift registers?

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(3,171 Views)

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

0 Kudos
Message 7 of 7
(3,139 Views)