05-26-2012 04:18 PM
Missed that.
Lynn
05-26-2012 04:50 PM - edited 05-26-2012 04:54 PM
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
05-30-2012 09:08 AM
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?
06-02-2012 06:32 PM - edited 06-02-2012 06:37 PM
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:
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.)
06-04-2012 08:12 PM
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!
06-05-2012 10:30 AM
I am glad this is working for you. Good luck!