spm_interp.m 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function [x] = spm_interp(x,r)
  2. % 1 or 2-D array interpolation
  3. % FORMAT [x] = spm_interp(x,r)
  4. % x - array
  5. % r - interpolation rate
  6. %__________________________________________________________________________
  7. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  8. % Karl Friston
  9. % $Id: spm_interp.m 5219 2013-01-29 17:07:07Z spm $
  10. % interpolate
  11. %--------------------------------------------------------------------------
  12. [n,m] = size(x);
  13. if n > 1 && m > 1 % matrix
  14. X = zeros(r*n,m);
  15. for i = 1:m
  16. X(:,i) = interpolate(x(:,i),r);
  17. end
  18. x = zeros(r*n,r*m);
  19. for i = 1:r*n
  20. x(i,:) = interpolate(X(i,:),r)';
  21. end
  22. elseif n == 1 % row vector
  23. x = interpolate(x',r)';
  24. elseif m == 1 % column vector
  25. x = interpolate(x,r);
  26. end
  27. % Interpolate using DCT
  28. % -------------------------------------------------------------------------
  29. function [u] = interpolate(y,r)
  30. if r == 1
  31. u = y;
  32. else
  33. y = y(:);
  34. n = size(y,1);
  35. Dy = spm_dctmtx(r*n,n);
  36. Du = spm_dctmtx(n,n);
  37. Dy = Dy*sqrt(r);
  38. u = Dy*(Du'*y);
  39. end