# How to test the FIR filter in C++?

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!

• Are you using a unit test framework like Google Test? – Damien Feb 23 '15 at 8:17
• Nope. Is there an approach or possibility to testing FIR Filter (C++) using this framework?. – PsychedGuy Feb 23 '15 at 8:24
• 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 ) – Damien Feb 23 '15 at 8:26
• 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. – Damien Feb 23 '15 at 8:29
• 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. – Damien Feb 23 '15 at 11:08

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$$
• @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). – Matt L. Dec 22 '16 at 20:54