Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R equivalent of MATLAB's filter function

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
like image 970
Amyunimus Avatar asked Jan 28 '12 20:01

Amyunimus


People also ask

What does Matlab filter function do?

Filters are data processing techniques that can smooth out high-frequency fluctuations in data or remove periodic trends of a specific frequency from data. In MATLAB®, the filter function filters a vector of data x according to the following difference equation, which describes a tapped delay-line filter.

What are B and A in filter function in Matlab?

na is the feedback filter order, and nb is the feedforward filter order. Due to normalization, assume a(1) = 1. You also can express the rational transfer function as the difference equation. a ( 1 ) y ( n ) = b ( 1 ) x ( n ) + b ( 2 ) x ( n − 1 ) + ... + b ( n b + 1 ) x ( n − n b ) − a ( 2 ) y ( n − 1 ) − ...

How do I create a low pass filter in Matlab?

Lowpass Filtering of Tonesfs = 1e3; t = 0:1/fs:1; x = [1 2]*sin(2*pi*[50 250]'. *t) + randn(size(t))/10; Lowpass-filter the signal to remove the high-frequency tone. Specify a passband frequency of 150 Hz.


2 Answers

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.

like image 83
Dr G Avatar answered Oct 08 '22 10:10

Dr G


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)
like image 40
Geek On Acid Avatar answered Oct 08 '22 10:10

Geek On Acid