No announcement yet.

Math::FirFilter and Math::IirFilter - Need algorithm definition

  • Time
  • Show
Clear All
new posts

  • Math::FirFilter and Math::IirFilter - Need algorithm definition

    I'm working with accelerometer and magnetometer (and soon to be gyroscope once Garmin exposes it) data and need to filter the data. I have reviewed the documentation for both FIR and IIR but neither describes how the coefficients and gain are implemented in the algorithm. Tuning the filter coefficients with trial and error is not feasible due to the time and effort involved in testing. I do have multiple sessions of 10hz data that I have logged that I would like to use to train the filter tuning outside of CIQ using Excel. Can the filter algorithm be further documented or communicated so that I can make use of this great sensor set and functionality that's built in?

    Note: Original development is being done on a Forerunner 935, CIQ 2.3.x


  • #2
    There is no easy answer to your question. Finite Impulse Response (FIR) and Infinite Impulse Response (IIR) filters are a rather dense topic of digital signal processing and their coefficient cannot be obtained without a heavy dose of math (Z transforms, etc.).
    Wikipedia is a good starting point on the subject:
    You may find FIR/IIR calculators on the net that allow you to obtain the coefficients for well-known analog filter equivalents like Butterworth, Bessel, etc. filters; one such link is:
    In one of my project, I needed to smoothen the rather "jumpy" sensor values measured by the deivce (i.e I needed a very low pass filter). One elegant way to do so is Exponential Moving Average, which is nothing but a crude 1st-order IIR:
    Device: D2 Charlie
    CIQ apps: Garmin ConnectIQ Store
    Environment: Linux/Debian (emacs, vim, make, etc.)


    • #3
      To add on to what CedricD wrote, Octave and Matlab both have very easy to use filter design tools. In Matlab there are two main graphical tools, accessible through either the filterDesigner or the filterBuilder commands. Octave has a close-to-equivalent feature set available in the signal package, but you might be lacking the graphical interfaces. Both software packages are capable of reading file types produced by Excel, which you mention is where you currently have you data.

      I might also recommend The Scientist and Engineer's Guide to DSP which is available for free here: It is one of the more comprehensive freely available resources on introductory DSP.


      • #4
        CedricD. and asandweech, thank you for the suggestions, I just realized that I never responded to close this out. I ended up going through the Python path to keep it open source. I utilized the NumPy fft library to visualize the signals in frequency space and gain an appreciation for which frequencies I cared about. Once there, I used the SciPy Signal library to try a variety of filters. The uploaded attachment shows a variety of Band Pass filters applied between 0.3 and 2hz with number of taps ranging from 3 to 50.

        A key learning for me was the "time delay" associated with increasing the number of taps. You see the greatest peak in the attached image shift to the right with the increasing number of taps (it shifts by numtaps/2). This is important to keep in mind if you are trying to associate filtered data with timed data.