Member Since: March 2, 2012

Country: United States


Programming Languages: C, C++, Java, Linux shell scripts.

Web Site:


Lessons in Algorithms

December 21, 2016

Learn techniques on how to use Finite Impulse Response (FIR) filters and other data-processing tools to turn data into information.
  • Now you know why Nate had to implement the “No Beer until an hour before the end of your Shift” rule. His 30 day binge not only jeopardized his own health, but he trashed his office and stole all his co-workers USB cables.

  • Good point about not throwing it away. Thinking about how these boards are used by Maker Spaces to do projects and then possibly put back in a bin for others to use, boards should be able to be wiped before returning to the bin. In the DOD world if a board with Non Volatile memory is plugged into a classified network that board must be maintained in a secure environment unless it has a sanitization procedure to wipe all non volatile information. Perhaps SparkFun can include on the product page a sanitization procedure or some executable that can be flashed onto the board and run that will remove all stored user parameters.

  • While as mentioned the fact that it’s defined local to the class it won’t have a conflict, but it might be a little confusing. One standard notation for a class member variable is to use m_ prefix. For example m_i2cPort.

  • In silent protest, “Left Shark” refused to race on a track with all right hand turns!!!

  • Yea, that would be tuff to discard that bad hit, it seems to create more acceleration then some of the early on good hits. To do it you’d probably have to make the live feed a punch estimate and then after calculating all the meta data over the total punch workout, then go back a reprocess the data to try to filter out bad hits.

    I’m thinking improving from the 28% error rate to around 1% is probably good enough for what’s trying to be accomplished with a low cost low hassle device.

  • Current Numbers:

    3-77hits -> 77

    4-81hits -> 81

    5-93hits -> 94

    6-79hits -> 79

    Mystery1 -> 172

    Mystery2 -> 158

    Status: It’s been a long road to get here, as I’ve reworked the algorithm 6 different times. I started out coding in Java so I could easily create a GUI and plot the data to understand how to process it. It seemed somewhat easy to make a Nate punch detector, but just wasn’t confident any of those could work for other boxers. This 6th generation seems to be on its way to working for most boxers so I’m going to submit it, I wanted to get a horse in the race with all the work I’ve put in so far. I implemented the algorithm first in java code that I wrote in a way the can be easily ported to C. Once I was ready I then quickly ported it to C/C++ in a Visual Studio 2015 project. Next I took the code from the VS 2015 project and ported it into Nate’s original Arduino project. All the code from all 3 phases is in the Git Hub repository. I’ve also included a PDF design document in the repository. The Java application can be run from a Linux or Windows command line by going to the project directory and typing: “java -jar dist/SpeedBagAlg.jar <filename>”

    You can view the Java source code in the src directory under Java folder with any editor or use netbeans to open the project. If your interested in using this java technique to quickly workout algorithms and then port them to microcontroller code you can see some examples on my website, here is an example of parsing AT command input data from an ESP8266 module, I plan to continue demostrating this in some of my future posts. The link is to the ported C but it has a link to the original Java code.

    Project: GitHub

    Approach: Since this is to run on a micro controller I decided to not use any floating point or time consuming math functions. All math used by the algorithm is integer addition, subtraction, multiplication or division. I used a Front End processor to remove bias and condition the raw input signal. Then a detection processor to find the mins and maxs to count punch. I want to add a tracking processor to track the punches and be able to open and close both amplitude and frequency thresholds plus the possibility of lighting an LED when the rhythm is staying consistent.

    Front End Processor: Starts with a High Pass FIR filter to remove static bias, then decimating the signal to squelch more noise then taking the absolute value of the signal and followed by a small smoothing average to clean up the signal so it can be fed into the detection processor.

    Detection Processor: Decimates the signal squelching more values near the floor to zero and then taking the magnitude squared (Mag Square) of the signal. The mag square signal is then feed into a Low Pass FIR filter. The output of the FIR filter is feed into a medium size smoothing algorithm that also spits out a delayed signal that is right in the middle of the averaged signal so it is aligned in such a way to be used as a punch threshold template. The algorithm adjusts automatically to amplitude variations to keep from getting confused on the many resonant addition and subtraction phases that seem to occur. Right now punch frequency gate is fixed at 260 ms, but this may be a problem for the same algorithm working for amateurs and speed bag pros, which is why a Tracking processor would most likely be needed to be highly accurate across boxers and different speed bag platforms.

    Tracking Processor: Not implemented yet, but will track the frequency of peak punch detections and be able to better regulate punch frequency gate to be able to increase accuracy for amateurs and speed bag pros.

  • I have a follow up question. In the 3-77 video you start out with two lefts and then switched to your right on the 3rd punch and you didn’t move your paw out of the way fast enough and the bag hit it and the bag did not continue for the other two impacts of the normal punch sequence, you then steadied the bag and restarted punching. My question is, did you count that as 3 hits or 2? In looking at the data its hard to tell the difference from the 2 good hits to the miss hit. My algorithm scores 77 hits and I’ve verified that I count that miss hit as a hit, so I wanted to know if you counted it as a hit. I have pulled that sequence to see if it was possible to tell its a miss hit, but it seems from the additional quick contact with your fist there is almost more acceleration events created than the good hits so it might be a tall order to detect miss hits.

    Thanks, Barry

  • Nate, A couple of questions on the data. Is the format: timestamp, x, y, z

    If so z seems to always be well into the negative numbers so does this mean the output is not 1g compensated on the z axis when at rest? If the bag is just hanging it does not read 0,0,0 (so z would have -1g worth of a 12 bit signed scale)? What is the range of the scale it seems like it might be +4 to -4 g’s? Sorry for all the questions, just wanted to explore other options than applying a filter on peaks of a 3D vector.

    I guess you can tell I would really like to have a trip out there to talk algs with you and the crew. :)

  • Enough talk, at this point it’s time to put your light where your mouth is.

  • Shhhhh! There it is, Nate’s awesome graphite 20x Magnifier LED Lamp, I’ve heard rumors, but I didn’t think it really existed.

No public wish lists :(