SparkFun Electronics Commentsurn:uuid:214d0e4e-f1b1-d287-ce26-ac5b4c9f82492024-03-19T06:26:39-06:00SparkFun ElectronicsNate on Crowdsourcing AlgorithmsNateurn:uuid:76b7eb99-9f41-35c3-bac7-56f3995e693b2017-08-31T14:41:19-06:00<p>Floppy! Thanks for entering. You got a <a href="https://www.sparkfun.com/news/2149" rel="nofollow">shout out</a>. <a href="https://learn.sparkfun.com/tutorials/lessons-in-algorithms" rel="nofollow">Barry's solution</a> managed to pulled the rabbit out of the hat.</p>
floppystick6 on Crowdsourcing Algorithmsfloppystick6urn:uuid:94ce843b-5e63-5260-73c5-d92959595d2d2017-08-31T14:25:25-06:00<p>Hey Nate,<p>Whatever happened to this contest?? Did you declare a winner? I think that this deserves a new blog post with an update.</p></p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:833deaa2-7482-6be7-3a51-85477bed0f522016-11-21T09:19:26-07:00<p>Nice work! Great video. I'm interested in how you setup/designed your FIR and hardware.</p>
Customer #408599 on Crowdsourcing AlgorithmsCustomer #408599urn:uuid:9c37757a-caa5-1c79-3b23-330145abf7f72016-11-21T09:11:29-07:00<p>Although i am late, here is my implementation of Arduino based punch counter and the results are being forwarded to Android Mobile for Display.
Ref: I took the lead from #barryjh and modified his algorithm to suit my scenario as the punching bag moves is random directions most of the time.<p>Here is a short video in which i demonstrated the working of this algo. Left side shows the output on an Android App.</p><p>https://www.youtube.com/watch?v=qgFmXZRP3lM</p></p>
marciopp on Crowdsourcing Algorithmsmarcioppurn:uuid:9fb79e47-5635-0ed5-adb2-f4ad1d1b955d2016-07-04T08:50:28-06:00<p>Did some alterations on .ino.
Maybe it runs directly, without alterations now.</p>
barryjh on Crowdsourcing Algorithmsbarryjhurn:uuid:97d67f8e-365e-75b2-2dca-9c7bee5e7fe12016-07-02T07:48:55-06:00<p>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.<p>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.</p></p>
Customer #284237 on Crowdsourcing AlgorithmsCustomer #284237urn:uuid:0f6a28eb-c221-478e-6542-82cc949920742016-07-01T18:22:30-06:00<p>Follow-up to what I've seen in the data: is the accelerometer over the center of the platform, or is it more "forward" (i.e. the direction where you punch out) in the platform?
My guess is that it's more forward, and this causes certain hits to be felt stronger. If so, it might be helpful to have two accelerometers, one in front of and one behind the center of the platform to detect different bag-platform hits.</p>
Patrickk on Crowdsourcing AlgorithmsPatrickkurn:uuid:91c98d7f-1deb-b708-ba37-0a025ee886992016-07-01T13:59:44-06:00<p>I had the same problem lol. I had to look back through the video to see what was going on in that 3rd punch. Reading your 7-1-16 comment I realized we probably have a similar DSP approach. I counted it as a hit, since it looks like he hit it. He just didn't retract his hand quickly. From what I remember too, if you don't count that as a punch, then the total count comes to 76.</p>
barryjh on Crowdsourcing Algorithmsbarryjhurn:uuid:3d7dbcb6-3a12-6ef3-b75b-cc84fdf3ab9d2016-07-01T10:00:10-06:00<p>Current Numbers:<p>3-77hits -> 77</p><p>4-81hits -> 81</p><p>5-93hits -> 94</p><p>6-79hits -> 79</p><p>Mystery1 -> 172</p><p>Mystery2 -> 158</p><p><strong>Status:</strong>
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>"</p><p>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, <a href="https://www.miser-tech.com/2015/12/esp8266-step-4-1-the-ported-code/" rel="nofollow">here</a> 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.</p><p>Project:
<a href="https://github.com/barryhannigan/SpeedBagChallenge" rel="nofollow">GitHub</a></p><p><strong>Approach:</strong>
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.</p><p><strong>Front End Processor:</strong>
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.</p><p><strong>Detection Processor:</strong>
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.</p><p><strong>Tracking Processor:</strong>
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.</p></p>
Patrickk on Crowdsourcing AlgorithmsPatrickkurn:uuid:139051fd-d177-5df2-2b08-86b18641a7f32016-06-30T21:03:22-06:00<p>Thanks for having this fun competition :). I wish I could say it was easy.
My numbers are:
77 for 77, 81 for 81, 93 for 93, 79 for 79, 172 for Mystery1, and 155 for Mystery2.<p>I used a PIC32 development board, I believe you have one in stock as well. The included C firmware project along with a pdf serve as an example of how to implement the algorithm. Link to files is <a href="https://github.com/Patrick0000/Git-Folder" rel="nofollow">here</a>. I have to say uploading a folder to Github was not intuitive at all for me.</p><p>Thanks again!</p></p>
bauerg on Crowdsourcing Algorithmsbauergurn:uuid:a8d85c1f-d1ad-5a68-69bb-952c1ff372c82016-06-30T18:56:46-06:00<p>Thank you for hosting this contest. I will not meet the deadline but I plan to continue to work on it and want to describe what I think is a different approach.<p>In thinking about the problem, I see a damped system that has energy periodically added. The thought is similarly expressed by Member #815726. In order for the bag to continue oscillating, the system needs to be perturbed within a fairly narrow frequency range that is independent from the boxer's skill.</p><p>So, I think an algorithm can be made to detect and count when energy above a certain threshold and at ~about a certain frequency is input in the system. In order to do that, I use a Goertzel algorithm to efficiently detect signal power within a certain frequency range.</p><p><a href="https://github.com/bauer-san/BeatBag" rel="nofollow">full project</a></p><p><a href="https://github.com/bauer-san/BeatBag/blob/master/BeatBag.ipynb" rel="nofollow">iPython notebook</a></p></p>
Customer #815726 on Crowdsourcing AlgorithmsCustomer #815726urn:uuid:0c3c26b7-a5dd-a6bc-469a-c82110a6cb032016-06-30T15:53:22-06:00<p>I won’t have the time to code up an entry, but in keeping with Nate’s desire to learn from each other, and to talk about approaches to the problem, I’ll share what wisdom I have. I think the essence of good engineering starts with a clear understanding of the physical principles at work in the system under consideration. At the level of the accelerometer data, things are pretty chaotic with all the shaking and bouncing around and all. But if you take a step back, it is much simpler. The bag and platform is a system with an under-damped (oscillatory) response that stores and dissipates energy. A “hit” is the way that energy is added to the system. The boxer’s job is to periodically keep adding energy to the system at a time and in an amount necessary to keep things going with some degree of consistency. So if you can somehow measure the energy contained in the system, then you can look for periodic increases in the amount of energy. The choice of sensors, mounting locations, and the mathematics of processing the data should be evaluated according to the ability to measure the energy in the system, subject to the other constraints of cost, simplicity, processing capacity, etc. And no matter what it looks like in the video, if there is no significant increase in the energy in the system, it probably shouldn’t be considered a hit.<p>So how do you measure energy in the system? Some of the energy is kinetic, 1/2 MV^2: movement of the bag, movement of the platform and brackets, etc. Part of it is potential: compression of the air in the bag, elastic deformation of the platform, height of the bag above rest position. As the system is bouncing and shaking, some of the energy is being converted from one form to another, but except for the boxer's punch, the overall energy will always decrease. Assuming that platform mounted accelerometers are a reasonable choice of sensor, one can integrate the signals from the accelerometers to get a profile of the velocities of the platform in each direction at any given time. By squaring these velocities, we should be able to get a snapshot of the kinetic energy profile of the system at that time, and then look for increases and decreases. I think the solution proposed by #284237 gets at this with the analysis of decreasing peaks and the variable thresholds that account for the current level of energy in the system. Todd's solution similarly looks for an pulse above a decreasing threshold that one could interpret as the decay of energy in the system. Similarly, other measures suggested, velocity of the bag, air pressure in the bag, etc. are also related to the energy content of the system.</p><p>It’s great that Nate is trying to bring the benefits of technology to the sport of boxing!</p><p>One last thought. A good solution might be to find an ultrasonic or radar doppler sensor. It could be mounted on the platform just out of reach of the bag, or on the back post or wall and aimed at the bag. Otherwise, it requires minimal modifications and should work for any speedbag. The output would be an FM signal, responsive to the velocity of the bag, which should be easier to filter and process. It would directly measure the velocity of the primary energy storage element of the system.</p></p>
marciopp on Crowdsourcing Algorithmsmarcioppurn:uuid:54f908ca-d29d-65e1-46bf-42a9c1c394682016-06-30T15:43:14-06:00<p>Arduino code trial uploaded on Github:<p>https://github.com/marciopp/SparkfunBag</p><p>Code was not verified.</p></p>
gcarmonar on Crowdsourcing Algorithmsgcarmonarurn:uuid:c08f0e65-0910-d64e-9c2f-1b78611ff18a2016-06-30T15:32:34-06:00<p>My contribution can be found <a href="https://makeroboticsprojects.wordpress.com/projects/sparkfun-contest-beatbag/" rel="nofollow">here</a>
Results:
* 3-77hits.TXT: 73 hits
* 4-81hits.TXT: 80 hits
* 5-93hits.TXT: 83 hits
* 6-79hits.TXT: 77 hits
* MysteryDataSet-1.TXT: 177 hits
* MysteryDataSet-2.TXT: 166 hits
Thanks for the opportunity!</p>
marciopp on Crowdsourcing Algorithmsmarcioppurn:uuid:f6a62316-01ae-92a6-7b38-30779392aab22016-06-30T13:59:27-06:00<p>Matlab code on Github:<p>https://github.com/marciopp/SparkfunBag</p><p>As soon as I have time I will port to Arduino as the code is simple and moving averages have specific libraries already coded.</p></p>
marciopp on Crowdsourcing Algorithmsmarcioppurn:uuid:0b391a89-09bf-5f14-de2f-ab0a025a8fc32016-06-30T12:49:18-06:00<p>Hi, I did not have time to port to Arduino, but the code is very simple.
I am posting today, because is the last day...
Approach is three moving averages to smooth the instantaneous acceleration delta and a lower limit to discriminate low acceleration change that is not a hit.
Parameters were established on trial and error to better suit the known results.
Code was tested on Matlab (have fun):<p>cont=0; % hit count
delta=0; % acceleration instantaneous delta
finalmean=0; % acceleration smoothed
firstmean=90; % parameter for first moving average
secondmean=110; % parameter for second moving average
thirdmean=30; % parameter for third moving average
lowerlimit=80; % hits are above this limit
for i=1:length(x)-1;
delta(i)=abs(x(i+1)-x(i))+ abs(y(i+1)-y(i)) + abs(z(i+1)-z(i));
end;
finalmean=movmean(movmean(movmean(delta,firstmean,'omitnan'),secondmean,'omitnan'),thirdmean,'omitnan');
for i=1:length(finalmean)-2;
if (finalmean(i+2)<finalmean(i+1)) && (finalmean(i+1)>finalmean(i)) && (finalmean(i+1) > lowerlimit);
cont=cont+1;
end;
end;
display(cont);</p><p>x,y and z are your inputs and cont will give you the hits.
On Arduino I believe it can count the hit in real time, after less than 1 second of turned on.
Results: 3: 77 (77), 4: 81 (81), 5: 91 (93), 6: 79 (79), Mistery 1: 190, Mistery 2: 161.</p></p>
Customer #821180 on Crowdsourcing AlgorithmsCustomer #821180urn:uuid:6bc07463-05a3-1b18-35d5-c36aaea4b4ce2016-06-30T06:35:57-06:00<p>Thanks for this awesome opportunity and for convincing me to publish something open source. I really need to do more.
Ive put everything I did with documentation at https://github.com/plakkiesza/speedbag
This is the first time Ive used github so I hope I did not mess anything up. Im also hoping I make the deadline as its been a bit difficult to get somewhere with internet and electricity (I deal with weird stuff)<p>I do not have the hardware and hope my modification of the code does work.</p><p>This is what I did
Take an average over the last 76 data points (152ms) if its greater than 17 count it as half a punch. Also making sure not to count punches unless they are at least 152ms apart. 1.29% seemed like I could do better
Results:
3-77 result 78 error 1.29%
4-81 result 82 error 1.23%
5-93 result 93 error 0%
6-79 result 79 error 0%
Mysterydataset1 = 154
Mysterydataset2 = 153</p></p>
UofI_1996 on Crowdsourcing AlgorithmsUofI_1996urn:uuid:38d24cc3-3a0b-6ed0-d378-503f44272e5d2016-06-30T06:32:07-06:00<p>My solution, documentation, and tools can be found here...
https://github.com/UofI-1996/BetterSpeedBagCounter<p>3-77hits --> 77
4-81hits --> 81
5-93hits --> 93<br>
6-79hits --> 79
MysteryDataSet-1 --> 172
MysteryDataSet-2 --> 154</p><p>The PDF file gives a description of the algorithm I used and a overview
of the Analysis and Test Driver applications that are also supplied in
the repository.</p><p>The BetterSpeedBagCounter Analysis Tool allows you to change the
parameters that affect the algorithm's filters and thresholding while seeing
how it affected the detection processing.</p><p>The Arduino Sketch is currently setup to communicate with the supplied
test driver application via a std. serial interface. I ran it on a
Leonardo board, but it will compile targeting any standard Arduino
board. The processing of the accelerometer data takes between 120-130us
on the Leonardo so there is be plenty of processor left, to make improvements,
even after allowing time to handle the interface with the accelerometer and display.</p><p>Thanks for the challenge! If required I can integrate the reset and
processAccelerometerData functions into your existing sketch but I wanted to
post the solution and test driver that people can modify/run with
just a PC and any Arduino board.</p></p>
Toad on Crowdsourcing AlgorithmsToadurn:uuid:3e872d47-b370-3161-68bb-c996abab046a2016-06-29T21:54:37-06:00<p>My approach is at:
<a href="https://github.com/tbberg/SpeedBagCounter_TBB" rel="nofollow">https://github.com/tbberg/SpeedBagCounter_TBB</a><p>I found 168 hits for mystery set 1, and 160 for mystery set 2.</p><p>detected 77 hits for the 3-77 dataset</p><p>detected 78 hits for the 4-81 dataset</p><p>detected 93 hits for the 5-93 dataset</p><p>detected 83 hits for the 6-79 dataset</p><p>There seem to be some leading and trailing events in most data sets - not sure if they are actual hits as the spacing between them are larger than the others in the main body of data. These could be a source of variability. Another challenge is detecting a "weak" hit event, which may be due to a soft blow or a blow when the stand is oscillating (the blow could land when the stand is "moving away" and the net acceleration is lower, possibly zero.)</p><p>It's also curious that there are so many accelerometer timeout events. Some of the hits may be missing..... Any thoughts? Maybe due to display data line sharing/multiplexing?</p><p>Thanks for the challenge!</p><p>Todd</p></p>
Customer #284237 on Crowdsourcing AlgorithmsCustomer #284237urn:uuid:c3812157-cf03-917a-309f-ae82258e47182016-06-27T00:48:11-06:00<p>My code is at <a href="https://github.com/neimet/SparkfunSpeedBag" rel="nofollow">https://github.com/neimet/SparkfunSpeedBag</a><p>It gets all four of the known sets correct and predicts 172 hits for Mystery Data 1 and 156 hits for Mystery Data 2. I didn't run it on an arduino, but I made sure it compiles and ran a slightly modified version (so I can actually run it) as a c program.</p><p>Here's the plot it produces for the 77 hits data set.</p><p><img src="http://i.imgur.com/m23IziR.png" alt=""></p></p>
Customer #815726 on Crowdsourcing AlgorithmsCustomer #815726urn:uuid:a05a9c19-c8ab-c9ad-f4f0-14b286b264982016-06-23T14:39:43-06:00<p>Hi Nate. I'm coming into this a little late, but it was good to see all the different insights to this (I think very difficult) problem from the respondents. But I have a very basic question. What are you really trying to measure? Is it hits per minute? Can a good boxer really make things go faster or is the speed pretty much determined by the natural resonance of the system? Is it a matter of getting into the rhythm of the system and keeping it consistently going - in other words, are you trying to measure "flubs" where the boxer looses sync and has to start over? Are you trying to measure how accurately the boxer hits the bag, and if so, how much of a glancing blow counts as a miss?<p>This is tough because what you are measuring, vibrations of the platform, are pretty far removed from the act of hitting the bag. The initial punch probably transfers some energy to the overall system (platform, brackets, etc.) which makes it respond in its own natural rhythm. Then, as others have observed, the bag appears to hit the platform multiple times per punch, each time making the platform vibrate in its own natural frequencies. To make matters worse, discs like the platform like to vibrate in many complex, non-integer harmonic modes (think of the crash of a cymbal). Then, acceleration, as a second derivative function, tends to amplify noise. On top of that, there is the natural variation in the force of each punch. Finally, there are issues with the sensors themselves, like the occasional "timeouts" in the data, and quantizing and sampling errors. To be able to find the "signal" in all that noise, I would suggest that you need to know as much about the signal as possible - hence my questions.</p><p>Theoretically, I suppose you could measure the flow of a mountain stream by measuring the noise it makes, but it would be better to measure cross section and flow velocity. Similarly, there are probably better ways to measure a boxer's skill if we can decide what that actually means.</p><p>In the meantime, what a great signal processing challenge!</p><p>Some additional thoughts:
How about putting two accelerometers on wristbands? Then you could gather all kinds of info that might be of use to a boxer: punch velocity and reach, contacts and contact force, missed punches. And, this could be gathered while sparring or in a match, as well as in the speedbag workouts. Another interesting experiment might be to tape a single accelerometer to your body, like maybe on your sternum. Theoretically, punches and hits should cause corresponding movements in a boxer's body and these may be easier to detect and provide more information than the vibrations of the speedbag platform.</p></p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:055bbc6e-f26e-1540-5249-e7bdeb4589112016-06-22T12:55:46-06:00<p>Thanks! Looks pretty good. I've upvoted this and will include this in the batch to test.</p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:3a95d377-9995-53c5-c0ff-d256814166582016-06-22T12:52:24-06:00<p>I welcome anything that will help people learn but to enter it has to be a functional program. If you can post your mathematical approach you might find friendly folks to help you convert that to code. Honestly, one of the hardest parts for me is <strong>this</strong> step - I've found various academic approaches to the problem only to be bogged down when I tried to wrap my head around converting the formulas to code.</p>
barryjh on Crowdsourcing Algorithmsbarryjhurn:uuid:5e7f57ee-016c-0427-8459-0c61dcad3f782016-06-22T11:18:13-06:00<p>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.<p>Thanks,
Barry</p></p>
waltemus on Crowdsourcing Algorithmswaltemusurn:uuid:2e92b18c-34ed-c464-8aa3-ae278cc5a64f2016-06-21T00:25:49-06:00<p>I uploaded my solution to https://github.com/WilliamAltemus/HitCounterChallenge<p>Output:</p><p>77 expected / 77 detected - 0% error</p><p>81 expected / 82 detected - 1.23% error</p><p>93 expected / 93 detected - 0% error</p><p>79 expected / 78 detected - 1.27% error</p><p>Mystery Dataset 1 - 169 detected</p><p>Mystery Dataset 2 - 155 detected</p><p>Thanks for the opportunity to participate in this challenge. It was a real learning experience!</p><p>William</p></p>
rben13 on Crowdsourcing Algorithmsrben13urn:uuid:503783f0-23fa-6273-6cf1-2ced8f844f022016-06-20T19:06:34-06:00<p>I also think the sensor is in the wrong place. It should be on the glove where it contacts the bag. You'll still get noisy data and have to filter it, but it should be a much easier job.</p>
Customer #494779 on Crowdsourcing AlgorithmsCustomer #494779urn:uuid:1a75367e-9180-b15b-f359-c1f69a1fbba12016-06-20T14:56:47-06:00<p>I haven't written an arduino program yet, but I have crunched the numbers in excel.<p>77 hit = 75 -3%</p><p>81 hit = 83 +2%</p><p>93 hit = 93 right on the money!</p><p>79 hit = 81 +3%</p><p>Mystery Set 1 = 200</p><p>Mystery Set 2 = 185</p><p>So does the solution have to be presented as functional code or can it be expressed mathematically?</p></p>
Customer #115633 on Crowdsourcing AlgorithmsCustomer #115633urn:uuid:5969c0ec-1937-968a-acd2-7fc5b6bac1e02016-06-18T21:44:22-06:00<p>I did a preliminary test using my Nexus 7 tablet with an app to capture accelerometer data. I had the screen facing up and tapped on the screen. There were significant jumps in values (possibly implying my assumption below that common mode noise is filtered to be less than ideal). So this scheme seems workable. But there are some issues remaining:
[1] using FIR/IIR or even DFT/FFT filtering is out of the question, since the data sampling is not truly periodic. The closest thing to use for aperiodic data is something called a periodogram, that is not really useful for harmonic analysis.
[2] The "notes" state that sampling is approximately every 2 ms, but does not state what the accelerometer's registers are setting (e.g. are they at defaults?). Register settings also affect whether or not the chip uses internal high-pass filtering (to eliminate DC offset) and some other issues.
[3] From my data (before I looked at Nate's data) it looked like I could "see" my knocks and reminded me of a nonlinear "threshold" filter I did for work. The Nexus data was sampled every 5 ms (vs. Nate's 2ms) and I could see each knock as "damped ringing" of the MEMS accelerometer data with about a 10-20 sample duration. I need to compare against Nate's data to see if it too "rings" and with what periodicity (preliminary answer is it rings with a period of about 50-100 samples).<p>I'll get back (soon?) with an update soon.</p></p>
Customer #399747 on Crowdsourcing AlgorithmsCustomer #399747urn:uuid:06163343-e343-6ab2-0863-e14a8f6097552016-06-18T06:33:00-06:00<p>My partial Arduino solution + a python script can be found here https://github.com/RobTillaart/HitCounterChallenge.<p>A hit results in a substantial larger acceleration (as discussed earlier) so checking the value with the previous one should do it. A straightforward python script helped to find the magic threshold between previous and new acceleration (17) used in the code. Running the python script generates:</p><p>MysteryDataSet-1.txt 454</p><p>MysteryDataSet-2.txt 186</p><p>3-77hits.txt 74</p><p>4-81hits.txt 79</p><p>5-93hits.txt 95</p><p>6-79hits.txt 83</p><p>The trainingsets in % are ~ -4, -2, +2 and +5% so on average ~0% . Applying the script on the mystery datasets gave me 454 hits and 186 hits respectively.</p><p>mmmm 454 hits sounds quite impressive, anyway that is what my quick code produced :)</p></p>
bdwyer on Crowdsourcing Algorithmsbdwyerurn:uuid:7aef17af-7756-84c5-7bfb-bafe2c68a62a2016-06-17T19:41:21-06:00<p>Hmm...'2047' as max readings... sounds like something is being saturated. Is this accelerometer an analog output, or digital based (spi/i2c)? If digital, is there a possibility to decrease the sensitivity (increase max-range) on the sensor itself so we have more fidelity with 'hit' values? Just curious, I like to go for the low hanging fruit in terms of optimizing this problem.<p>I have one other idea that could improve algorithm/solution finding: Since we are in the experimentation stage, I think it would be beneficial to have a trigger-type sensor in the boxing glove to have a synchronized truth vector to work with. As fun as it is seeming to be for some people here, I don't see why we would choose to fly blind from the get-go :-)</p><p>But hey, if that's what you'd like your challenge to really be I understand.</p><p>Thanks!</p></p>
DoctorD on Crowdsourcing AlgorithmsDoctorDurn:uuid:6f133fd4-a32c-6bae-3b1e-0ef493222b0c2016-06-17T15:40:46-06:00<p>I like the microphone idea. It would be inexpensive and sensitive, as long as the microphone would take the abuse. The trick would be in mounting the microphone appropriately so that it picks up the bag punches but is less sensitive to ambient noise.<p>An ideal solution might be an absolute pressure sensor inside the speed bag. That would pick up the air compression from each punch but be insensitive to movement and most environmental noise. The problem is that it would need to be coupled to the air inside, which would be troublesome to implement. You would also need a pressure sensor with sufficient bandwidth to pick up individual punches. These exist, but are not the tiny surface mount kind.</p><p>Mounting the accelerometer differently would also help. Instead of mounting it to a fixed part, trying to pick up the shocks when the bag is punched, why not attach it to a small finger that moves a small amount as the bag moves a large amount. Think of it as a tiny lever or an impedance matching transformer. The accelerometer is far too sensitive to mount it directly on the bag, but a little finger that goes from the accelerometer to the top of the bag, allowing it to move slightly with each punch, would allow you to see the gross motion of the bag without clipping the acceleromoter, and without having to deal with the complicated signals received when the accelerometer is mounted to a fixed part.</p></p>
DoctorD on Crowdsourcing AlgorithmsDoctorDurn:uuid:81fcd356-f7da-20de-5ab4-7031c5e5064f2016-06-17T15:23:01-06:00<p>Something as simple as this would probably work: https://www.sparkfun.com/products/10293<p>Try taping one onto the speed bag and looking at the leads with an oscilloscope. No power supply or other circuitry needed for a simple test.</p></p>
floppystick6 on Crowdsourcing Algorithmsfloppystick6urn:uuid:b706cb8e-6dee-d693-f540-355da5c58e942016-06-17T14:33:46-06:00<p>Check it: <a href="https://github.com/floppystick6/Sparkfun-BeatBag" rel="nofollow">github with algorithm code.</a><p>Please let me know what you think. I would be interested to see how my Mystery numbers line up.</p><p>*disclaimer - did all of my calculations in a spreadsheet to get the above values. I then wrote the arduino code to execute my spreadsheet calculations in real time. The code does compile, but I have not downloaded it, due to the lack of a free arduino and accelerometer it the time.</p><p>*disclaimer² - I am not the best at making efficient code, but it always works... sometimes.</p></p>
Ita Katz on Crowdsourcing AlgorithmsIta Katzurn:uuid:7a3b1516-9d8e-d688-26bf-e160526b2f5b2016-06-17T14:26:36-06:00<p>You can't do regression since you don't have the hits labelled. You can watch the video and hand-label, but it is hard to align the video to the accelerometer data.</p>
Ita Katz on Crowdsourcing AlgorithmsIta Katzurn:uuid:c9729399-349b-6b82-480b-0dcfc3a6403a2016-06-17T14:22:21-06:00<p>This task is very challenging (and therefor interesting from the data-analysis point of view). I don't have time to participate, but I will share some of my insights which might help others.
First, I took one of the files (the 77 hits one) and I watched the video many (many) times. I also ripped the audio track, and I loaded it to my analysis software (Matlab) alongside with the accelerometer data. I tried to align the audio and acc data (not trivial) and I watched and listened. I listened in the original speed and in X2 and X4 times slower rate. I am telling you all this because you might want to do it as well. The things I learned (some are facts, some hypotheses):
1. A typical hit is followed by 3 "after-hits" of the bag on the wooden top. That is, after the hit the bag goes forward, hits the top, bounces backward, hits the top, bounces forward, hits the top, and then gets hit again by the boxer.
2. The main impact is therefor not from the hit itself, but from the after-hits, since the accelerometer is mounted on the top. You can clearly see this by the fact that the z-data has the strongest signal (I am NOT talking about the constant DC due to gravity, as I subtracted the average of the first 1000 samples from each channel).
3. Therefor, I do not advise you to look at the norm of the vector (root of sum of squares), because this way you loose important information about the sign (positive or negative) of the z-component.
4. The fact that much of the signal is not from the hit we need to count, but from the after-hits, makes the task challenging.<p>To conclude:
- don't look at the norm, use all 3 channels
- if you do use the norm (as well as the 3 channels), don't subtract the gravity from it (like was suggested in some of the comment). This is mathematically <em>wrong</em>, that's not the way to add/subtract vectors. You add/subtract component-wise, only then take the norm.
- Use the typical hit (hit followed by 3 after-hits) as the basic event to look for.
- watch the videos, listen to the audio, slow it down. Look at the data before you try and solve the problem.</p></p>
Customer #568905 on Crowdsourcing AlgorithmsCustomer #568905urn:uuid:b5c083e0-5122-9ac4-1767-3863b2491fb92016-06-17T12:31:59-06:00<p>Well it may be as easy as a linear regression between x,y,z and hits.<p>Or linear regression between sqrt(x<em>x + y</em>y + z*z) and hits.</p><p>Tom</p></p>
Art75 on Crowdsourcing AlgorithmsArt75urn:uuid:0afdc725-526a-bd22-7dd7-1e239fdf79ba2016-06-17T10:22:20-06:00<p>What a great challenge. Just to clarify, are we trying to count punches or the number of times the bag swings back and forth? It seems like there would be two sets of things happening in this data - both the punches and the bag hitting the board.<p>Also, I agree with some of the other commenters about the attachment of the sensor. Is it possible to get a better data sample by playing with the mechanical connection of the sensor to the board by screwing it down tighter or attaching a (relatively) large metal plate to the board that the sensor is then attached to? Is there an amount of dampening that could be provided by a thin elastic layer between the sensor and the board?</p></p>
Customer #115633 on Crowdsourcing AlgorithmsCustomer #115633urn:uuid:84296df0-c1f1-a154-100f-ee87260d1f412016-06-17T09:56:05-06:00<p>So this setup is really a "knock" sensor. If the accelerometer were IN the bag, then it would be a punch sensor. Most accelerometers are designed to reject mechanically coupled noise, so what this is trying to do is measure the ineffectiveness of the manufacturer's mechanical isolation (which could be digital if there was another knock sensor onboard to do common-mode rejection).<p>I think a microphone is a better sensor for this application. Maybe one of your MEMS microphones.</p></p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:75ebbd0e-6d68-1328-730b-0136e3f264f22016-06-17T08:53:36-06:00<p>ShapeShifter nailed it. Sorry for the confusion. Sensor is mounted (screwed) to the top of the platform, mostly perpendicular to the surface of earth.</p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:7337ba42-4a1f-59c9-8e0c-d66f8cc20a812016-06-17T08:51:43-06:00<p>Hi Chris - Sorry for the ambiguity. The MMA8452Q is sitting on top of and is screwed to the wooden platform from which the bag hangs. The idea (of this particular project) was to create a thing that anyone could screw or stick to the top of the platform and get hit counts, without modifying the bag, hinge, or platform (other than attached said magical box).</p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:99597a4e-c290-5329-47fc-c35cad0f2aaf2016-06-17T08:49:27-06:00<p>Is it possible? Oh ya. I'll dig back through the logs and notes and see if I can get anything to line up but if you've got an algorithm (and it looks as tho you do) please post it. The proof is in the demo ;)</p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:88cbe5a8-4b49-13c3-a0e6-b8d044cff4ba2016-06-17T08:46:58-06:00<p>Hmm, neat! A Piezo Trigger is a very cool thing that I did not know existed but in this case we've got accel data. But knowing what other tools are out this is valuable as well. Thanks!</p>
yepher on Crowdsourcing Algorithmsyepherurn:uuid:a871b41a-a55f-da51-c628-fe9ef0d52f022016-06-17T07:08:09-06:00<p>Nice contest I hope to find some time to work on this for fun.<p>One thought while thinking about your design is why not use a Piezo Trigger. Seems like a much more natural sensor for this sort of application. At that point you can just use a simple threshold of the impulse and cut off any values below a given threshold. Essentially the bag hitting the platform on top would be similar to how an electric drum set works. You could use glue, tape or screw to mount the trigger to the top of the bag platform.</p></p>
Customer #266582 on Crowdsourcing AlgorithmsCustomer #266582urn:uuid:dad62266-f5c7-9a7e-2995-aa806014315f2016-06-17T07:02:35-06:00<p>Hi Nate,<p>I just wanted to put out there that by adding a decimator in front of the data, that it becomes a lot less noisy. So, in this case, less is more. There is one other thing that generally cleans up accel data, which is using a Kalman filter, as it removes Gaussian noise, which is inherent to any accelerometer or gyro. It seems like taking a look at the ardupilot project should give people some hints</p><p>One other thing is that from looking at the data, if you find the total magnitude of the acceleration, it seems to just add noise to the output. This indicates that the sensor was not placed on the bag, but maybe mounted on the plate that holds the bag. Therefore, just using accel data for one axis is sufficient. Again, less is more. One thing to think about is that the X axis actually works pretty well too.</p><p>A final thing to think about is to think about using integration to help with finding "hits".</p><p>There are a couple people who appear to have nailed it, but haven't posted their algo yet. I'll post mine this evening.</p></p>
Customer #550509 on Crowdsourcing AlgorithmsCustomer #550509urn:uuid:3ff9e443-dc5e-eb6c-80f1-9b6bb8d20d502016-06-17T05:40:05-06:00<p>I've seen data very similar to this on my first Arduino project. In that case using the Arduino as a detector was quite noisy...BECAUSE...there was a lot of stray AC noise coming in on the line voltage. This data looks very much like that. I am capable of writing an algorithm...but long before one does that please post the control data to demonstrate that you are not measuring line noise i.e. gently rotate the bag by hand for several minutes and post that data set. IF...it is noisy...then the solution is to add a capacitive gate either/and/or to the input/output of the sensor and/or to the Arduino. The other control is to hit something else, that is not the bag, for instance the frame that holds everything, and see what that signal looks like. I don't think your algorithm is particularly good or bad, I think you need to run some controls to figure out what is being measured...instead of assuming that the measurements are measuring X, as opposed to X + Q + W.</p>
floppystick6 on Crowdsourcing Algorithmsfloppystick6urn:uuid:0c41542e-79a0-7068-0ee2-24859a3252be2016-06-16T12:36:51-06:00<p>Hi Nate,<p>Is it possible that you have the data for the 5-93hit.txt and the 6-79hit.txt mixed up?
Here is what I got after looking at your data sets. (by switching the 93 hit and 79 hit data)</p><p>3-77hits → 77</p><p>4-81hits → 80</p><p>5-93hits → <strong>94</strong></p><p>6-79hits → <strong>76</strong></p><p>Mystery1 → 240</p><p>Mystery2 → 213</p><p>By looking at the first four data sets (only sets with known number of hits), this gives me an error of <4%.</p><p>What do you think? Am I in the ballpark?</p></p>
chriscrowder on Crowdsourcing Algorithmschriscrowderurn:uuid:9c31b258-3569-9c8f-c63a-1351b7bf0d332016-06-16T10:19:47-06:00<p>Can you give us a better description of how the hardware is attached? Or even a napkin drawing. From what I gathered the sensor is just mounted to the wooden support that the speedbag is attached to?</p>
Customer #394180 on Crowdsourcing AlgorithmsCustomer #394180urn:uuid:a2f8707c-4c06-1e47-2273-28eb4a17a9072016-06-16T06:49:43-06:00<p>Another possibility is to use jerk instead of acceleration. When the bag is punched, the momentum imparted by the fist generates an acceleration. Assuming that the rate of change of acceleration (jerk) is greater from a fist impact than from all the other sources of acceleration changes, it's a simple matter to take the instantaneous derivative of the acceleration magnitude to get jerk and then apply a threshold. Anything greater than the threshold is a hit.<p>Using this approach with a very quick and dirty threshold calculation, the 77 hit data set comes up with 82 hits.</p><p>To calculate the instantaneous derivative, no calculus is needed. Simply remember that the derivative of a function is the limit of delta x / delta y as delta y goes to 0. Since our data is coming in at a more or less regular interval, we can approximate this by subtracting the current magnitude of the acceleration vector from the previous value and dividing the result by the time difference between the 2.</p><p>You'll end up with positive and negative values. One is the result of fist impacts, the other of the bag hitting its stops and bouncing back. I made the assumption that the fist impacts are going to be harder, so I took the side with the largest jerk, which in this case was the positive side.</p><p>Again, I eyeballed the threshold from a plot, but you could do something more sophisticated like a statistical analysis of the jerk values and set the threshold at a certain number of standard deviations. Enjoy</p></p>
ShapeShifter on Crowdsourcing AlgorithmsShapeShifterurn:uuid:b20c0fdf-cb80-9205-73a6-6869165e69b32016-06-16T04:50:20-06:00<p>From this and your other reply, it would appear that you think the sensor is mounted in/on the bag itself. From the comments at the beginning of the code, this does not appear to be the case: the sensor is apparently mounted on the platform itself, not on the bag. The sensor is measuring the accelerations (movement or vibrations) that are imparted to the bag platform by the movement of the bag. Keep in mind that this is a 4G sensor: if the sensor were in the bag, you would need a sensor that could handle a <em>much</em> higher acceleration. Same thing for a gyro, it would have to support a very high angular rotation change rate. I agree that a 6-DOF in the bag could be a way to go, but it is at odds with Nate's "no-modification" goal (he states he wants something that can easily be screwed to the platform) and it would need a very robust sensor.<p>Because of the limitation of not mounting the sensor to the bag, you cannot measure the position of the bag or the accelerations that it experiences. You can only infer its movement based on its impacts with the platform and the resulting platform accelerations.</p></p>
Customer #93510 on Crowdsourcing AlgorithmsCustomer #93510urn:uuid:86efd553-cbc9-ddd4-9848-f08f06ceccaf2016-06-15T22:00:57-06:00<p>Part of the issue is that the wrong sensor was used. The issue with the accel is that the gravity vector dominates in all cases and even though a one can guess at the zero motion cal state the resulting accel values in anything other than the z vector (gravity) are going to limited by the delta v of the bag and the length of the sensor from the pivot point of the mounting.<p>This is generating the V^2 / R (distance between mount point and sensor) values of acceleration. By inspection it's obvious that gravity is always dominate that the motion of the bag is pretty much planar although I haven't really computed the x-y rotation vectors yet.</p><p>We don't want to measure linear acceleration, we want to measure angular velocity and angular acceleration</p><p>Had a 3 axis gyro been used the hits hits would have been extremely evident since the slopes of angular velocity ( angular accel) would clearly show an external impact force opposed to the angular accel in free fall which is essentially gravity trying to rotate the bag down to the zero momentum state</p><p>If a 6 axis DOF sensor is used with something with a bit more computation horsepower (SAMD21 board) the 6 axis fusion would be able to count hits and the energy impacted on the bag given the mass of the bag and the pivot length. Gaming controller sensor fusion is usually 125 Hz so 500 Hz may be problematic just because of the I2C transfer times. I need to do some math and see if a Bosch or Invensense IMU can sample @ 4g / / 500 Hz</p><p>my 2 cents</p><p>cheers
bob m (Wizard of Make / Atmel)</p></p>
MomboMan on Crowdsourcing AlgorithmsMomboManurn:uuid:22b934c7-9980-e7a5-38a0-d399c0a49d352016-06-15T18:58:05-06:00<p>This sounds like a middle-out compression problem!</p>
Iris A on Crowdsourcing AlgorithmsIris Aurn:uuid:01b41278-4f36-c0be-55c8-4a5347e110fc2016-06-15T17:58:18-06:00<p>Sidebar (which you can also see by reading my code, but I am summarizing here since people asked): the sensor is giving back readings from -2048 to +2047, with Z axis baseline around -512. That means that the sensor has a 12-bit ADC and ±4g range.</p>
Iris A on Crowdsourcing AlgorithmsIris Aurn:uuid:974b20c2-b50c-00c2-770d-b01b114838822016-06-15T17:54:47-06:00<p>My answer is at <a href="https://github.com/airbornemint/SparkFun-accelerometer-challenge" rel="nofollow">https://github.com/airbornemint/SparkFun-accelerometer-challenge</a><p>Its output for the four known datasets is: 80 (77 expected, +4% error), 92 (81 expected, +14% error), 106 (93 expected, +14% error), and 76 (79 expected, -4% error).</p><p>Its output for the two mystery datasets is: 232, 172.</p><p>Enjoy.</p></p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:6242affc-865d-96fb-5e1c-7c02315e47432016-06-15T16:40:34-06:00<p>There's a series of ways to tackle the problem. The mic is a very cool approach I had not heard of (pun intended). IR is how speed bags are <a href="http://speedbagdisplay.com/" rel="nofollow">currently counted</a>. I've also seen some folks trying to modify the swivel with a photogate, reed switch, etc which becomes finicky. For this particular project my vision was for anyone to walk up to a speed bag platform, screw down a thing, and get counts without need for adjustment or calibration.</p>
Customer #394180 on Crowdsourcing AlgorithmsCustomer #394180urn:uuid:6b2de0d4-e793-3dfe-5789-27ec46fd9ec02016-06-15T15:54:21-06:00<p>OK, so that was gravitational acceleration. I had made it out to be about 500 just from visually examining my plot of the magnitudes. Of course, since I was looking at magnitudes and x & y never go to 0 (probably due to noise and thermal effects, as well as the bag not being level) 500 is a perfectly reasonable value when the vector math is done to find the magnitude of the acceleration vector.<p>BTW, Nate, you could have also used a microphone near the bag, done an FFT of the incoming audio and looked for the components that indicated a hit. That way you wouldn't have to have modified the bag.</p></p>
Customer #394180 on Crowdsourcing AlgorithmsCustomer #394180urn:uuid:6e4932c8-142d-9f6c-bb6d-dba00cc322c92016-06-15T15:45:13-06:00<p>Here's what my hit plot for the 77 hit data set looks like using the acceleration magnitude algorithm above (not the jerk). It's binary, in that there's either a hit or there isn't. This plot does not show the strength of each hit. That's the timestamp on the x axis, so plot out Nate's data and see how it compares. He got a nice rhythm going between 7500 and 9000.<p><img src="http://www.morocz.com/posts/speedbag.jpg" alt="Alt text"></p></p>
Nate on Crowdsourcing AlgorithmsNateurn:uuid:9747d087-a60c-5125-0fe7-beb236d662dc2016-06-15T14:32:57-06:00<p>Yes, you are correct. Sorry, the log explanation is a bit buried in the repo: you can find it <a href="https://github.com/nseidle/BeatBag/tree/master/data" rel="nofollow">here</a>. Additionally I've updated the <a href="https://cdn.sparkfun.com/assets/home_page_posts/2/1/1/5/AccelerometerData-2.zip" rel="nofollow">dataset zip</a> to include a readme that breaks down the x/y/z.<p>Z is negative at approximately -512 which is 1g or earth's gravity pulling down. The X and Y axis are not quite zero because this is the physical world and things are not quite level.</p><p>Oh! What an excellent idea. I will probably twist the arm of the winner to give a lunch on learn at SparkFun. These are lunch presentations about hacking, building, etc. The last one was with Even Booth on his <a href="http://www.terminalcornucopia.com/" rel="nofollow">Terminal Cornucopia</a> work as well as his work converting a Kuerig into a <a href="https://www.youtube.com/watch?v=aatbIkvtQQo" rel="nofollow">prosthetic hand</a>. Amazing stuff.</p></p>
barryjh on Crowdsourcing Algorithmsbarryjhurn:uuid:06ee67af-64a3-a4c6-dab1-11e6b34a58682016-06-15T13:12:04-06:00<p>Nate,
A couple of questions on the data. Is the format:
timestamp, x, y, z<p>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.</p><p>I guess you can tell I would really like to have a trip out there to talk algs with you and the crew. :)</p></p>
Arodd2000 on Crowdsourcing AlgorithmsArodd2000urn:uuid:ebaa10b3-1e87-2770-bb0a-1f2b654078292016-06-15T12:08:38-06:00<p>I wish this was during the school year, my math teacher might be able to help me make heads or tales of this.</p>
Customer #394180 on Crowdsourcing AlgorithmsCustomer #394180urn:uuid:a8e1d4e0-744e-5249-e033-04cf30024f3c2016-06-15T11:23:43-06:00<p>Instead of entering the contest I'll give the rest of you a head start. Think of it as the ultimate shareware gift.<ol>
<li>For each triplet, take the square root of the sum of the squares of the individual acceleration values. This gives you the total magnitude of the acceleration vector. Right away, it'll be a lot more meaningful than the plot above of just the z vector. If you plot it you'll easily see the individual hits.</li>
<li>When you examine the result, you'll see that there is a quiescent value, the value when the bag is settled. Subtract that from each magnitude to normalize it (probably taking out the 1 g gravitational acceleration when we do this, don't have time to work it out exactly)</li>
<li>Divide each normalized magnitude by 100</li>
<li>Take the floor of each scaled normalized magnitude</li>
<li>Call any result larger than 9 a hit</li>
</ol><p>When I do this with the 77 hit data set, I see 80 hits which is a 4% error, substantially better than the 28% error Nate got.</p><p>Of course that 100 and 9 look like they came straight from the orificial oracle, but I actually got them from plotting the data with Excel and visually examining the plot. The fun part for you contestants is to figure out a self-calibrating scheme to set those thresholds automatically. By looking at the total magnitudes, you can also see how hard the hit was.</p><p>Good luck to all</p></p>