Modified fourier/fourierf to be much more robust