Automatic calculation function for samples of 2^N size