# Apply a filter according to some function

I'm fairly new to digital signal processing. I've been trying with limited success to apply a time-varying bandpass filter to a signal (question at stackoverflow). Instead I thought I'd try a different approach. Say I have a function which approximates the data I'm trying to filter from my signal. Is there a technique -- perhaps some sort of optimisation -- that can take this estimation as a "template" for a filter design, rather than specifying strict filter parameters, as when one designs a Butterworth filter, for example.

• I'd have a look at adaptive filtering techniques. – Naresh Aug 14 '13 at 9:49
• @Naresh Please see my discussion below - could you comment on this at all? – allhands Aug 14 '13 at 10:45

Say I have a function which approximates the data I'm trying to filter from my signal. Is there a technique -- perhaps some sort of optimisation --

Let us say that you have a model of your data, in the form of a polynomial fit of certain order. In this case you will have co-efficients that produce a polynomial that best fits your data in the Least Squares Sense. Thus, you would have already solved the LSE problem via optimization routines, which would yield the co-efficients $p_i$. for a $m$ degree polynomial.

$$y[n] = p_0x^0[n] + p_1x[n] + p_2x^2[n] ... p_mx^m[n]$$

that can take this estimation as a "template" for a filter design, rather than specifying strict filter parameters, as when one designs a Butterworth filter, for example.

Technically yes, you can do this. Once you have your polynomial co-efficients, you can generate a polynomial at sample spacing commensurate with your sampling rate, and perform a DFT on it and inspect the absolute magnitude of your result, in order to get a frequency domain representation of your 'template'. This is certainly do-able.

In fact, this is precisely the theory behind matched filters. Matched filters work optimally (in AWGN) because they take into account frequency bins where your signal resides, and ignore other bins with noise only. This is how they maximize SNR when performing active detection of (obviously known) signals. (This is also closely related to the technique of Empirical filtering in the frequency domain).

I say the above is doable, however the wisdom of doing it would depend heavily on your application, which your question does not really delve into.

EDIT: Based on the new information you have provided in your comments:

First off, note that the Hilbert Spectrum (instantaneous frequency) is not defined for signals with more than one complex exponential.

Secondly, the way you have described it, you may be over-thinking this. You want to perform a narrow-band filtering operation on a frequency-varying signal over time. One basic solution for this is to simply use an Adaptive Filter, whereby the weights of your (adaptive) filter are constantly updated so as to minimize the error between your estimate and the empirical data.

One implementation of an LSE Adaptive filter will seek to minimize the cost function, defined by:

$$C[n] = \Big[y[n] - \mathbf{h}^T[n]\mathbf{x}[n]\Big]^2$$

Where $\mathbf{h}^T[n]$ is the $M$ length adaptive weight vector at instant $n$, $\mathbf{x}[n]$ is the $M$ length data vector taken as column vectors of the Toeplitz data matrix $\mathbf{X}$, and $y[n]$ is the desired signal at instant $n$. A filter structure such as this will 'track' your signal as it changes frequencies.

• Perhaps a bit more background on my application would be useful. I want a good time-frequency representation of a monocomponent audio signal using Hilbert spectral analysis. My problem is that I have a fairly poor SNR, so to filter my audio signal I need a narrow bandwidth. But my frequency data is non-stationary, and using fixed parameters for a bandpass filter introduces noise to the signal. One idea I had was to try and use a time-varying bandpass filter, although I haven't been able to successfully do so... – allhands Aug 9 '13 at 16:47
• ..continued. Another idea was to use an estimate of my signal (perhaps obtained through something like a polynomial fit to some fixed points) to extract the actual instantaneous frequency from my data. Simply getting a DFT of the template is not really enough, since I require the preservation of time information. STFTs are also not really useful for me, since they are limited in either time/frequency resolution. – allhands Aug 9 '13 at 16:49
• @allhands Please see my edits. – Tarin Ziyaee Aug 9 '13 at 17:42
• Thanks for your very detailed comments. I'm wondering if you could supply more information on adaptive filtering and its implementation (specifically, I'm working in Python). The problem I see is that my filter function is only a coarse-grained estimate of the "true" signal - in reality the "true" signal has modulations in frequency that are much more rapid than the estimated function shows. My question is would an adaptive filter be able to track these modulations, using the "estimate" signal to minimize the cost function? – allhands Aug 14 '13 at 10:44
• The only limitation of an adaptive filter in my opinion is the computational cost/tracking parameter. – Naresh Aug 14 '13 at 12:08