# Difference between order and length of a filter

Let, the channel be modeled as a FIR model with order L. Mathematically, $y_n = \sum_{k=1}^L h_k u_{n-k} \tag{1}$ where $u$ is the data input to the channel and h is the channel coefficient. In statistics, the model y is known as the Moving Average process with order L. In signal processing, L is known as the length. Consider an example where there are 3 coefficients viz. $h_1,h_2,h_3$

Confusion 1: My confusion is, what is the order for this example? There are 3 coefficients so the order should be 3. I am confused between these terms - order, length and delays.

Confusion 2: Can somebody please clarify what is the order for this example? Please correct me where I have made any mistakes.

In Matlab I have implemented the equation(1) as follows:

N = 1000;
u = rand(1,N);
for n = 3 : N
y(n) = h(1)*u(n) + h(2)*u(n-1) + h(3)*u(n-2);
end


In your example order is $2$ and length is $3$.
Its has more to do with convention. Consider a polynomial in $x$: $$a_n x^n + a_{n-1} x^{n-1} + ... a_0 x^0$$ The order of this polynomial is $n$, whereas, number of coefficients is $n+1$. In your case an FIR filter of order $L$, is a polynomial you write as: $$h_L \delta(n-L) + h_{L-1} \delta(n-L+1) + ... h_0 \delta(n)$$ The $z$-transform of which is: $$h_L z^{-L} + h_{L-1} z^{-L+1} + ...+ h_1 z^{-1} + h_0 z^{0}$$ Note this transform, which you might not have studied yet, just places the shift in $\delta(n)$ on power of $z$, e.g., $z^{0}$ and $\delta(n)$ correspond to no-delay, just scaling the input signal. $z^{-1}$ and $\delta(n-1)$ correspond to order $1$ and one delay.
I think real confusion comes from MATLAB, as it does not allow $0$ as first index value. You cannot write x(0) in MATLAB. The first index is $1$. Therefore, we have to start from x(1).