I have an input sequence $x(n)$ and impulse sequence
\begin{equation} h(n) = \begin{cases} 0 & \quad \text{when } n = 0 \\ .239052 & \quad \text{when } n = 1 \\1.3357\exp(-0.650286n) & \quad \text{when } n > 1\\ \end{cases} \end{equation}
I did a convolution and obtained $y(n)=x(n)*h(n)$. I trimmed some of the data in the end from $y(n)$ and then I flipped $h(n)$ and I did reverse filtering $w(n)=y(n)*h(-n)$.
When I researched about this I found filtfilt
in matlab is an easier option but I am trying to implement this in C.
So my question is without trimming the first output sequence $y(n)$ I am getting a drifted version of the result (there is a delay).
Is it trimming really necessary or am I doing something wrong here.
One more question is I can see some transients both at the start and end of $w(n)$ sequence when I use filtfilt
I don't see that transients.The reason is matlab is using some initial states based on the below paper to get rid of the transients.
Gustafsson, F. "Determining the initial states in forward-backward filtering." IEEE® Transactions on Signal Processing. Vol. 44, April 1996, pp. 988–992.
To summarize :
- Is it trimming really necessary ? PS the figure attached without trimming the the resultant data has a lag..Trimming the $y(n)$ sequence before backward filtering aligns the result.
- how to determine the initial states for getting rid of transients.