Apply line-broadening to a time-series

    Parameters
    ----------
    ts : a nitime.TimeSeries class instance

    width : float
        The exponential decay time-constant (in seconds)

    Returns
    -------
    A nitime.TimeSeries class instance with windowed data

    Notes
    -----

    For details, see page 92 of Keeler2005_.

    .. [Keeler2005] Keeler, J (2005). Understanding NMR spectroscopy, second
       edition. Wiley (West Sussex, UK).

def line_broadening(ts, width):
    """
    Apply line-broadening to a time-series

    Parameters
    ----------
    ts : a nitime.TimeSeries class instance

    width : float
        The exponential decay time-constant (in seconds)

    Returns
    -------
    A nitime.TimeSeries class instance with windowed data

    Notes
    -----

    For details, see page 92 of Keeler2005_.

    .. [Keeler2005] Keeler, J (2005). Understanding NMR spectroscopy, second
       edition. Wiley (West Sussex, UK).

    """ 
    # We'll need to broadcast into this many dims:
    n_dims = len(ts.shape)
    # We use the information in the TimeSeries.time attribute to get it:
    win = np.exp(- width * ts.time/np.float(ts.time._conversion_factor))
    
    new_data = ts.data * win
    return nts.TimeSeries(new_data, sampling_rate=ts.sampling_rate)