How to design and implement a low-pass AR1 filter in Matlab?

I have a data series

y(n)


that I want to filter using a low-pass AR1 filter. I found that this filter has a transfer function

H=1/(1+s/omega_c)


with omega_c the cut-off frequency. [Error: this is not a discrete time filter.]

If I implement this in Matlab:

filter(1,[1 1/(2*pi*500)],y)


it does not give a correct result. Is there an error in my reasoning?

• How did you go about discretising your transfer function to produce those coefficients? – Speedy Oct 24 '16 at 17:13
• @Speedy You mean that H(s) is in continuous time and I have to discretize it in order to be able to use it with a discrete time data series y(n)? – Karlo Oct 25 '16 at 15:23
• Exactly - I ask because you've presented your problem and attempted solution but not the reasoning you used to get there. – Speedy Oct 25 '16 at 17:04
• @Karlo Your H is written for continuous-time. Does it mean you want to design an analog filter? Isn't your data discrete? – msm Oct 26 '16 at 3:32
• @Karlo OK, I will give an answer shortly. – msm Oct 26 '16 at 19:45

An autoregressive filter is referred to as IIR (infinite impulse response) filter in signal processing. You have several options to do that. In Matlab, one way is to use commands like

[b,a] = butter(n,wn);             % Butterworth
[b,a] = cheby1(n,Rp,ws);          % Chebyshev Type I
[b,a] = cheby2(n,Rs,ws);          % Chebyshev Type II
[b,a] = ellip(n,Rp,Rs,ws);        % elliptic


where wn is the normalized cutoff, ws is normalized edge frequency, and Rp and Rs are the ripples of passband and stopband in dB (for more details see the documentation). Then use filter with the designed a and b.

If you want to design it yourself, your current analog filter can be a good starting point. You can use bilinear transformation to build your digital filter from an analog transfer function. Let's say your sampling period is $T$ (assume $T=1$ if it is just a series). Using this transform you should substitute $$s=\frac{2}{T}\frac{1-z^{-1}}{1+z^{-1}}\tag{1}$$ in the analog $H(s)$, to find the digital filter. One can show that the relationship between the cutoff frequency of the analog filter ($\omega_a$) and that of the digital filter ($\omega_d$) is $$\omega_a=\frac{2}{T}\tan\frac{\omega_d T}{2}\tag{2}$$ So if your desired digital filter's cutoff is $\omega_d (=2\pi f_d)$, then find the equivalent analog cutoff from $(2)$, and then your digital filter is just $H(s)$ with the given $s$ in $(1)$.

If you are strictly looking for a first order digital AR filter of the form $$H(z)=\frac{1-a}{1-az^{-1}}$$ then $$H(j\omega)=\frac{1-a}{1-ae^{-j\omega}}$$ and

$$|H(j\omega)|=\frac{1-a}{|1-ae^{-j\omega}|}=\frac{1-a}{|1-a\cos(\omega)+ja\sin(\omega)|}=\frac{1-a}{\sqrt{1-2a\cos(\omega)+a^2}}$$ With that, you can find $a$ with respect to the cutoff frequency.