R equivalent of MATLAB's filter function

2019-04-09 04:43发布

I'm adapting MATLAB code to R and trying to generate a waveform using ARMA formula. Is there a simple R equivalent function for MATLAB's filter to take AR/MA coefficients to build a waveform?

npts = 100;
a = [1 0.6]; % AR coeffs
b = [1 0.25 3]; % MA coeffs
e = randn(npts,1); % generate gaussian white noise
waveform = filter(b,a,e); % generate waveform

2条回答
smile是对你的礼貌
2楼-- · 2019-04-09 05:33

Hmm can't you achieve that with filter function in the package signal ?

require(signal)
a = c(1,0.6)
b = c(1,0.25,3)
e = rnorm(100)
waveform = filter(b,a,e)
查看更多
Viruses.
3楼-- · 2019-04-09 05:33

Yeah, you can do this usring arima.sim, e.g.

arima.sim(npts, model=list(ar=a, ma=b), rand.gen=rnorm)

Note that the model is checked for stationarity and the model you have above is not stationary. If you want something integrated you can specify the order of integration in the model.

查看更多
登录 后发表回答