Fix FFT algorithm, and add sample rate selection logic