3
$\begingroup$

I am almost done with design and implementation of my first FIR filter using C++. Its a Sinc-Windowed FIR filter designed for a cut off frequency of 100 Hz with sampling rate of 500, with a filter order M = 100. All the operations have been carried out in discrete time domain. So basically my question is regarding testing to see if my filter is generating the desired response .

I presume one way to test the output would be to apply DFT to it and check the response spectrum of the filter in the frequency domain, but for this I have to develop a function that performs the DFT on the output .

Question :To avoid this, I am looking,

---->Are there any methods that make it possible to test the filter response in the (without the need for applying DFT) time domain itself?.

----> If the above is not possible, are there are any alternative methods like some C++ DSP library with FT function's you can suggest?

Or Any suggestions and advice regarding this with your experience would be appreciated. Thanks in advance!

$\endgroup$
6
  • $\begingroup$ Are you using a unit test framework like Google Test? $\endgroup$
    – Damien
    Commented Feb 23, 2015 at 8:17
  • $\begingroup$ Nope. Is there an approach or possibility to testing FIR Filter (C++) using this framework?. $\endgroup$
    – PsychedGuy
    Commented Feb 23, 2015 at 8:24
  • $\begingroup$ An FIR filter is deterministic; it will generate a precise output for a given input. Therefore, you can verify that the C++ code is generating the correct output using a unit test framework. There are plenty to choose from (e.g. Boost Test, Cppunit, see Unit testing on wikipedia ) $\endgroup$
    – Damien
    Commented Feb 23, 2015 at 8:26
  • $\begingroup$ HOWEVER! This does not validate your requirements to whether the filter gives the correct frequency response. Since the filter is an FIR, it is relatively easy to test using something like MATLAB or Octave. $\endgroup$
    – Damien
    Commented Feb 23, 2015 at 8:29
  • 2
    $\begingroup$ the unit test referred to above is a software engineering technique. The unit impulse is a mathematical construct. The unit test will ensure you have implemented the software correctly. The unit impulse will ensure you have created the filter has the properties that you want. $\endgroup$
    – Damien
    Commented Feb 23, 2015 at 11:08

1 Answer 1

6
$\begingroup$

The first basic test could be to use a unit impulse as an input signal and see if the output signal equals the impulse response (i.e. the filter coefficients). Another simple test signal is a unit step. The corresponding output should be the cumulative sum of the filter's impulse response, i.e. for $x[n]=u[n]$, the output must be

$$y[n]=\sum_{k=0}^nh[k],\quad n\ge 0$$

If you obtain the desired response for these two simple test signals, that's a good start, but I wouldn't stop there. In general it is very helpful to use a tool like Matlab or Octave (free), or anything similar, which has built-in filtering routines against which you can check your routine for arbitrary input signals.

$\endgroup$
5
  • 1
    $\begingroup$ I would go for Python since you can call it's routines very easily from within C++ code. $\endgroup$
    – jojeck
    Commented Feb 23, 2015 at 8:33
  • $\begingroup$ How about Scilab?, Its a freeware too. $\endgroup$
    – PsychedGuy
    Commented Feb 23, 2015 at 10:12
  • $\begingroup$ @DigitalGeeK: Any of them will do for your task, just choose what you like. $\endgroup$
    – Matt L.
    Commented Feb 23, 2015 at 10:15
  • $\begingroup$ @MattL. I'm wondering, is the step response you described valid iff the step response is infinite in length? The reason I ask is because I have designed a C++ FIR tool that stores the operands h[n] and x[n]. The resultant convolution function behaves as described above initially, but then tails back towards zero when the array reaches its end...? $\endgroup$
    – davidhood2
    Commented Dec 22, 2016 at 19:07
  • $\begingroup$ @davidhood2: The formula is valid no matter if the impulse response (and hence the step response) is finite or infinite. Note that $y[n]$ in the above formula can converge to zero for $n\rightarrow\infty$. That would be the expected behavior of a high pass or band pass filter (i.e., a filter blocking DC). $\endgroup$
    – Matt L.
    Commented Dec 22, 2016 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.