Code covered by the BSD License  

Highlights from
FFT accelerated surface analysis tools package

image thumbnail
from FFT accelerated surface analysis tools package by Andreas Almqvist
FFT accelerated functions for analysing 1D and 2D signals such surface profiles, surfaces and images

myffttrunc2(s,n,m)
function S = myffttrunc2(s,n,m)
%MYFFTTRUNC(s,n) returns the low-pass filtered content of the signal s
%
%   s    = s(x,y) where
%   x(j) = x(1)+(j-1)*(x(N)-x(1)+x(2)-x(1))/N,   i = 1...N, N = 2^k1
%   y(i) = y(1)+(i-1)*(y(N)-y(1)+y(2)-y(1))/M,   i = 1...M, M = 2^k2
%
%   S is the low-passtruncated signal S = W*s, where W is the Fourier 
%   transfer function
%
%   See also myffttrunc

%   Author(s): A. Almqvist
%   Copyright 2009- Andreas Almqvist
%   $Revision: 1$  $Date: 2009/11$
%   Homemade function

[M,N]   = size(s);

% Creating the transfer function W
wx  = (1:N/2-1);
wy  = (1:M/2-1);

[Wx,Wy] = meshgrid(wx,wy);
                                    % wy          N/2+1
W1  = 1.*(Wx<=n & Wy<=m);           % |           |
W2  = fliplr(W1);                   % |   W3      |    W4
W3  = flipud(W1);                   % |_ _ _ _ _ _|_ _ _ _ _ _ M/2+1
W4  = flipud(W2);                   % |           |
                                    % |   W1      |    W2
W   = zeros(M,N);                   % |___________|______________wx 
W(M/2+2:M   ,2:N/2  )   = W3;       %
W(M/2+2:M   ,N/2+2:N)   = W4;       %
W(2:M/2     ,2:N/2  )   = W1;       % W = [W1,W2;W3,W4]
W(2:M/2     ,N/2+2:N)   = W2;       %

W(1                             ,[1:min(n,N),max(end-n-1,1):N]  )   = 1;
W([1:min(m,M),max(end-m-1,1):M] ,1                              )   = 1;
W(M/2+1                         ,[1:min(n,N),max(end-n-1,1):N]  )   = 1;
W([1:min(m,M),max(end-m-1,1):M] ,N/2+1                          )   = 1;

% Truncating the signal in the frequency space and return it to the time
% domain
S   = real(ifft2(W.*fft2(s)));

Contact us at files@mathworks.com