# -------------------------------------------------------------
#  Functions for acausal filtering
# -------------------------------------------------------------
import numpy as np

def boxcar_lowpass_filter(fc, df, nf):
    """
    Calculates samples of the boxcar lowpass filter transfer function (positive frequencies only)
    :param fc: corner frequency in Hz
    :param df: frequency stepping
    :param nf: number of frequencies
    """
    return np.where(df*np.arange(0, nf) > fc, 0, 1)


def boxcar_highpass_filter(fc, df, nf):
    """
    Calculates samples of the boxcar highpass filter transfer function (positive frequencies only)
    :param fc: corner frequency in Hz
    :param df: frequency stepping
    :param nf: number of frequencies
    """
    return np.where(df*np.arange(0, nf) < fc, 0, 1)


def hann_lowpass_filter(fc, df, nf):
    """
    Calculates samples of the Hann filter transfer function (positive frequencies only)
    :param fc: corner frequency in Hz
    :param df: frequency stepping
    :param nf: number of frequencies
    """
    f = df*np.arange(0, nf)
    return np.where(f < fc, np.cos(np.pi*f/fc)**2, 0)