LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Optimize 2D array creation for memory usage and parallel processing

Solved!
Go to solution

Missed that.

 

Lynn

Message 11 of 16
(786 Views)

It is the subvi of larger program.

 

Basically there is a complex signal coming from a ADC with 465120 samples. The objective of this subvi is to determine the magnitue and phase  of 15 different and well known frequencies contained in the signal. The magnitude and phase is basically recovered by multiplying the signal by sin and cos (quadrutare) of these the same frequencies (the basic idea lying behind is that the multiplication of two sin or cos waves of the same frequency gives a DC value). I tried to express everything as a matrix multiplication because I though it was the most optimal code.

 

5 different datasets are recorded so that we can get more accurate values by averaging and to get also the standard deviations.

 

The program works as it is supposed, I have no problems with it. The only concern is if there is any way to optimize the speed and/or memory usage.

 

I attach an updated version of the vi. With some of your comments already implemented

0 Kudos
Message 12 of 16
(783 Views)

I have been testing the program above, and it is noticiably faster than before. My only problem now is the memory usage, which seems slightly higher than before. Is there any trick I can use to reduce the amount of memory taken?

0 Kudos
Message 13 of 16
(748 Views)
Solution
Accepted by topic author obarriel

OK, I still think that you have way (way!!) too much code for this.

 

Basically you want to do a FFT of a huge signal, but are only interested in the amplitude and phase of very few selected frequencies.

 

All you need is a complex set of your base frequencies and a single matrix multiplication. The resulting complex array has the magnitude and phase of the desired components.

 

Attached is a very simple draft that demonstrates it for a single signal. You would simply need to place the variable parts inside a FOR loop and autoindex on your 2D array of signals.

 

It compares three techniques:

  1. A plain old FFT
  2. A very inefficient explicit FFT using a complex set of all frequencies and a matrix multiplication
  3. Same as 2, but looking at only very few frequencies.

You should be able to adapt it easily to your code. I have not done any benchmarking but I suspect that doing a plain FFT and then indexing out the desired components might not be much slower.

 

(I am taking some shortcuts and do some scaling so the result can be compared directly with the results, so modify as needed)

 

 

Note that the frequency set needs to be calculated only once (or whenever one if the inputs changes (size, frequency, etc).

 

Let me know if you have any questions.

 

(If you have many CPU cores, you could probably further speedup of the matrix multiplication by doing it explicit using a parallel FOR loop. You might even try the MASM toolkit.)

0 Kudos
Message 14 of 16
(729 Views)

Thank you very much!. I have already adapted your code to my application and works very well. In my computer it takes less than 2/3 of the memory than took before. It is also noticeably faster, specially after enabling the iteration parallelism in the for loop that generates the exponentials (I use a 8 core computer).   I had never used the ramp vi and I see now how useful it is.

 

As you have suggested I will replace the matrix multiplication by an explicit calculation to see if there is any further speed benefit.

 

Thank you again!

 

 

0 Kudos
Message 15 of 16
(703 Views)

I am glad this is working for you. Good luck!

0 Kudos
Message 16 of 16
(684 Views)