04-13-2013 01:23 AM
Hello,
I am having trouble using the InvFFT2D and CxInvFFT2D functions in LabWindows/CVI.
My code looks something like this:
double a [nRows_a] [nCols_a];
double b [nRows_b] [nCols_b];
int m = (nRows_a + nRows_b) - 1;
int n = (nCols_a + nCols_b) - 1;
double fft_a [m] [n * 2];
double fft_b [m] [n * 2];
.... fill a and b with signal data ....
FFT2D(a, nRows, nColumns, m, n, 0, fft_a);
FFT2D(b, nRows, nColumns, m, n, 0, fft_b);
Now fft_a and fft_b contain real and imaginary parts on alternating array indices, per LabWindows/CVI's method of storing the complex numbers that result from FFT2D. The next thing I do is multiply the corresponding elements of fft_a and fft_b, and store the results in a new matrix fft_ab. The new matrix fft_ab has the same dimensions as fft_a and fft_b, and still maintains the alternating real and imaginary parts:
double fft_ab [m] [n * 2];
.... use for loop to multiply elements of fft_a and fft_b, store in fft_ab ...
Now I want to do the following:
double inv_fft [m] [n];
InvFFT2D (fft_ab, m, n * 2, 0, inv_fft);
But this is not working. I expect inv_fft to only contain real numbers, so I expect it will be half the size of fft_ab. The above code does not work, however. I keep getting an error telling me that fft_ab is not sized correctly.
Please help me resolve.. thanks.
Solved! Go to Solution.
04-15-2013 05:24 PM
Hey davidqk,
I see that the help for the fft functions are unclear to say the least. However, one thing you might consider is to increase the size of the allocated arrays. In my tests making the fft_ab and inv_fft have a large number of indices did not affect my outcome from what I expected.
double a [100] [100];
double fft_a [500] [500];
double b[500][500];
SinePattern (100, 1.0, 0.0, 1, a[0]);
SinePattern(100, 1.0, 0.0, 1, a[99]);
FFT2D (a, 100, 100, 199, 199*2, 0, fft_a);
InvFFT2D (fft_a, 199, 199*2, 0, b);
for(i = 0; i < 199; i++){
PlotY (panel, PANEL_GRAPH, b[i], 500, VAL_DOUBLE, VAL_THIN_LINE,
VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
}
04-16-2013 03:30 PM
Thanks.
You are right. Basically the second dimension of the input array into CxInvFFT2D needs to be twice as big as the output array, since the output will only contain real numbers.
The help file for CxInvFFT2D is a little misleading. It states the following:
numberOfRows | ssize_t | The number of rows in frequencyDomainSignal. |
numberOfColumns | ssize_t | The number of columns in frequencyDomainSignal. |
More clearly stated, it should should be the number of rows/columns excluding the imaginary columns. Not sure if the help file can be updated to be more clear.
And from what I can tell, there is no need to increase the size of the "numberOfRowsForFFT" and "numberOfColumnsForFFT" parameters in the FFT2D function.
If I re-write your code as follows it works fine:
double a [100] [100];
double fft_a [100] [200];
double b[100][100];
SinePattern (100, 1.0, 0.0, 1, a[0]);
SinePattern(100, 1.0, 0.0, 1, a[99]);
FFT2D (a, 100, 100, 100, 100, 0, fft_a);
InvFFT2D (fft_a, 100, 100, 0, b);
for(i = 0; i < 100; i++){
PlotY (panel, PANEL_GRAPH, b[i], 500, VAL_DOUBLE, VAL_THIN_LINE,
VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
}