A General Method for Gradient Computation in Multirate Digital Systems