LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

3D FFTshift in labview

Hi 

 

I would like to perform the following matlab operation in labview for a 3D array:

 

r =fftshift(fftn((p)); 

 

where p is a 3D array.

 

I found the following code that allows me to perform a 3D fft: 

 

https://forums.ni.com/t5/Example-Code/3D-FFT-Fast-Fourier-Transform-in-LabVIEW/ta-p/3494833?profile....

 

so i can perform : r =fftn(p);  successfully in labview for a 3D array

 

but i am not sure how to modify the code to implement the 3D fftshift. I tried changing the code by enabling the fft shift in the initial 2D FFT and the column 1D FFT as shown in the attached photo but it did not work...

 

 

0 Kudos
Message 1 of 2
(1,918 Views)

Here's one implementation of LabVIEW code that imitates MATLAB's fftshift() function:

Spoiler
fftshift_in_LabVIEW_JoB.png
If you don't have LV2019, all that's hidden is rotating the rows (Case 1, the constants are wired to the middle inputs) and rotating the columns (Case 2, the constants are wired to the bottom inputs).
All constants used in the case structure have a value of 0.

No guarantee it's efficient (in fact, I suspect that for very large data sets, it will be quite inefficient). But it works.

(I'm curious what some of the more expert LabVIEW forum members could do with this code...)

 

You can compare it to the output in this MATLAB code:

Spoiler
% Creating the matrix that's default in the LabVIEW code
m = 4; % Number of Pages
n = 5; % Number of Rows
o = 6; % Number of Columns

for k = 1:m
    for j = 1:n
        for i = 1:o
            x(j,i,k) = i + (j-1)*o + (k-1)*n*o;
        end
    end
end

% Performing the fftshift()
fftshift(x)

In case you're interested, MATLAB just performs this by rotating the matrix about half-way in each dimension. LabVIEW has a "Rotate 1D Array" function that would more closely imitate the MATLAB code, but I struggled grabbing the correct 1D arrays to rotate in the page-direction. What I did here is functionally equivalent.

 

Hope this helps!

-joeorbob

 

 

0 Kudos
Message 2 of 2
(1,822 Views)