0
$\begingroup$

I have to take the Fourier transform of quite a large 2D array (2^15 by 2^15, but I'll use 2^10 as an example here). My array is mostly zeros, and since Fourier can take sparse arrays, I can just initialize my array as a SparseArray and pass it through Fourier. The problem is that once I Fourier transform the array, it's no longer a sparse array and becomes much more memory-intensive:

arrayIndices = DeleteDuplicates@RandomInteger[{1, 2^10}, {100, 2}]; sparse = SparseArray[# -> 1 & /@ arrayIndices, {2^10, 2^10}]; fft = Fourier[sparse]; ByteCount /@ {sparse, fft} 

{21400, 16777376}

I feel that there should be a work-around because I don't actually need a Fourier transform of the same resolution as my original data. So, what I would like to do is feed in an input sparse array of size 2^10 by 2^10 and get out a more course-grained Fourier transform, say of size 2^8 by 2^8.

I know that Fourier allows you to specify which entries of the discrete Fourier transform that you want to extract, but this amounts to computing the full FFT and then throwing away some of the data. What I would like is to get a coarse-grained discrete Fourier transform in one shot so that I avoid making the computation unnecessarily memory intensive.

$\endgroup$
8
  • 1
    $\begingroup$If you lose sparsity through Fourier transform, then you should reconsider whether you want to Fourier transform at all. Typically, Fourier transform is a means to get to the right storage format, be it either sparse (extract the most important frequenceies) or more cost-efficient for all sorts of operations. But sparse matrices are already a good format for your data and many operations on sparse matrices are fast.$\endgroup$CommentedApr 6, 2024 at 15:14
  • $\begingroup$When I look at you matrix sparse I observe that most rows and most columns are entirely equal to 0. Is that really representative of your use case?$\endgroup$CommentedApr 6, 2024 at 15:17
  • $\begingroup$Did you potentially try ArrayResample ? It is difficult to understand if your spatial sampling rate is too high or if there are other issues (like too many zeroes that Henrik mentioned) unless there is a bit more on the physics of the problem$\endgroup$
    – gpap
    CommentedApr 6, 2024 at 15:21
  • $\begingroup$Maybe I should give more context: the reason I need to Fourier transform is because I'm generating a diffraction pattern from a point distribution. The reason the array is sparse is because I'm treating each point in the distribution as a delta function, and if my 2D array is thought of as an image, then each point would take up a single pixel. So essentially, the higher the resolution of the image, the sparser the 2D array. But I don't actually need a Fourier transform of extremely high resolution, I'm just trying to limit convolution effects and side lobes, etc.$\endgroup$
    – az123p
    CommentedApr 6, 2024 at 16:19
  • 1
    $\begingroup$Okay, I'll try that. Thanks for the help.$\endgroup$
    – az123p
    CommentedApr 7, 2024 at 16:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.