def freq_to_chan(frequency,bandwidth,n_chans):
  """
  Returns the channel number where a given frequency is to be found.

  @param frequency : frequency of channel in sane units as bandwidth.
  @type  frequency : float

  @param bandwidth : upper limit of spectrometer passband
  @type  bandwidth : float

  @param n_chans : number of channels in the spectrometer
  @type  n_chans : int

  @return: channel number (int)
  """
  if frequency < 0:
    frequency = bandwidth + frequency
  if frequency > bandwidth:
    raise RuntimeError("that frequency is too high.")
  return round(float(frequency)/bandwidth*n_chans) % n_chans