1

As a generalization of the following questions:

I would like to know how to handle the n dimensional general case both for Upsampling and Downsampling.
The above questions deals with 1D and 2D and I wonder how to handle the general nD case.
The answer should be practical, namely emphasize implementation considerations.

Eric Johnson
  • 324
  • 1
  • 3
  • 16

1 Answers1

1

The general $ n $ dimension case can be solved with the following loop:

for dimIdx in 1:ndims(tX)
    tXDft = fft(tX, dimIdx);
    tXDft = PadOrCrop(tXDft, dimIdx);
    tXDft = FixSlice(tXDft, dimIdx)
    tX    = ifft(tXDft, dimIdx);
end

The tricky parts are handling the cropping (Downsampling) or padding (Upsampling) for the $ n - 1 $ dimensions slice.

One way to solve it is to recursively work on smaller dimensions slices until we get to 1D / 2D slice which is solved in the questions you linked to.

Another way is to define a slice indexing.
Assume the array has indices of: (1:5, 1:10, 1:15, 1:20) then the the $ i $ -th slice in the $ d $ -th dimensions has the indices, for i = 4 and d = 2 (1:5, 4, 1:15, 1:20).

Those slices are the elements we can treat as scalars in the 1D case. Namely split them or add them in order to compensate for Upsampling / Downsampling.

So basically we do, 1D DFT, then we apply cropping / padding according to need at the dimension in work, then we extract the slices at the bin which needs to be fixed and add them / split them then Inverse DFT.

Royi
  • 19,608
  • 4
  • 197
  • 238