Code covered by the BSD License  

Highlights from
N-dimensional Fourier interpolation

2.0

2.0 | 1 rating Rate this file 13 Downloads (last 30 days) File Size: 2.35 KB File ID: #22665
image thumbnail

N-dimensional Fourier interpolation

by Matthias Schabel

 

12 Jan 2009 (Updated 15 Dec 2010)

Performs N-D FFT interpolation with upsampling, downsampling, or mixed up- and downsampling

| Watch this File

File Information
Description

Performs N-D FFT interpolation on any data for which fftn works. Will upsample by zero-filling, downsample by truncating high frequencies, or combine both up- and downsampling by dimension to allow arbitrary reshaping.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
13 Jan 2009 Matthias Schabel

This code is needed as well (append on to end of fftInterpolate.m file):

function subData = subRange(data,rng)

if (isempty(rng))
    subData = data;
    return;
end;

sz = size(data);
dim = length(sz);

lo = rng(:,1)';
hi = rng(:,2)';

if (length(lo) ~= dim || length(hi) ~= dim)
    error('subRange :: dimension mismatch');
end;

% replace zeros with lower/upper limit
for i=1:dim
    if (lo(i) == 0) lo(i) = 1; end;
    if (hi(i) == 0) hi(i) = sz(i); end;
end;

if (any(lo<1) | any(hi > sz))
    error('subRange :: sub-range out of bounds');
end;

switch (dim)
    case 1, subData = data(lo(1):hi(1));
    case 2, subData = data(lo(1):hi(1),...
                    lo(2):hi(2));
    case 3, subData = data(lo(1):hi(1),...
                    lo(2):hi(2),...
                    lo(3):hi(3));
    case 4, subData = data(lo(1):hi(1),...
                    lo(2):hi(2),...
                    lo(3):hi(3),...
                    lo(4):hi(4));
    case 5, subData = data(lo(1):hi(1),...
                    lo(2):hi(2),...[]
                    lo(3):hi(3),...
                    lo(4):hi(4),...
                    lo(5):hi(5));
    otherwise,
            % generate string and use eval
            str = 'subData = data(';
            for i=1:dim
                str = [str 'lo(' num2str(i) '):hi(' num2str(i) ')'];
                if (i~=dim)
                    str = [str ','];
                else
                    str = [str ');'];
                end;
            end;
            eval(str);
end;
        
return;

24 Apr 2009 Benjamin

Matthias, I cannot get this to work. The example image posted seems to interpolate the peaks dataset by a factor of two. But when I run the following code, I don't get the same result:
>>> figure; subplot(1,2,1); imagesc(peaks);
>>> subplot(1,2,2); imagesc(fftInterpolate(peaks,2));
what's going on?

04 Mar 2010 Matthias

code works excellent for data with even dimensions. In case of odd dimensions the code fails.

21 Jul 2010 Matthias

Dear author

please find
rng = [ceil(newsz/2)-ceil(sz/2)+1;ceil(newsz/2)-ceil(sz/2)+sz]';

and replace it with
rng = [ceil(newsz/2)-floor(sz/2)+1;ceil(newsz/2)-floor(sz/2)+sz]';

then the code also works with odd dimesions.

Matthias Wurm

28 Aug 2011 Kevin Sharp

This fails with ...

??? Undefined function or method 'odd' for input arguments of type 'double'.

Error in ==> fftInterpolate at 61
centeru = floor(newsz/2)+1+odd(newsz);

Please login to add a comment or rating.
Updates
10 Dec 2010

fixed so it works correctly with odd sizes and mixed sizes, substantially simplified code

13 Dec 2010

Fixed bug that caused problems with odd dimensions and simplified code

15 Dec 2010

Bug fixes and improved efficiency

Tag Activity for this File
Tag Applied By Date/Time
nd fft Cristina McIntire 13 Jan 2009 15:51:04
interpolation Cristina McIntire 13 Jan 2009 15:51:09
image processing Matthias Schabel 13 Jan 2009 15:51:14
image processing Philipp H 04 Jul 2009 06:34:02

Contact us at files@mathworks.com