#NEWLINE# def fir( timeseries , design ) : #NEWLINE# #INDENT# '\n    Calculate the FIR (finite impulse response) HRF, according to [Burock2000]_\n\n    Parameters\n    ----------\n\n    timeseries : float array\n            timeseries data\n\n    design : int array\n          This is a design matrix.  It has to have shape = (number\n          of TRS, number of conditions * length of HRF)\n\n          The form of the matrix is:\n\n              A B C ...\n\n          where A is a (number of TRs) x (length of HRF) matrix with a unity\n          matrix placed with its top left corner placed in each TR in which\n          event of type A occured in the design. B is the equivalent for\n          events of type B, etc.\n\n    Returns\n    -------\n\n    HRF: float array\n        HRF is a numpy array of 1X(length of HRF * number of conditions)\n        with the HRFs for the different conditions concatenated. This is an\n        estimate of the linear filters between the time-series and the events\n        described in design.\n\n    Notes\n    -----\n\n    Implements equation 4 in Burock(2000):\n\n    .. math::\n\n        \\hat{h} = (X^T X)^{-1} X^T y\n\n    M.A. Burock and A.M.Dale (2000). Estimation and Detection of Event-Related\n    fMRI Signals with Temporally Correlated Noise: A Statistically Efficient\n    and Unbiased Approach. Human Brain Mapping, 11:249-260\n\n    ' #NEWLINE# X = np . matrix ( design ) #NEWLINE# y = np . matrix ( timeseries ) #NEWLINE# h = np . array ( ( ( linalg . pinv ( ( X . T * X ) ) * X . T ) * y . T ) ) #NEWLINE# return h