function  y = conv_delay(x, h, d)
   // Convolution with a delayed impulse response
   //
   // Usage:
   //       y = conv_delay(x, h, d)
   // where
   //       x: Input signal vector
   //       h: Finite impulse response
   //       d: Delay (positive or negative) to apply to
   //          impulse response, in samples
   //       y: Output signal vector
   //
   // NOTE: A positive delay means the impulse response 
   //       is delayed respect to the impulse. A negative
   //       delay means it is anticipated, which implies
   //       a non-causal response
   //
   // -------------------------------
   // Author: Federico Miyara
   // Date:   2025-09-24
   
   rhs = argn(2);
   if rhs<3
      d = 0
   end
     
   if d>=0
      // For non-negative delay zero-pad h
      // to the left
      hh = [zeros(1,d), h];
      y = convol(hh, x);
   else
      // For negative delay (anticipation)
      // zero-pad x to the left
      xx = [zeros(1,abs(d)), x];
      y = convol(h, xx);
      // Remove non-causal response
      y = y(abs(d)+1:$) 
   end
   
endfunction
