- #1
Gigasoft
- 59
- 0
I am trying to graph the frequency spectrum of a signal over time. To do this, for each frequency I use a filter defined by the following equation:
[tex]y_n = Ae^{i\omega_0}y_{n-1} + x_n[/tex]
This has a frequency response of [tex]\frac 1 {\sqrt{\left(1-A\right)^2+2A\left(1-cos\left(\omega-\omega_0\right)\right)}}[/tex], which peaks at [tex]\omega_0[/tex].
Now, for every m steps I want to find out how much [tex]x_n[/tex] contributed to [tex]|y_n|[/tex] during the last m steps. I define [tex]\widehat{y}_n=H\left[n\right]\left|y_n\right|[/tex], where n=0 is the first of the last m steps and H is the unit step function, and I let [tex]\widehat{x}[/tex] be the contribution of x to |y|, which I assume to be constant for the m samples under consideration. This gets me the equation [tex]\widehat{y}_n=A\widehat{y}_{n-1}+\delta\left[n\right]A\left|y_{-1}\right|+H\left[n\right]\widehat{x}[/tex].
The Z-transform of this equation is:
[tex]\left(1-Az^{-1}\right)\widehat{Y}\left(z\right)=A\left|y_{-1}\right|+\frac{\widehat{x}}{1-z^{-1}}[/tex]
In other words,
[tex]\widehat{Y}\left(z\right)=\frac{A\left|y_{-1}\right|\left(1-z^{-1}\right)+\widehat{x}}{\left(1-z^{-1}\right)\left(1-Az^{-1}\right)}[/tex]
This can be written as:
[tex]\widehat{Y}\left(z\right)=\frac C{1-z^{-1}}+\frac D{1-Az^{-1}}=\frac{C\left(1-Az^{-1}\right)+D\left(1+z^{-1}\right)}{\left(1-z^{-1}\right)\left(1-Az^{-1}\right)}[/tex]
From the two equations about, [tex]A\left|y_{-1}\right|+\widehat{x}-A\left|y_{-1}\right|z^{-1}=C+D-ACz^{-1}-Dz^{-1}[/tex] for all z, and we must have [tex]A\left|y_{-1}\right|+\widehat{x}=C+D[/tex] and [tex]Ay_{-1}=AC+D[/tex].
The inverse transform of [tex]\frac C{1-z^{-1}}+\frac D{1-Az^{-1}}[/tex] is [tex]H\left[n\right]\left(C+DA^n\right)[/tex]. So, we have [tex]C+DA^{m-1}=\widehat{y}_{m-1}[/tex].
This gives:
[tex]D=A\left|y_{-1}\right|-AC=\frac{\widehat{y}_{m-1}-C}{A^{m-1}}[/tex]
[tex]A\left|y_{-1}\right|-\frac{\widehat{y}_{m-1}}{A^{m-1}}=C\left(A-\frac 1{A^{m-1}}\right)[/tex]
[tex]\left|y_{-1}\right|-\widehat{y}A^{-m}=C\left(1-A^{-m}\right)[/tex]
[tex]C=\frac{\left|y_{-1}\right|-\widehat{y}_{m-1}A^{-m}}{1-A^{-m}}=\frac{\left|y_{-1}\right|A^m-\widehat{y}_{m-1}}{A^m-1}=\left|y_{-1}\right|+\frac{\widehat{y}_{m-1}-\left|y_{-1}\right|}{1-A^m}[/tex]
[tex]\widehat{x}=C+A\left|y_{-1}\right|-AC-A\left|y_{-1}\right|=\left(1-A\right)C=\left(1-A\right)\left(\left|y_{-1}\right|+\frac{\widehat{y}_{m-1}-\left|y_{-1}\right|}{1-A^m}\right)[/tex]
However, when I apply the last formula to the result of the first filter in my program, I don't get [tex]\widehat{x}[/tex]. If x is 0, then [tex]\widehat{x}[/tex] should be 0 as well, but it isn't. The formula looks correct. I have tried with a value of m as low as 2, but it still doesn't work. What could be the problem.
[tex]y_n = Ae^{i\omega_0}y_{n-1} + x_n[/tex]
This has a frequency response of [tex]\frac 1 {\sqrt{\left(1-A\right)^2+2A\left(1-cos\left(\omega-\omega_0\right)\right)}}[/tex], which peaks at [tex]\omega_0[/tex].
Now, for every m steps I want to find out how much [tex]x_n[/tex] contributed to [tex]|y_n|[/tex] during the last m steps. I define [tex]\widehat{y}_n=H\left[n\right]\left|y_n\right|[/tex], where n=0 is the first of the last m steps and H is the unit step function, and I let [tex]\widehat{x}[/tex] be the contribution of x to |y|, which I assume to be constant for the m samples under consideration. This gets me the equation [tex]\widehat{y}_n=A\widehat{y}_{n-1}+\delta\left[n\right]A\left|y_{-1}\right|+H\left[n\right]\widehat{x}[/tex].
The Z-transform of this equation is:
[tex]\left(1-Az^{-1}\right)\widehat{Y}\left(z\right)=A\left|y_{-1}\right|+\frac{\widehat{x}}{1-z^{-1}}[/tex]
In other words,
[tex]\widehat{Y}\left(z\right)=\frac{A\left|y_{-1}\right|\left(1-z^{-1}\right)+\widehat{x}}{\left(1-z^{-1}\right)\left(1-Az^{-1}\right)}[/tex]
This can be written as:
[tex]\widehat{Y}\left(z\right)=\frac C{1-z^{-1}}+\frac D{1-Az^{-1}}=\frac{C\left(1-Az^{-1}\right)+D\left(1+z^{-1}\right)}{\left(1-z^{-1}\right)\left(1-Az^{-1}\right)}[/tex]
From the two equations about, [tex]A\left|y_{-1}\right|+\widehat{x}-A\left|y_{-1}\right|z^{-1}=C+D-ACz^{-1}-Dz^{-1}[/tex] for all z, and we must have [tex]A\left|y_{-1}\right|+\widehat{x}=C+D[/tex] and [tex]Ay_{-1}=AC+D[/tex].
The inverse transform of [tex]\frac C{1-z^{-1}}+\frac D{1-Az^{-1}}[/tex] is [tex]H\left[n\right]\left(C+DA^n\right)[/tex]. So, we have [tex]C+DA^{m-1}=\widehat{y}_{m-1}[/tex].
This gives:
[tex]D=A\left|y_{-1}\right|-AC=\frac{\widehat{y}_{m-1}-C}{A^{m-1}}[/tex]
[tex]A\left|y_{-1}\right|-\frac{\widehat{y}_{m-1}}{A^{m-1}}=C\left(A-\frac 1{A^{m-1}}\right)[/tex]
[tex]\left|y_{-1}\right|-\widehat{y}A^{-m}=C\left(1-A^{-m}\right)[/tex]
[tex]C=\frac{\left|y_{-1}\right|-\widehat{y}_{m-1}A^{-m}}{1-A^{-m}}=\frac{\left|y_{-1}\right|A^m-\widehat{y}_{m-1}}{A^m-1}=\left|y_{-1}\right|+\frac{\widehat{y}_{m-1}-\left|y_{-1}\right|}{1-A^m}[/tex]
[tex]\widehat{x}=C+A\left|y_{-1}\right|-AC-A\left|y_{-1}\right|=\left(1-A\right)C=\left(1-A\right)\left(\left|y_{-1}\right|+\frac{\widehat{y}_{m-1}-\left|y_{-1}\right|}{1-A^m}\right)[/tex]
However, when I apply the last formula to the result of the first filter in my program, I don't get [tex]\widehat{x}[/tex]. If x is 0, then [tex]\widehat{x}[/tex] should be 0 as well, but it isn't. The formula looks correct. I have tried with a value of m as low as 2, but it still doesn't work. What could be the problem.
Last edited: