def ir2tf(imp_resp, shape, dim=None, is_real=True):
 if (not dim):
  dim = imp_resp.ndim
 irpadded = np.zeros(shape)
 irpadded[tuple([slice(0, s) for s in imp_resp.shape])] = imp_resp
 for (axis, axis_size) in enumerate(imp_resp.shape):
  if (axis >= (imp_resp.ndim - dim)):
   irpadded = np.roll(irpadded, shift=(- int(np.floor((axis_size / 2)))), axis=axis)
 if is_real:
  return np.fft.rfftn(irpadded, axes=range((- dim), 0))
 else:
  return np.fft.fftn(irpadded, axes=range((- dim), 0))

def ir2tf ( imp_resp , shape , dim = None , is_real = True ) : if ( not dim ) : dim = imp_resp . ndim irpadded = np . zeros ( shape ) irpadded [ tuple ( [ slice ( 0 , s ) for s in imp_resp . shape ] ) ] = imp_resp for ( axis , axis_size ) in enumerate ( imp_resp . shape ) : if ( axis >= ( imp_resp . ndim - dim ) ) : irpadded = np . roll ( irpadded , shift = ( - int ( np . floor ( ( axis_size / 2 ) ) ) ) , axis = axis ) if is_real : return np . fft . rfftn ( irpadded , axes = range ( ( - dim ) , 0 ) ) else : return np . fft . fftn ( irpadded , axes = range ( ( - dim ) , 0 ) )
compute the transfer function of an impulse response .