# Recursive filter gain

I implemented a filter similar to the one below, within a FPGA. Two substractors and an accumulator.

The recursive equation is given by:

My inputs are exponentially decaying pulses of the form sampled every n

I want to express y[n] as a function of the pulse amplitude A (which I need to retrieve), and the constants , L, and K.

Any hints would be greatly appreciated

Edit:

I followed Andy Walls' advice and this is what I get

$$H(z) = \frac{(1-Z^{-K})(1-Z^{-L})}{1-Z^{-1}}$$ $$X(z) = \frac{A}{1-aZ^{-1}}$$ $$with: a = e^{\frac{-nT}{\tau}}$$ $$Y(z) = H(z).X(z) = \frac{A}{1-aZ^{-1}} . \frac{(1-Z^{-K})(1-Z^{-L})}{1-Z^{-1}}$$ Using partial fraction expansion I try to find B and C so that $$Y(z) = A.(\frac{B}{1-aZ^{-1}} + \frac{C}{1-Z^{-1}})$$ I get $$B = \frac{A.(1-a^{-K})(1-a^{-L})}{(1-a^{-1})}; C=0$$ So $$Y(z) = \frac{A.(1-a^{-K})(1-a^{-L})}{(1-a^{-1})(1-aZ^{-1})}$$

I don't know if I am right at this point, but this is where I get stuck. This filter is trapezoidal, but because the input is an exponential decay, I would expect at least 2 exponential terms corresponding to the trapeze rise and fall times.

Am I on the right path?

Take the Z Transform of your difference equation and perform algebraic manipulations to find $$H(z)=\dfrac{Y(z)}{X(z)}$$ as a rational function of $$z$$.

Take the Z Transform of your input $$x(nT) = x[n]$$ to find $$X(z)$$.

Multiply to get $$H(z)X(z) = Y(z)$$.

Find the inverse Z Transform of $$Y(z)$$ to find $$y[n]$$. (This will be the difficult part, as you may need to use partial fraction expansion and other mathematical techniques so you can look up inverse transform in a table.)

These tables will help: http://lpsa.swarthmore.edu/LaplaceZTable/LaplaceZFuncTable.html

Update in response to comment

Here's what I get.

Finding the transfer function:

$$\mathcal{Z}\left\{y[n]\right\} = \mathcal{Z}\left\{y[n-1] + x[n] -x[n-K]-x[n-L]+x[n-K-L]\right\}$$

$$Y(z) = Y(z)z^{-1} + X(z) - X(z)z^{-K} -X(z)z^{-L} + X(z)z^{-K-L}$$

\begin{align*}H(z) = \dfrac{Y(z)}{X(z)} &= \dfrac{1-z^{-K}-z^{-L}+z^{-K-L}}{1-z^{-1}}\\ \\ &= \dfrac{\left(1-z^{-K}\right)\left(1-z^{-L}\right)}{1-z^{-1}}\\ \\ &= \left(1 + z^{-1} + \dots + z^{-K+1}\right)\left(1-z^{-L}\right)\\ \\ &= 1 + z^{-1} + \dots + z^{-K+1} -z^{-L}-z^{-L-1}- \dots -z^{-K-L+1}\\ \\ \end{align*}

Transforming the input:

$$X(z) = \mathcal{Z}\left\{x(nT)\right\} = \mathcal{Z}\left\{Ae^{-\frac{nT}{\tau}}u[n]\right\} = A\dfrac{z}{z-e^{-\frac{T}{\tau}}}= A\dfrac{1}{1-e^{-\frac{T}{\tau}}z^{-1}}$$

Filtering in the Z domain: \begin{align*}Y(z) &= H(z)X(z)\\ \\ &=\dfrac{1-z^{-K}-z^{-L}+z^{-K-L}}{1-z^{-1}} \cdot A\dfrac{1}{1-e^{-\frac{T}{\tau}}z^{-1}}\\ \\ &=A\left[\dfrac{1-z^{-K}-z^{-L}+z^{-K-L}}{\left(1-z^{-1}\right)\left(1-e^{-\frac{T}{\tau}}z^{-1}\right)}\right]\\ \\ &=A\left[\dfrac{C}{1-z^{-1}}+\dfrac{B}{1-e^{-\frac{T}{\tau}}z^{-1}}\right]\\ \\ \end{align*}

Performing partial fraction expansion:

\begin{align*}1-z^{-K}-z^{-L}+z^{-K-L} &= C\left(1-e^{-\frac{T}{\tau}}z^{-1}\right) + B\left(1-z^{-1}\right)\\ \\ \left(1 + z^{-1} + \dots + z^{-K+1}\right)\left(1-z^{-L}\right)\left(1-z^{-1}\right)&=C\left(1-e^{-\frac{T}{\tau}}z^{-1}\right) + B\left(1-z^{-1}\right)\\ \end{align*}

so \begin{align*}C &= 0 \\ \\ B &= 1 + z^{-1} + \dots + z^{-K+1} -z^{-L}-z^{-L-1}- \dots -z^{-K-L+1}\\ \end{align*}

Continuing filtering in the Z domain: \begin{align*}Y(z) &=A\dfrac{1 + z^{-1} + \dots + z^{-K+1} -z^{-L}-z^{-L-1}- \dots -z^{-K-L+1}}{1-e^{-\frac{T}{\tau}}z^{-1}}\\ \\ \end{align*}

Since there is no information on the values of $$K$$ and $$L$$, there is not really any more simplification we can do in the Z domain.

Taking the inverse Z-Tranform:

\begin{align*}y[n] &= A\left[e^{-\frac{nT}{\tau}}u[n]+e^{-\frac{(n-1)T}{\tau}}u[n-1]+\dots+e^{-\frac{(n-K+1)T}{\tau}}u[n-K+1]-e^{-\frac{(n-L)T}{\tau}}u[n-L]-e^{-\frac{(n-L-1)T}{\tau}}u[n-L-1]-\dots-e^{-\frac{(n-K-L+1)T}{\tau}}u[n-K-L+1] \right]\\ \\ &= A \sum_{k = 0}^{K-1} e^{-\frac{(n-k)T}{\tau}}u[n-k] - e^{-\frac{(n-k-L)T}{\tau}}u[n-k-L]\\ \\ \end{align*}

• Thank you for your answer. I tried to follow your advices and I edited my post. I get stuck when i have to rearrange my equation and apply inverse Z transform. Could you please take a look at it? Nov 11 '18 at 8:04
• @Dams0622 I edited my answer. Nov 12 '18 at 21:04
• I took some time applying this formula to a concrete example and it worked perfectly. (I did it with excel and it can be downloaded here. I really appreciate your help, thank you a lot! Nov 13 '18 at 13:24
• You're welcome. I edited the final result a l little more, to pull out the constant terms, to make computation easier. Nov 13 '18 at 17:36
• @Dams0622 Oops, I forgot the unit step functions because of the implied positive time sequence on input. Answer has been revised. Nov 14 '18 at 13:27