From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fourier space operations - keep getting NaNs

Solved!
Go to solution

Hi

 

I have created a program that takes the Fourier transform of an array (taken from an image if that makes any difference), uses a couple of for loops to isolate each element of the Fourier transormed array, then applies the following in a mathscript window:

 

ky=height/2-y
kx=x-width/2

k=sqrt(kx^2+ky^2)
Jx=B*ky*(a bunch of constants)
Jy=-Jx*kx/ky

 

Where B is my original array, kx and ky are the frequency components. Then it does an inverse fourier transform on the result arrays Jx and Jy.

 

Essentially, I'm doing element by element maths in Fourier space, where the operations depend on the frequency represented by each element.

 

The problem is: I keep getting an array of NaNs after the final inverse Fourier. Any ideas?

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

Hi MOI maker,

 

None of the operations you describe in your post are glaring potential sources of the unexpected behavior you are seeing. Could you please attach your code so we can take a deeper look to see why you might be getting only NaN as the output?

 

Thanks!

Matt
NI Community Team
National Instruments
0 Kudos
Message 2 of 8
(2,464 Views)

Hmmmm.....

 

I tried isolating the code for the Fourier operations from the rest of my VI, and I see that it works fine by itself. I guess something else is causing my NaNs.

Really stumped now... I'll attach both the full VI and the Fourier part.

 

 

Download All
0 Kudos
Message 3 of 8
(2,463 Views)

Hi,

 

I ran both the test and the original VI and did not receive NaN ouputs with either. However, I did not use the 'Quantify' step as I did not have any of the necessary calibration data. If you run your VI skipping the 'Quantify' step, do you still see NaNs as outputs? What if you include the quantify step in your test VI? It seems like the problem may be isolated to that portion of the VI.

Matt
NI Community Team
National Instruments
0 Kudos
Message 4 of 8
(2,421 Views)

Hi Matt,

 

I added the "skip" option specifically to avoid the quantification step in case that was causing the NaNs. For me it happens whether I quantify the image or not.

 

I have found that for some very specific images, Jx is not NaN and actually gives good values, but for any image, Jy is always NaNs.

 

It's very strange that it worked for you.... maybe I'll try running the VI on another computer, since that's the only difference I can conceive.

 

Thanks,

Steve

0 Kudos
Message 5 of 8
(2,418 Views)
Solution
Accepted by topic author MOI_maker

Steve,

 

I do not have the IMAQ or the Mathscript stuff so I cannot run your VIs but I think I see something you may want to check.

 

Jy = -Jx*kx/ky;

ky = height/2 - y;

height = N

y is wired to the iteration counter "i" which ranges from zero to N-1 where N is the size of the array.  So if N is even, then there is a value of y for which ky = 0.  For ky = 0 Jy = Inf.

 

The inverse FFT produces Inf also but I suspect that the divide by zero is your culprit.

 

Lynn

Message 6 of 8
(2,415 Views)

That's it! Thanks johnsold.

 

When my arrays have an odd number of columns they work fine, but an extra column and it's all NaNs. I just have to add a single row/column of zero-padding wherever necessary and (fingers crossed) it should work. - or rather, delete a single row/column from the edge, since zero-padding will introduce unwanted frequency components.

 

Steve

0 Kudos
Message 7 of 8
(2,410 Views)

I am glad you got that working.

 

It might be worth thinking about whether the algorithm you are using really does what you want.  When a computation has the possibilty to blow up for certain values of parameters which are within the normal range for the process, it is often a clue that something is not doing what you really want.  For most applications dropping or padding one column of pixels is probably insignificant, but can you epxlain it to a professor, boss, customer, or judge and jury?

 

Lynn

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