Help with CMSIS FIR bandpass filter implementation

Hello,

I am trying to implement a 60kHz bandpass filter in a STM32F407 microcontroller with the help of the CMSIS DSP Library, and unfortunately I am having a bit of trouble... I am wondering if someone here might know what I might be doing wrong. I've attached two pdfs one where it shows the 60kHz sine input that is sampled 4500 times at the sampling r ate of 5.25MSPS, the  second pdf shows the output of the filter  and as you might see it is completely off so I am obviously doing something wrong...

I've attached the code that I've written for the filter and the filter co-efficents that is used. The filter co-efficents are generated with the MATLAB fdatool and I've also attached a MATLAB script for simulating the filter.firCoeffs_q15.jpg

The picture above is the plot of the filter co-efficents, I used the fdatool to generate 16-bit unsigned integer co-efficents because the MCU is using a 12-bit ADC which I then just read as 16-bit unsigned integers, which I then forward to the arm_fir_q15 function.

I've looked at some examples online and I can't figure out what I am doing so wrong. Is there something I'm missing or what?

10263.zip
  • Well for starters I can tell you're doing this all in unsigned ints rather than Q15.  They are different data types.  Q15 is a signed integer, with an imaginary decimal place after the most significant bit.  In other words, it has 1 integer bit, and 15 fractional bits.  The range of acceptable values for Q15 is [-1,1),  which is represented by [0x8000, 0x7FFF].  Spend a little bit of time researching that, and adapting your code to Q15 and you'll probably figure it out.

    Cheers,

    Dan

  • Hi Pete,

    I ran your Matlab coefficient generator and found you may have an error in the translation in C code: the negative coefficients are translated to NULL values.

    This is a good reason to have large values in the FIR accumulator since your data are also all positive, which translates in saturations. By the way we can see on your plot the saturation occurs at sample #400 while there is no issue at the start of the filtering process: after 400 samples you probably accumulated too much positive data in the accumulator.

    Next point is the need of such a long FIR while a simple IIR 6th-order would do the same operation (I checked this with quantisation).

    We would be glad to help you in the analysis of your use-case and either have lower MHz or lower the need to capture as much data for your detection, using zero-crossing, FFT/Goertzel or techniques found in radio demodulators. You can contact us at : contact@firmware-developments.com or +33 698 846 090 (CET).

    Kind regards,

    Laurent.