04-08-2015 08:51 PM - edited 04-08-2015 09:08 PM
Hi Everyone,
Disclaimer: I am a physicist, not a programmer, please try not to cringe at my code....
I am trying to carry out some functions in Fourier space for very large arrays.
The way I have done this is to first use the LabVIEW FFT function, then iterate over each frequency component using two for loops, using Mathscript to do the calculations I need within these loops. The index of each loop is critical to my calculations (as it represents the spatial frequency component).
It works, however it is very slow (since I need to loop this entire process several thousand times for different data). I have read on the forums that using Mathscript within a for loop is not ideal, that it is better to use arrays in the Mathscript window. However, I am not familiar with this, and can see problems since I currently work with the indices of each loop.
I have attached the appropriate segment of my code (as an image, since I had trouble uploading the actual code). The calculations in the Mathscript window are critical, while the other math window is simply to set kx, ky = 0 in the middle of the array rather than at the corner, while avoiding dividing by zero. The "true" case for k>kmax is not shown, it simply outputs 0+0i to all three tunnels.
Thanks to anyone who can help!
Steve
P.S. for anyone interested, what I am doing is calculating the current and magnetisation at each point in a two-dimensional superconductor by measuring the magnetic field at each point in a film above it.
04-09-2015 01:34 AM
Hi bob,
It works, however it is very slow
Yes, especially as you use a formula node AND a mathscript node…
Do all calculations in pure G! Employ polymorphism: LabVIEW can do most of the calculations on arrays as it does on scalars!
04-09-2015 02:09 AM - edited 04-09-2015 02:10 AM
Can you attach the actual code instead of a picture? Also include some typical default data.
You are just doing plain calculations, calling the mathscript node one point at a time in the innermost loop.
How big are the 2D arrays?
I agree with Gerd. It looks to me that rewriting this all in plain LabVIEW would be quite trivial and it will be much faster.
One minor point: The control for "kmax" belongs outside the loops. There is no need to re-read the control with every interation of the innermost loop. The code only make sense if kmax is constant for the duration of the loops.
04-09-2015 11:41 PM
I tried to attach the code in my first message but kept getting this error:
"Correct the highlighted errors and try again.
I've tried renaming, saving the file for a previous version, even copying and pasting the code into a new VI..... what should I do so it uploads properly?
04-09-2015 11:55 PM
Try a different browser or zip the files up before attaching.
04-10-2015
01:43 AM
- last edited on
04-15-2025
12:24 PM
by
Content Cleaner
I do not know the size of your arrays, but you can get sometimes pretty nice speed improvement, if you do the different FFT calculations using a video card. Few years ago I had to do FFT operations on large data sets (gigabytes of single floats, magnetic Barkhausen-noise data), and I managed to get nice speed using CUDA language and doing FFT in parallel way on the multicore videocard.
LabVIEW has also a toolkit, so you may have a look:
04-10-2015 02:31 AM
Ok, I am attaching the actual code now.
I have included an array of typical data as a defualt value for "field values".
I also moved kmax outside of the loops, but was less confident about making any of the other suggested changes...