function M = mfft( X, unit_cell_size )
%MFFT Perform a fourier transform for systems with a finite unit cell size
%
%Transforms a vector / the columns of a matrix (like fft does), but uses
%the same transformation for unit_cell_size consecutive elements. For
%example, if unit_cell_size is 2, then two elements at a time will be
%transformed with the same element.
    M=[];
    for v=X     %for each column of X (trivial if X is a single vector)
        %Split v in a matrix with unit_cell_size columns  (e.g. two)
        % v1 v2
        % v3 v4
        % v5 v5
        % ...
        a=reshape(v,unit_cell_size,[]).';
        a=fft(a).'; %Fourier transform the columns
                    %Merge the columns of 'a' to a vector
                    % (a11;a12;a21;a22;..) and append it
                    % to M
        M=[M,a(:)];    
    end
end

