[TESTED] Updated to work with floating point numbers (for fractional frequency)