LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

optimization for calculation

Solved!
Go to solution

Hi,

 

Is there a faster way to calculate this common mode rejection...? I have een EEG signal (the first 64 channels) and they have to be added and devide through the number of available channels and then subtracte from the signal. See picture:

Optimization needed2.png

 

Best regards,

Thijs Boeree

0 Kudos
Message 1 of 8
(2,562 Views)

Have you tested this?  When you add two arrays of different lengths, the result has the same length as the shorter input array.  Since the input to the shift register is an empty array the output is also empty.

 

All that processing on empty arrays is actually pretty fast because the compiler optimizes away much of the code.

 

When I initialize the shift register with an array of the same length as the array being added, this code is slightly faster than a few other things I tried.

 

Lynn

0 Kudos
Message 2 of 8
(2,523 Views)

I'm curious if you actually need the FOR loop at the end or if the native function will handle it.  It is generally faster to let the native functions do their work with arrays instead of using explicit loops.  You may need a Transpose Array in there to make it work.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 8
(2,511 Views)

Ah you're right, i have to initialize a 1D array first. but i don't know a better a way to add a 1D array and a 2D array without using a for loop...? Is there?

Regards,

Thijs

0 Kudos
Message 4 of 8
(2,494 Views)

You can use the funtion "Initialize Array" available in array pallette to initialize a 1D or 2D array without using for loop.

______________________________________________
Kudos are welcome
0 Kudos
Message 5 of 8
(2,481 Views)

Here are two other ways , which one is faster?  It's up to you to test it 🙂

two ways.png

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 6 of 8
(2,465 Views)

Hi,

 

The examples you are giving are with 1D array's but i have 2D array's, i have a 2D array with let's say 107 channels (columns) and 40 samples (each channel (rows)).

 

Now i have to add all the single samples of each channel and then devide them through the nummer of channels and subtract the outcome of each channel.

See here:

Optimization needed2.png

 

Best regards,

Thijs

 

 

0 Kudos
Message 7 of 8
(2,445 Views)
Solution
Accepted by topic author ThijsBoeree

Hi Thijs,

 

use just one loop:

check.png

On my PC this routine takes ~50µs...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 8
(2,437 Views)