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

myconv(z,h)
%MYCONV is a fft accelerated correspondence to
%   ZC = CONV(Z,H)
%
%   Z is a Ny x Nx matrix and H is Ny x Nh matrix
%   ZC is a Nx+Nh-1 matix
%   
%   See also CONV, CONV2, MYCONV2
%
%   Here follows an examplification of usage:
%   
%   clear all;
%   
%   %  Create a "measurement" domain
%   Lx = 1e-3;
%   Nx = 2^15;
%   x  = Lx*(0:Nx-1)/Nx;
%   dx = x(2)-x(1);
%   
%   % "Sample" the (periodic) signal
%   z = cos(2*pi*2*x/Lx)+...
%        0.5*cos(2*pi*5*(x-0.14*Lx)/Lx)+...
%        0.25*cos(2*pi*20*(x-0.3*Lx)/Lx)+...
%        0.25*cos(2*pi*30*(x-0.7*Lx)/Lx);
% 
%   Nz = length(z);
%   
%   % Filter weighting function
%   lcx = Lx/5; % Cut-off acc to ISO 11562 Gaussian Profile Filter Lx/5
%   xf  = [x x(end)+dx]-Lx/2; % Symmetric and ensure that Nx+Nh-1 = 2^k
%   variancex = 1/(pi*sqrt(2/log(2)))*lcx; 
%   h = dx/(sqrt(2*pi)*variancex)*...
%        exp(-(((xf)/variancex).^2)/2);
%   Nh  = length(h);
% 
%   % Total length of the padded arrays needed for the fft operations
%   N  = Nz+Nh-1;
%   
%   % Apply the filter in the spatial domain using conv
%   tic;
%   zc = conv(z,h);
%   toc;
% 
%   % Apply the filter in the frequency domain
%   tic;
%   Z  = fft([z zeros(1,Nh-1)]);
%   H  = fft([h zeros(1,Nz-1)]);
%   zf = real(ifft(Z.*H));
%   toc;
% 
%   % Doing the same again but using the functional representation
%   tic;
%   zffunc = myconv(z,h);
%   toc;
% 
%   % Plotting the results
%   plot(...
%        1:N, zc    , 'k.' ,...Filtered - spatial domain
%        1:N, zf    , 'r--',...Filtered - freq. domain
%        1:N, zffunc, 'w:'  ...Filtered - freq. domain, func. repr.
%        );
%   Author(s): A. Almqvist
%   Copyright 2009- Andreas Almqvist
%   $Revision: 1$  $Date: 2009/11$
%   Homemade function
function zc = myconv(z,h)

[Ny,Nx] = size(z);

Nh = size(h,2);

zc = real(ifft(fft([z zeros(Ny,Nh-1)]').*fft([h zeros(Ny,Nx-1)]')))';

Contact us