# Filtering time series based on arima coefficients for prewhitening

I've been following this tutorial for pre-whitening time series in order to apply CCF.

In the example, the authors use an ARIMA(1,1,0) model, which is then defined as presenting the following polynomial expression:

$$(1 - (1 + \phi_1)B + \phi_1B^2)y_t$$

This translates into the following filter in R:

filter(y, filter=c(1,-(1+phi1),phi1), sides=1)

On the other hand, ARIMA models with only the AR component present the following polynomial representation:

$$1 - \sum_{j=1}^{p}{\phi_jB^j}$$

which implies a filter like this in R:

filter(y, filter=c(1, -arima_model\$coeffs), sides=1)

How would it be a filter for an ARIMA(2,1,0) and for series including the MA component?

Sorry if the question looks awkward, I'm trying to implement the pre-whitening in collections of rasters, which may have different AR, I, and MA values.

Regards